Ejemplo n.º 1
0
def calculate_and_save_correlation(subj_1_num, subj_2_num):
    """
    Calculates correlation using smoothed 2-D data with 8 full width half
    maximum mm, and saves values into a designated correlation_path. If a file
    with calculated correlations already exists, uses that cached version
    instead.

    Parameters
    ----------
    subj_1_num : int
    subj_2_num : int

    Returns
    -------
    None
    """
    correlation_path = dp.get_correlation_path(subj_1_num, subj_2_num)
    if not exists(correlation_path) or not USE_CACHED_DATA:
        subj_1_data = np.load(dp.get_smoothed_2d_path(subj_1_num, 8))
        subj_2_data = np.load(dp.get_smoothed_2d_path(subj_2_num, 8))
        correlations = correlation(subj_1_data, subj_2_data)
        np.save(correlation_path, correlations)
        print('Saved {0}'.format(correlation_path))
    else:
        print('Using cached version of {0}'.format(correlation_path))
Ejemplo n.º 2
0
def test_get_correlation_path():
	subject_pairs = [(1, 2), (1, 3), (1, 4), (1, 5)]
	paths = [dp.get_correlation_path(pair[0], pair[1]) for pair in subject_pairs]
	assert paths[0] == '{0}/data/processed/sub1_sub2_correlation.npy'.format(
        REPO_HOME_PATH)
	assert paths[1] == '{0}/data/processed/sub1_sub3_correlation.npy'.format(
        REPO_HOME_PATH)
	assert paths[2] == '{0}/data/processed/sub1_sub4_correlation.npy'.format(
        REPO_HOME_PATH)
	assert paths[3] == '{0}/data/processed/sub1_sub5_correlation.npy'.format(
        REPO_HOME_PATH)
Ejemplo n.º 3
0
def test_get_correlation_path():
    subject_pairs = [(1, 2), (1, 3), (1, 4), (1, 5)]
    paths = [
        dp.get_correlation_path(pair[0], pair[1]) for pair in subject_pairs
    ]
    assert paths[0] == '{0}/data/processed/sub1_sub2_correlation.npy'.format(
        REPO_HOME_PATH)
    assert paths[1] == '{0}/data/processed/sub1_sub3_correlation.npy'.format(
        REPO_HOME_PATH)
    assert paths[2] == '{0}/data/processed/sub1_sub4_correlation.npy'.format(
        REPO_HOME_PATH)
    assert paths[3] == '{0}/data/processed/sub1_sub5_correlation.npy'.format(
        REPO_HOME_PATH)
Ejemplo n.º 4
0
def get_pairwise_correlations():
    """
    Finds and returns the paths to the correlations of all possible pairs of
    subjects (if the paths exist)

    Parameters
    ----------
    None

    Returns
    -------
    paths : string array
    """
    subject_pairs = itertools.combinations(SUBJECTS, 2)
    return [np.load(dp.get_correlation_path(subj_a, subj_b))
            for subj_a, subj_b in subject_pairs]
Ejemplo n.º 5
0
def get_pairwise_correlations(only_brain = True):
    """
    Finds and returns the paths to the correlations of all possible pairs of
    subjects (if the paths exist)

    Parameters
    ----------
    None

    Returns
    -------
    paths : string array
    """
    subject_pairs = itertools.combinations(SUBJECTS, 2)
    brain_mask = np.ravel(bm.get_brain_mask())
    correlations = [np.load(dp.get_correlation_path(subj_a, subj_b))
            for subj_a, subj_b in subject_pairs]
    if only_brain:
        return [c[brain_mask] for c in correlations]
    return correlations
Ejemplo n.º 6
0
def get_pairwise_correlations(only_brain=True):
    """
    Finds and returns the paths to the correlations of all possible pairs of
    subjects (if the paths exist)

    Parameters
    ----------
    None

    Returns
    -------
    paths : string array
    """
    subject_pairs = itertools.combinations(SUBJECTS, 2)
    brain_mask = np.ravel(bm.get_brain_mask())
    correlations = [
        np.load(dp.get_correlation_path(subj_a, subj_b))
        for subj_a, subj_b in subject_pairs
    ]
    if only_brain:
        return [c[brain_mask] for c in correlations]
    return correlations