def test_get_conn_matrix(conn_model_in, n_features): """ Test computing a functional connectivity matrix.""" network = 'Default' ID = '002' smooth = 2 coords = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] node_size = 8 extract_strategy = 'zscore' roi = None atlas = None uatlas = None labels = [1, 2, 3] time_series = generate_signals(n_features=n_features, n_confounds=5, length=n_features, same_variance=False)[0] outs = get_conn_matrix( time_series, conn_model_in, tempfile.TemporaryDirectory(), node_size, smooth, False, network, ID, roi, False, False, True, True, atlas, uatlas, labels, coords, 3, False, 0, extract_strategy, ) conn_matrix_out, conn_model_out = outs[0], outs[1] assert isinstance(conn_matrix_out, np.ndarray) assert np.shape(conn_matrix_out) == np.shape(time_series) assert conn_model_in == conn_model_out if "corr" in conn_model_in: assert (is_spd(conn_matrix_out, decimal=7)) d = np.sqrt(np.diag(np.diag(conn_matrix_out))) assert_array_almost_equal(np.diag(conn_matrix_out), np.ones((n_features))) elif "partcorr" in conn_model_in: prec = np.linalg.inv(conn_matrix_out) d = np.sqrt(np.diag(np.diag(prec))) assert_array_almost_equal( d.dot(conn_matrix_out).dot(d), -prec + 2 * np.diag(np.diag(prec)))
def test_get_conn_matrix_cov(conn_model): """ Test for get_conn_matrix functionality """ base_dir = str(Path(__file__).parent/"examples") dir_path = base_dir + '/002/fmri' time_series_file = dir_path + '/whole_brain_cluster_labels_PCA200/002_Default_rsn_net_ts.npy' time_series = np.load(time_series_file) node_size = 2 smooth = 2 c_boot = 0 dens_thresh = False network = 'Default' ID = '002' roi = None min_span_tree = False disp_filt = False hpass = None parc = None prune = 1 norm = 1 binary = False atlas = 'whole_brain_cluster_labels_PCA200' uatlas = None labels_file_path = dir_path + '/whole_brain_cluster_labels_PCA200/Default_func_labelnames_wb.pkl' labels_file = open(labels_file_path, 'rb') labels = pickle.load(labels_file) coord_file_path = dir_path + '/whole_brain_cluster_labels_PCA200/Default_func_coords_wb.pkl' coord_file = open(coord_file_path, 'rb') coords = pickle.load(coord_file) start_time = time.time() [conn_matrix, conn_model, dir_path, node_size, smooth, dens_thresh, network, ID, roi, min_span_tree, disp_filt, parc, prune, atlas, uatlas, labels, coords, c_boot, norm, binary, hpass] = fmri_estimation.get_conn_matrix(time_series, conn_model, dir_path, node_size, smooth, dens_thresh, network, ID, roi, min_span_tree, disp_filt, parc, prune, atlas, uatlas, labels, coords, c_boot, norm, binary, hpass) print("%s%s%s" % ('get_conn_matrix --> finished: ', str(np.round(time.time() - start_time, 1)), 's')) assert conn_matrix is not None assert conn_model is not None assert dir_path is not None assert node_size is not None assert smooth is not None assert c_boot is not None assert dens_thresh is not None assert network is not None assert ID is not None #assert roi is not None assert min_span_tree is not None assert disp_filt is not None #assert parc is not None assert prune is not None assert atlas is not None #assert uatlas is not None #assert labels is not None assert coords is not None
def test_get_conn_matrix(conn_model_in, time_series): """ Test computing a functional connectivity matrix.""" pass_args = np.random.rand(len(getargspec(get_conn_matrix).args) - 2) outs = get_conn_matrix(time_series, conn_model_in, *pass_args) conn_matrix_out, conn_model_out = outs[0], outs[1] assert isinstance(conn_matrix_out, np.ndarray) assert np.shape(conn_matrix_out) == np.shape(time_series) assert conn_model_in == conn_model_out assert (pass_args == outs[2:]).all()
def test_get_conn_matrix(conn_model_in, time_series): """ Test computing a functional connectivity matrix.""" network = 'Default' ID = '002' smooth = 2 coords = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] node_size = 8 extract_strategy = 'zscore' roi = None atlas = None uatlas = None labels = [1, 2, 3] outs = get_conn_matrix( time_series, conn_model_in, tempfile.TemporaryDirectory(), node_size, smooth, False, network, ID, roi, False, False, True, True, atlas, uatlas, labels, coords, 3, False, 0, extract_strategy, ) conn_matrix_out, conn_model_out = outs[0], outs[1] assert isinstance(conn_matrix_out, np.ndarray) assert np.shape(conn_matrix_out) == np.shape(time_series) assert conn_model_in == conn_model_out
def test_get_conn_matrix(conn_model_in, n_features): """ Test computing a functional connectivity matrix.""" tmp = tempfile.TemporaryDirectory() dir_path = str(tmp.name) os.makedirs(dir_path, exist_ok=True) subnet = 'Default' ID = '002' smooth = 2 coords = [(1, 2, 3), (4, 5, 6), (7, 8, 9)] node_radius = 8 signal = 'zscore' roi = None atlas = None parcellation = None labels = [1, 2, 3] time_series = generate_signals(n_features=n_features, n_confounds=5, length=n_features, same_variance=False)[0] outs = get_conn_matrix( time_series, conn_model_in, dir_path, node_radius, smooth, False, subnet, ID, roi, False, False, True, True, atlas, parcellation, labels, coords, 3, False, 0, signal, ) conn_matrix_out, conn_model_out = outs[0], outs[1] assert isinstance(conn_matrix_out, np.ndarray) assert np.shape(conn_matrix_out) == np.shape(time_series) assert conn_model_in == conn_model_out if "corr" in conn_model_in: assert (is_spd(conn_matrix_out, decimal=7)) d = np.sqrt(np.diag(np.diag(conn_matrix_out))) assert_array_almost_equal(np.diag(conn_matrix_out), np.ones(n_features)) elif "partcorr" in conn_model_in: prec = np.linalg.inv(conn_matrix_out) d = np.sqrt(np.diag(np.diag(prec))) assert_array_almost_equal( d.dot(conn_matrix_out).dot(d), -prec + 2 * np.diag(np.diag(prec))) tmp.cleanup()