Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes in cpac_correlations #8

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions cpac_correlations.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,20 @@ def batch_correlate(
https://en.wikipedia.org/wiki/Concordance_correlation_coefficient
"""
# Summary stats for x
x_mean = np.mean(x, axis=axis, keepdims=True)
x_var = np.var(x, axis=axis, keepdims=True)
x_mean = np.mean(x, axis=axis)
x_var = np.var(x, axis=axis)
x_std = np.sqrt(x_var)
# NOTE: Not trying to fix NaNs
x_norm = (x - x_mean) / x_std

# Summary stats for y
y_mean = np.mean(y, axis=axis, keepdims=True)
y_var = np.var(y, axis=axis, keepdims=True)
y_mean = np.mean(y, axis=axis)
y_var = np.var(y, axis=axis)
y_std = np.sqrt(y_var)
y_norm = (y - y_mean) / y_std

# Correlation coefficients
pearson = np.mean(x_norm * y_norm, axis=axis, keepdims=True)
pearson = np.mean(x_norm * y_norm, axis=axis)
concor = 2 * pearson * x_std * y_std / (x_var + y_var + (x_mean - y_mean) ** 2)

# Squeeze reduced singleton dimensions
Expand Down Expand Up @@ -558,8 +558,8 @@ def calculate_correlation(args_tuple):
old_file_dims = old_file_hdr.get_zooms()
new_file_dims = new_file_hdr.get_zooms()

data_1 = nb.load(old_path).get_data()
data_2 = nb.load(new_path).get_data()
data_1 = nb.load(old_path).get_fdata()
data_2 = nb.load(new_path).get_fdata()

except Exception as e:
corr_tuple = ("file reading problem: {0}".format(e),
Expand Down Expand Up @@ -858,7 +858,7 @@ def create_boxplot(corr_group, corr_group_name, pipeline_names=None,
if "file reading problem" in label:
continue
try:
allData.append(np.asarray(corr_group[label]).astype(np.float))
allData.append(np.asarray(corr_group[label]).astype(float))
except ValueError as ve:
continue
#raise Exception(ve)
Expand Down