Skip to content

Commit

Permalink
add merge_conndata_subjects to data.py
Browse files Browse the repository at this point in the history
  • Loading branch information
kjamison committed May 1, 2024
1 parent ebcd490 commit c956436
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion krakencoder/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,34 @@ def get_subjects_from_conndata(conndata, subjects=None, remove_subjects=None):
conndata_new[k]=conndata[k].copy()

return conndata_new


def merge_conndata_subjects(conndata_list):
"""
Merge a list of conndata dicts, each with the same 'subjects' field, into a single conndata dict with all subjects concatenated
Parameters:
conndata_list: list of conndata dicts with 'subjects' and 'data' fields
Returns:
conndata_new: dict, new conndata dict with all subjects concatenated
"""
if not ('subjects' in conndata_list[0] and 'data' in conndata_list[0]):
#if provided a multi-flavor input, loop over the flavors
#(make deep copy)
conndata_new={}
for conntype in conndata_list[0].keys():
conndata_new[conntype]=merge_conndata_subjects([c[conntype] for c in conndata_list])
return conndata_new

#make new deep copy of data
conndata_new={}
for k in conndata_list[0].keys():
if np.size(conndata_list[0][k])<=1:
conndata_new[k]=conndata_list[0][k]
else:
conndata_new[k]=np.concatenate([c[k] for c in conndata_list],axis=0)
return conndata_new

def load_hcp_data(subjects=[], conn_name_list=[], load_retest=False, quiet=False, keep_diagonal=False):
"""
Load HCP data from a set of subjects and a list of data types, using hardcoded input paths
Expand Down

0 comments on commit c956436

Please sign in to comment.