def extract_coordinates_from_talstructs(subject_localization, rootdir="/"): talstruct_base_path = os.path.join(rootdir, "data10/RAM/subjects/{}/tal/{}_talLocs_database_{}.mat") # TODO: Use PathFinder once the matlab talstructs are available bipol_reader = TalReader(filename=talstruct_base_path.format(subject_localization, subject_localization, 'bipol'), struct_type='bi') bipol_structs = bipol_reader.read() mono_reader = TalReader(filename=talstruct_base_path.format(subject_localization, subject_localization, 'monopol'), struct_type='mono') mono_structs = mono_reader.read() mono_start_df = get_coords(mono_structs, 'monopolar') mono_start_df["contact_name"] = "o" + mono_start_df["contact_name"] mono_adj_df = get_coords(mono_structs, 'monopolar', atlas='Dykstra') bipo_adj_df = get_coords(bipol_structs, 'bipolar', atlas='Dykstra') all_coord_df = pd.concat([mono_start_df, mono_adj_df, bipo_adj_df]) return all_coord_df
def get_tal_structs_row(subject,anode_tag,cathode_tag): # '/Users/m/data/eeg/R1111M/tal/R1111M_talLocs_database_bipol.mat' # tal_path = join(mount_point,'data/eeg/',subject,'tal',subject+'_talLocs_database_bipol.mat') tal_path = str(join(mount_point,'data/eeg/',subject,'tal',subject+'_talLocs_database_monopol.mat')) tal_reader = TalReader(filename=tal_path,struct_name='talStruct') tal_structs = tal_reader.read() # sel = tal_structs[np.where(tal_structs.tagName == anode_tag+'-'+cathode_tag)] sel = tal_structs[np.where((tal_structs.tagName == anode_tag)|(tal_structs.tagName == cathode_tag))] if not len(sel): sel = tal_structs[np.where((tal_structs.tagName == anode_tag)|(tal_structs.tagName == cathode_tag))] if not len(sel): tal_path = str(join(mount_point,'data/eeg/',subject,'tal',subject+'_talLocs_database_stimOnly.mat')) tal_reader = TalStimOnlyReader(filename=tal_path) tal_structs = tal_reader.read() sel = tal_structs[np.where((tal_structs.tagName == anode_tag)|(tal_structs.tagName == cathode_tag))] if not len(sel): sel = tal_structs[np.where((tal_structs.tagName == anode_tag)|(tal_structs.tagName == cathode_tag))] return sel
def get_tal_structs_row(subject, anode_tag, cathode_tag): # '/Users/m/data/eeg/R1111M/tal/R1111M_talLocs_database_bipol.mat' # tal_path = join(mount_point,'data/eeg/',subject,'tal',subject+'_talLocs_database_bipol.mat') tal_path = str( join(mount_point, 'data/eeg/', subject, 'tal', subject + '_talLocs_database_monopol.mat')) tal_reader = TalReader(filename=tal_path, struct_name='talStruct') tal_structs = tal_reader.read() # sel = tal_structs[np.where(tal_structs.tagName == anode_tag+'-'+cathode_tag)] sel = tal_structs[np.where((tal_structs.tagName == anode_tag) | (tal_structs.tagName == cathode_tag))] if not len(sel): sel = tal_structs[np.where((tal_structs.tagName == anode_tag) | (tal_structs.tagName == cathode_tag))] if not len(sel): tal_path = str( join(mount_point, 'data/eeg/', subject, 'tal', subject + '_talLocs_database_stimOnly.mat')) tal_reader = TalStimOnlyReader(filename=tal_path) tal_structs = tal_reader.read() sel = tal_structs[np.where((tal_structs.tagName == anode_tag) | (tal_structs.tagName == cathode_tag))] if not len(sel): sel = tal_structs[np.where((tal_structs.tagName == anode_tag) | (tal_structs.tagName == cathode_tag))] return sel
def extract_electrode_positions(tal_path): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array(map( lambda loc : loc.startswith('Left'), tal_structs.Loc1)) rh_selector = np.array(map( lambda loc : loc.startswith('Right'), tal_structs.Loc1)) lh_avg_surf = tal_structs.avgSurf[lh_selector] rh_avg_surf = tal_structs.avgSurf[rh_selector] return lh_avg_surf, rh_avg_surf
def get_bp_tal_struct(sub, montage=0): from ptsa.data.readers import TalReader #Get electrode information -- bipolar tal_path = '/protocols/r1/subjects/' + sub + '/localizations/0/montages/' + str( montage) + '/neuroradiology/current_processed/pairs.json' tal_reader = TalReader(filename=tal_path) tal_struct = tal_reader.read() monopolar_channels = tal_reader.get_monopolar_channels() bipolar_pairs = tal_reader.get_bipolar_pairs() return tal_struct, bipolar_pairs, monopolar_channels
def extract_electrode_positions(tal_path): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array( map(lambda loc: loc.startswith('Left'), tal_structs.Loc1)) rh_selector = np.array( map(lambda loc: loc.startswith('Right'), tal_structs.Loc1)) lh_avg_surf = tal_structs.avgSurf[lh_selector] rh_avg_surf = tal_structs.avgSurf[rh_selector] return lh_avg_surf, rh_avg_surf
def extract_electrode_positions(tal_path, electrode_types=['D', 'G', 'S'], hemi=['R', 'L']): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() electrode_types_lower = map(lambda t: t.lower(), electrode_types) electrode_type_selector = np.array( map(lambda eType: eType.lower() in electrode_types_lower, tal_structs.eType)) h_data = tal_structs[['avgSurf', 'eType']] h_data = h_data[electrode_type_selector] return h_data
def extract_electrode_positions(tal_path, electrode_types=['D', 'G', 'S'], hemi=['R','L']): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() electrode_types_lower = map(lambda t: t.lower(), electrode_types) electrode_type_selector = np.array(map(lambda eType: eType.lower() in electrode_types_lower, tal_structs.eType)) h_data = tal_structs[['avgSurf','eType']] h_data = h_data[electrode_type_selector] return h_data
def extract_electrode_positions(tal_path, electrode_types=['D', 'G', 'S']): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array(map(lambda loc: loc.upper().startswith('L'), tal_structs.tagName)) rh_selector = np.array(map(lambda loc: loc.upper().startswith('R'), tal_structs.tagName)) electrode_types_lower = map(lambda t: t.lower(), electrode_types) electrode_type_selector = np.array(map(lambda eType: eType.lower() in electrode_types_lower, tal_structs.eType)) lh_data = tal_structs[['avgSurf','eType']] rh_data = tal_structs[['avgSurf','eType']] lh_data = lh_data[lh_selector & electrode_type_selector] rh_data = rh_data[rh_selector & electrode_type_selector] return lh_data,rh_data
def extract_electrode_positions(tal_path, electrode_types=['D', 'G', 'S']): from ptsa.data.readers import TalReader tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array(map(lambda loc: loc.upper().startswith('L'), tal_structs.tagName)) rh_selector = np.array(map(lambda loc: loc.upper().startswith('R'), tal_structs.tagName)) electrode_types_lower = map(lambda t: t.lower(), electrode_types) electrode_type_selector = np.array(map(lambda eType: eType.lower() in electrode_types_lower, tal_structs.eType)) lh_data = tal_structs[['avgSurf','eType']] rh_data = tal_structs[['avgSurf','eType']] lh_data = lh_data[lh_selector & electrode_type_selector] rh_data = rh_data[rh_selector & electrode_type_selector] return lh_data,rh_data
def construct_significant_elec_info(df): tal_structs = None subject = '' lh_selector = None rh_selector = None lh_data_combined = None rh_data_combined = None for index, row in df.iterrows(): if subject != row['Subject']: subject = row['Subject'] # '/Users/m/data/eeg/R1111M/tal/R1111M_talLocs_database_bipol.mat' tal_path = join(mount_point,'data/eeg/',subject,'tal',subject+'_talLocs_database_bipol.mat') tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array(map(lambda loc: loc.upper().startswith('L'), tal_structs.tagName)) rh_selector = np.array(map(lambda loc: loc.upper().startswith('R'), tal_structs.tagName)) lh_data = tal_structs[['avgSurf','eType','tagName']] rh_data = tal_structs[['avgSurf','eType','tagName']] lh_data = lh_data[lh_selector] rh_data = rh_data[rh_selector] lh_sel = get_elec_data_coords_array(lh_data[np.where(lh_data.tagName == row['stimAnodeTag']+'-'+row['stimCathodeTag'])]) lh_sel_flip = get_elec_data_coords_array(lh_data[np.where(lh_data.tagName == row['stimCathodeTag']+'-'+row['stimAnodeTag'])]) rh_sel = get_elec_data_coords_array(rh_data[np.where(rh_data.tagName == row['stimAnodeTag']+'-'+row['stimCathodeTag'])]) rh_sel_flip = get_elec_data_coords_array(rh_data[np.where(rh_data.tagName == row['stimCathodeTag']+'-'+row['stimAnodeTag'])]) lh_data_combined = append_to_combined(lh_data_combined,lh_sel,lh_sel_flip) rh_data_combined = append_to_combined(rh_data_combined,rh_sel,rh_sel_flip) # lh_sel_stack = vstack_arrays(lh_sel,lh_sel_flip) # rh_sel_stack = vstack_arrays(rh_sel,rh_sel_flip) # # # lh_tmp = np.vstack((lh_sel,lh_sel_flip)) # rh_tmp = np.vstack((rh_sel,rh_sel_flip)) # # if not lh_data_combined: # lh_data_combined = lh_tmp # else: # lh_data_combined = np.vstack((lh_data_combined,lh_tmp)) # # if not rh_data_combined: # rh_data_combined = rh_tmp # else: # rh_data_combined = np.vstack((rh_data_combined,rh_tmp)) print rh_data_combined print lh_data_combined return lh_data_combined, rh_data_combined
def test_with_version_no(): fname = osp.join(osp.dirname(__file__), 'data', 'pairs.json') tal_reader = TalReader(filename=fname) tal_reader.read()
def construct_significant_elec_info(df): tal_structs = None subject = '' lh_selector = None rh_selector = None lh_data_combined = None rh_data_combined = None for index, row in df.iterrows(): if subject != row['Subject']: subject = row['Subject'] # '/Users/m/data/eeg/R1111M/tal/R1111M_talLocs_database_bipol.mat' tal_path = join(mount_point, 'data/eeg/', subject, 'tal', subject + '_talLocs_database_bipol.mat') tal_reader = TalReader(filename=tal_path) tal_structs = tal_reader.read() lh_selector = np.array( map(lambda loc: loc.upper().startswith('L'), tal_structs.tagName)) rh_selector = np.array( map(lambda loc: loc.upper().startswith('R'), tal_structs.tagName)) lh_data = tal_structs[['avgSurf', 'eType', 'tagName']] rh_data = tal_structs[['avgSurf', 'eType', 'tagName']] lh_data = lh_data[lh_selector] rh_data = rh_data[rh_selector] lh_sel = get_elec_data_coords_array( lh_data[np.where(lh_data.tagName == row['stimAnodeTag'] + '-' + row['stimCathodeTag'])]) lh_sel_flip = get_elec_data_coords_array( lh_data[np.where(lh_data.tagName == row['stimCathodeTag'] + '-' + row['stimAnodeTag'])]) rh_sel = get_elec_data_coords_array( rh_data[np.where(rh_data.tagName == row['stimAnodeTag'] + '-' + row['stimCathodeTag'])]) rh_sel_flip = get_elec_data_coords_array( rh_data[np.where(rh_data.tagName == row['stimCathodeTag'] + '-' + row['stimAnodeTag'])]) lh_data_combined = append_to_combined(lh_data_combined, lh_sel, lh_sel_flip) rh_data_combined = append_to_combined(rh_data_combined, rh_sel, rh_sel_flip) # lh_sel_stack = vstack_arrays(lh_sel,lh_sel_flip) # rh_sel_stack = vstack_arrays(rh_sel,rh_sel_flip) # # # lh_tmp = np.vstack((lh_sel,lh_sel_flip)) # rh_tmp = np.vstack((rh_sel,rh_sel_flip)) # # if not lh_data_combined: # lh_data_combined = lh_tmp # else: # lh_data_combined = np.vstack((lh_data_combined,lh_tmp)) # # if not rh_data_combined: # rh_data_combined = rh_tmp # else: # rh_data_combined = np.vstack((rh_data_combined,rh_tmp)) print rh_data_combined print lh_data_combined return lh_data_combined, rh_data_combined