From 10b5e8dcf09922e5c968a95262b3d0643081d917 Mon Sep 17 00:00:00 2001 From: raihaan Date: Fri, 7 May 2021 14:53:14 -0400 Subject: [PATCH] added code to output .txt files for mean and std dev of each metric during metric extract step --- vertex/extract_metrics.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/vertex/extract_metrics.py b/vertex/extract_metrics.py index 728e38f..086c540 100644 --- a/vertex/extract_metrics.py +++ b/vertex/extract_metrics.py @@ -41,10 +41,14 @@ def load_vertex_data(df, column, n_subjects, n_vertex, mask=None): else: vertex_data = np.concatenate( (vertex_data, np.loadtxt(fname).reshape(1,n_vertex)), axis=0) + + vertex_mean = np.mean(vertex_data,axis=0) + vertex_std = np.std(vertex_data,axis=0) + if mask is not None: - return vertex_data[:,mask] + return vertex_data[:,mask], vertex_mean, vertex_std else: - return vertex_data + return vertex_data, vertex_mean, vertex_std def save_mat(x,key,fname): print("Saving ", np.shape(x), key, "to", fname) @@ -65,8 +69,12 @@ def save_mat(x,key,fname): metric = m[0] #args.metric is list of lists, each w length 1. we just want the metric, not whole list print('extracting', metric) for c_idx,c in enumerate(args.metric_column[m_idx]): - vertex_data = load_vertex_data(df_inputs,c,n_subjects,n_vertex, valid_vertices) + vertex_data, vertex_mean, vertex_std = load_vertex_data(df_inputs,c,n_subjects,n_vertex, valid_vertices) + + np.savetxt(c + '_mean.txt',vertex_mean.astype('float32'),delimiter='\t',fmt='%f') + np.savetxt(c + '_stdev.txt',vertex_std.astype('float32'),delimiter='\t',fmt='%f') save_mat(np.transpose(vertex_data), c, c + '.mat') + if c_idx == 0: metric_dict[metric] = np.transpose(vertex_data.copy()) else: