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 __init__(self, **kwds): ''' Constructor: :param kwds:allowed values are: ------------------------------------- :param filename {str} - path to tal file :param struct_name {str} - name of the matlab struct to load :return: None ''' TalReader.__init__(self, **kwds) self.struct_name = 'virtualTalStruct'
def __init__(self, **kwds): ''' Constructor: :param kwds:allowed values are: ------------------------------------- :param filename {str} - path to tal file :param struct_name {str} - name of the matlab struct to load :return: None ''' TalReader.__init__(self, **kwds) self.struct_name = 'virtualTalStruct'
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 read_session(subject, root, experiment, rhino_root): jr = JsonIndexReader(rhino_root + '/protocols/r1.json') # Build JSON reader pairs_path = jr.get_value('pairs', subject=subject, experiment=experiment) tal_reader = TalReader(filename=pairs_path) monopolar_channels = tal_reader.get_monopolar_channels() bipolar_channels = tal_reader.get_bipolar_pairs() jr = JsonIndexReader(rhino_root + '/protocols/r1.json') # Build JSON reader pairs_path = jr.get_value('pairs', subject=subject, experiment=experiment) tal_reader = TalReader(filename=pairs_path) monopolar_channels = tal_reader.get_monopolar_channels() p_reader = ParamsReader(dataroot=root) params = p_reader.read() samplerate = params['samplerate'] print samplerate try: raw_eeg = EEGReader(session_dataroot=root, channels = monopolar_channels) raw_eeg = raw_eeg.read() print raw_eeg.shape except: with h5py.File(root, 'r') as hfile: raw_eeg = H5RawReader.H5RawReader.read_h5file(hfile, monopolar_channels,[0])[0] print raw_eeg.shape raw_eeg = TimeSeriesX.TimeSeriesX(raw_eeg, dims=['channels', 'start_offsets', 'time'], coords={ 'channels': monopolar_channels, 'start_offsets': [0], 'time': np.arange(raw_eeg.shape[2])*1000/samplerate, 'offsets': ('time',np.arange(raw_eeg.shape[2])), 'samplerate': samplerate}) return raw_eeg
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 test_talreader_on_database(): old_reader = TalReader( filename= '/Volumes/rhino_root/data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat' ) jr = JsonIndexReader('/Volumes/rhino_root/protocols/r1.json') new_reader = TalReader( filename=jr.get_value('pairs', subject='R1234D', experiment='FR1')) assert new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs() assert new_reader.get_monopolar_channels( ) == old_reader.get_monopolar_channels()
def test_talreader_on_database(): old_reader = TalReader(filename=osp.join( utils.get_rhino_root(), 'data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat')) jr = JsonIndexReader(osp.join(utils.get_rhino_root(), 'protocols/r1.json')) new_reader = TalReader( filename=jr.get_value('pairs', subject='R1234D', experiment='FR1')) assert (new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs() ).all() assert (new_reader.get_monopolar_channels() == old_reader.get_monopolar_channels()).all()
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 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 _test_eeg_with_tal_struct(self, subject, experiment, session, struct_type='mono'): from ptsa.data.readers import JsonIndexReader,TalReader,EEGReader,BaseEventReader import os tal_file = 'contacts' if struct_type=='mono' else 'pairs' jr = JsonIndexReader(os.path.join(get_rhino_root(),'protocols','r1.json')) events = BaseEventReader(filename=jr.get_value('task_events',subject=subject,experiment=experiment,session=session)).read() tal_struct = TalReader(filename=jr.get_value(tal_file,subject=subject),struct_type=struct_type).read() eeg_reader = EEGReader(events=events[:10],channels=tal_struct[:10],start_time=0.0,end_time=0.1) eeg = eeg_reader.read() print(eeg) channel_name = eeg_reader.channel_name for col in tal_struct.dtype.names: if col != 'atlases': # Because I don't want to deal with NaNs at the moment assert_array_equal(eeg[channel_name].data[col],tal_struct[:10][col])
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 __init__(self, **kwds): TalReader.__init__(self, **kwds) self.struct_name = 'virtualTalStruct'
def __init__(self, **kwds): TalReader.__init__(self, **kwds) self.struct_name = 'virtualTalStruct'
def test_from_dict(): pairs_dict = { u'R1111M': { u'code': u'R1111M', u'id': u'r1.111.0_0', u'pairs': { u'LAS1-LAS2': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiortemporal', u'x': -42.61, u'y': 1.125, u'z': -47.255 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiortemporal', u'x': -40.325014, u'y': -0.977092, u'z': -42.874617 }, u'dk': { u'id': u'dk', u'region': u'inferiortemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'inferiortemporal', u'x': -35.445, u'y': 13.665, u'z': -61.24 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'inferiortemporal', u'x': -35.617608, u'y': 14.180917, u'z': -61.773298 }, u'mni': { u'id': u'mni', u'region': None, u'x': -44.2202, u'y': -3.57164, u'z': -47.2775337826913 }, u'tal': { u'id': u'tal', u'region': None, u'x': -44.438, u'y': -0.9717655, u'z': -40.04145 } }, u'channel_1': 89, u'channel_2': 90, u'code': u'LAS1-LAS2', u'id': u'las.1-las.2', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LAS2-LAS3': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'middletemporal', u'x': -50.97, u'y': 3.555, u'z': -41.405 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiortemporal', u'x': -47.8082255, u'y': 2.239497, u'z': -37.192936 }, u'dk': { u'id': u'dk', u'region': u'middletemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'middletemporal', u'x': -43.275, u'y': 16.62, u'z': -56.25 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'middletemporal', u'x': -43.5149515, u'y': 16.4580355, u'z': -55.944128 }, u'mni': { u'id': u'mni', u'region': None, u'x': -54.7232, u'y': 5.86805, u'z': -40.4636384749486 }, u'tal': { u'id': u'tal', u'region': None, u'x': -53.0634, u'y': 1.0772995, u'z': -35.2313 } }, u'channel_1': 90, u'channel_2': 91, u'code': u'LAS2-LAS3', u'id': u'las.2-las.3', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LAS3-LAS4': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'middletemporal', u'x': -55.865, u'y': 5.325, u'z': -32.175 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'middletemporal', u'x': -53.7415735, u'y': 4.1258245, u'z': -30.37393 }, u'dk': { u'id': u'dk', u'region': u'middletemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'middletemporal', u'x': -47.9, u'y': 18.98, u'z': -48.155 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'middletemporal', u'x': -48.4478225, u'y': 18.0682125, u'z': -47.8244455 }, u'mni': { u'id': u'mni', u'region': None, u'x': -60.0524, u'y': 9.01968, u'z': -30.4733115958087 }, u'tal': { u'id': u'tal', u'region': None, u'x': -58.06875, u'y': 2.924265, u'z': -27.53625 } }, u'channel_1': 91, u'channel_2': 92, u'code': u'LAS3-LAS4', u'id': u'las.3-las.4', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOAD1-LOAD2': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'cuneus', u'x': -13.63, u'y': -66.385, u'z': 15.19 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'cuneus', u'x': -13.63, u'y': -66.385, u'z': 15.19 }, u'dk': { u'id': u'dk', u'region': u'cuneus', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'cuneus', u'x': -11.505, u'y': -48.95, u'z': -1.285 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'cuneus', u'x': -11.505, u'y': -48.95, u'z': -1.285 }, u'mni': { u'id': u'mni', u'region': None, u'x': -11.6775, u'y': -64.569, u'z': 16.3181365099509 }, u'tal': { u'id': u'tal', u'region': None, u'x': -11.52777, u'y': -60.041, u'z': 17.80605 }, u'wb': { u'id': u'wb', u'region': u'Left Cerebral White Matter', u'x': None, u'y': None, u'z': None } }, u'channel_1': 65, u'channel_2': 66, u'code': u'LOAD1-LOAD2', u'id': u'load.1-load.2', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOAD2-LOAD3': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'precuneus', u'x': -18.59, u'y': -66.81, u'z': 14.165 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'precuneus', u'x': -18.59, u'y': -66.81, u'z': 14.165 }, u'dk': { u'id': u'dk', u'region': u'precuneus', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'precuneus', u'x': -16.185, u'y': -49.215, u'z': -2.245 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'precuneus', u'x': -16.185, u'y': -49.215, u'z': -2.245 }, u'mni': { u'id': u'mni', u'region': None, u'x': -16.7927, u'y': -65.7112, u'z': 13.4931492118311 }, u'tal': { u'id': u'tal', u'region': None, u'x': -16.62185, u'y': -60.85595, u'z': 16.8891 }, u'wb': { u'id': u'wb', u'region': u'Left Cerebral White Matter', u'x': None, u'y': None, u'z': None } }, u'channel_1': 66, u'channel_2': 67, u'code': u'LOAD2-LOAD3', u'id': u'load.2-load.3', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOAD3-LOAD4': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'precuneus', u'x': -23.555, u'y': -67.235, u'z': 13.14 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'precuneus', u'x': -23.555, u'y': -67.235, u'z': 13.14 }, u'dk': { u'id': u'dk', u'region': u'precuneus', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'precuneus', u'x': -20.86, u'y': -49.48, u'z': -3.205 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'precuneus', u'x': -20.86, u'y': -49.48, u'z': -3.205 }, u'mni': { u'id': u'mni', u'region': None, u'x': -21.0773, u'y': -65.9614, u'z': 12.2086643183131 }, u'tal': { u'id': u'tal', u'region': None, u'x': -21.71595, u'y': -61.67085, u'z': 15.9722 }, u'wb': { u'id': u'wb', u'region': u'Left Calc calcarine cortex', u'x': None, u'y': None, u'z': None } }, u'channel_1': 67, u'channel_2': 68, u'code': u'LOAD3-LOAD4', u'id': u'load.3-load.4', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOPD1-LOPD2': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -30.63, u'y': -81.945, u'z': 58.94 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -30.63, u'y': -81.945, u'z': 58.94 }, u'dk': { u'id': u'dk', u'region': u'superiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -28.56, u'y': -60.95, u'z': 38.47 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiorparietal', u'x': -28.56, u'y': -60.95, u'z': 38.47 }, u'mni': { u'id': u'mni', u'region': None, u'x': -24.5621, u'y': -79.1906, u'z': 62.4706843403474 }, u'tal': { u'id': u'tal', u'region': None, u'x': -27.9833, u'y': -73.56945, u'z': 59.18815 } }, u'channel_1': 69, u'channel_2': 70, u'code': u'LOPD1-LOPD2', u'id': u'lopd.1-lopd.2', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOPD2-LOPD3': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -29.755, u'y': -82.795, u'z': 53.795 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -29.755, u'y': -82.795, u'z': 53.795 }, u'dk': { u'id': u'dk', u'region': u'superiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -27.72, u'y': -62.065, u'z': 33.925 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiorparietal', u'x': -27.72, u'y': -62.065, u'z': 33.925 }, u'mni': { u'id': u'mni', u'region': None, u'x': -23.5147, u'y': -80.1419, u'z': 58.2811043268419 }, u'tal': { u'id': u'tal', u'region': None, u'x': -27.1024, u'y': -74.62095, u'z': 54.4778 } }, u'channel_1': 70, u'channel_2': 71, u'code': u'LOPD2-LOPD3', u'id': u'lopd.2-lopd.3', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOPD3-LOPD4': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -28.88, u'y': -83.65, u'z': 48.65 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -28.88, u'y': -83.65, u'z': 48.65 }, u'dk': { u'id': u'dk', u'region': u'superiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -26.88, u'y': -63.18, u'z': 29.38 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiorparietal', u'x': -26.88, u'y': -63.18, u'z': 29.38 }, u'mni': { u'id': u'mni', u'region': None, u'x': -23.2005, u'y': -81.3792, u'z': 52.8415514608542 }, u'tal': { u'id': u'tal', u'region': None, u'x': -26.2215, u'y': -75.6724, u'z': 49.7675 } }, u'channel_1': 71, u'channel_2': 72, u'code': u'LOPD3-LOPD4', u'id': u'lopd.3-lopd.4', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'D', u'type_2': u'D' }, u'LOS1-LOS2': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -28.385, u'y': -80.54, u'z': 46.795 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -31.9624765, u'y': -80.009785, u'z': 43.7571925 }, u'dk': { u'id': u'dk', u'region': u'superiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -26.27, u'y': -60.31, u'z': 27.565 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiorparietal', u'x': -25.621956, u'y': -59.0888045, u'z': 26.9537985 }, u'mni': { u'id': u'mni', u'region': None, u'x': -25.983, u'y': -81.6538, u'z': 51.4410530734692 }, u'tal': { u'id': u'tal', u'region': None, u'x': -25.84895, u'y': -72.772, u'z': 47.876 } }, u'channel_1': 73, u'channel_2': 74, u'code': u'LOS1-LOS2', u'id': u'los.1-los.2', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS2-LOS3': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -30.79, u'y': -85.275, u'z': 37.305 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -31.896347, u'y': -85.034851, u'z': 36.6861385 }, u'dk': { u'id': u'dk', u'region': u'superiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -28.63, u'y': -65.25, u'z': 19.3 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiorparietal', u'x': -28.5924815, u'y': -64.2941325, u'z': 18.8504215 }, u'mni': { u'id': u'mni', u'region': None, u'x': -29.2536, u'y': -87.3907, u'z': 39.7327475322989 }, u'tal': { u'id': u'tal', u'region': None, u'x': -28.23555, u'y': -78.0252, u'z': 39.37745 } }, u'channel_1': 74, u'channel_2': 75, u'code': u'LOS2-LOS3', u'id': u'los.2-los.3', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS3-LOS4': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -32.68, u'y': -89.495, u'z': 27.425 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -32.7484685, u'y': -89.9033505, u'z': 27.7109635 }, u'dk': { u'id': u'dk', u'region': u'inferiorparietal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiorparietal', u'x': -30.48, u'y': -69.73, u'z': 10.67 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'inferiorparietal', u'x': -31.2447985, u'y': -69.772751, u'z': 10.943914 }, u'mni': { u'id': u'mni', u'region': None, u'x': -28.9378, u'y': -90.4938, u'z': 30.1770576010663 }, u'tal': { u'id': u'tal', u'region': None, u'x': -30.11915, u'y': -82.77085, u'z': 30.48975 } }, u'channel_1': 75, u'channel_2': 76, u'code': u'LOS3-LOS4', u'id': u'los.3-los.4', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS4-LOS5': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'inferiorparietal', u'x': -34.055, u'y': -92.945, u'z': 17.17 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiorparietal', u'x': -33.332989, u'y': -92.530365, u'z': 17.8096305 }, u'dk': { u'id': u'dk', u'region': u'lateraloccipital', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'lateraloccipital', u'x': -31.81, u'y': -73.51, u'z': 1.665 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'lateraloccipital', u'x': -31.8847475, u'y': -72.704563, u'z': 1.0278435 }, u'mni': { u'id': u'mni', u'region': None, u'x': -30.6632, u'y': -93.3643, u'z': 21.1368810115199 }, u'tal': { u'id': u'tal', u'region': None, u'x': -31.5062, u'y': -86.76545, u'z': 21.20715 } }, u'channel_1': 76, u'channel_2': 77, u'code': u'LOS4-LOS5', u'id': u'los.4-los.5', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS5-LOS6': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'lateraloccipital', u'x': -34.905, u'y': -95.89, u'z': 6.915 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'lateraloccipital', u'x': -34.6101875, u'y': -93.081612, u'z': 6.177663 }, u'dk': { u'id': u'dk', u'region': u'lateraloccipital', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'lateraloccipital', u'x': -32.625, u'y': -76.83, u'z': -7.36 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'lateraloccipital', u'x': -32.195423, u'y': -76.221016, u'z': -8.764146 }, u'mni': { u'id': u'mni', u'region': None, u'x': -32.9977, u'y': -95.148, u'z': 11.1991202643372 }, u'tal': { u'id': u'tal', u'region': None, u'x': -32.3739, u'y': -90.24175, u'z': 11.896825 } }, u'channel_1': 77, u'channel_2': 78, u'code': u'LOS5-LOS6', u'id': u'los.5-los.6', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS6-LOS7': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'lateraloccipital', u'x': -34.19, u'y': -96.555, u'z': -3.695 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'lateraloccipital', u'x': -34.6314465, u'y': -94.574303, u'z': -4.7864505 }, u'dk': { u'id': u'dk', u'region': u'lateraloccipital', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'lateraloccipital', u'x': -31.87, u'y': -78.04, u'z': -16.805 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'lateraloccipital', u'x': -31.569232, u'y': -78.955883, u'z': -17.3940285 }, u'mni': { u'id': u'mni', u'region': None, u'x': -33.9091, u'y': -97.6849, u'z': -0.635968502853124 }, u'tal': { u'id': u'tal', u'region': None, u'x': -31.7196, u'y': -91.4269, u'z': 2.452 } }, u'channel_1': 78, u'channel_2': 79, u'code': u'LOS6-LOS7', u'id': u'los.6-los.7', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LOS7-LOS8': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'lateraloccipital', u'x': -30.79, u'y': -92.98, u'z': -12.66 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'lateraloccipital', u'x': -30.919649, u'y': -92.046631, u'z': -13.7526315 }, u'dk': { u'id': u'dk', u'region': u'lateraloccipital', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'lateraloccipital', u'x': -28.44, u'y': -75.205, u'z': -24.975 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'lateraloccipital', u'x': -28.6223425, u'y': -76.2744675, u'z': -24.8487765 }, u'mni': { u'id': u'mni', u'region': None, u'x': -29.8776, u'y': -96.3908, u'z': -12.3233510754761 }, u'tal': { u'id': u'tal', u'region': None, u'x': -28.45005, u'y': -88.25875, u'z': -5.44166 } }, u'channel_1': 79, u'channel_2': 80, u'code': u'LOS7-LOS8', u'id': u'los.7-los.8', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'S', u'type_2': u'S' }, u'LPOG1-LPOG2': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'middletemporal', u'x': -66.14, u'y': -18.33, u'z': -21.425 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'middletemporal', u'x': -64.5034485, u'y': -17.996502, u'z': -19.586545 }, u'dk': { u'id': u'dk', u'region': u'middletemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'middletemporal', u'x': -58.625, u'y': -2.74, u'z': -37.385 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'middletemporal', u'x': -57.8816775, u'y': -1.366716, u'z': -36.8690175 }, u'mni': { u'id': u'mni', u'region': None, u'x': -70.0048, u'y': -20.3756, u'z': -21.8269386012566 }, u'tal': { u'id': u'tal', u'region': None, u'x': -67.6431, u'y': -19.84015, u'z': -17.08995 } }, u'channel_1': 1, u'channel_2': 2, u'code': u'LPOG1-LPOG2', u'id': u'lpog.1-lpog.2', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'G', u'type_2': u'G' }, u'LPOG1-LPOG9': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'middletemporal', u'x': -65.295, u'y': -24.035, u'z': -25.98 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'inferiortemporal', u'x': -61.0239315, u'y': -23.5120125, u'z': -24.3799705 }, u'dk': { u'id': u'dk', u'region': u'middletemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'middletemporal', u'x': -58.01, u'y': -8.475, u'z': -41.135 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'middletemporal', u'x': -57.6646155, u'y': -8.8993865, u'z': -41.8339195 }, u'mni': { u'id': u'mni', u'region': None, u'x': -67.0841, u'y': -24.6176, u'z': -27.0443846559308 }, u'tal': { u'id': u'tal', u'region': None, u'x': -66.6047, u'y': -25.48, u'z': -20.6093 } }, u'channel_1': 1, u'channel_2': 9, u'code': u'LPOG1-LPOG9', u'id': u'lpog.1-lpog.9', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'G', u'type_2': u'G' }, u'LPOG10-LPOG11': { u'atlases': { u'avg': { u'id': u'avg', u'region': u'middletemporal', u'x': -66.93, u'y': -28.895, u'z': -9.695 }, u'avg.dural': { u'id': u'avg.dural', u'region': u'middletemporal', u'x': -65.264931, u'y': -29.3022265, u'z': -10.6323445 }, u'dk': { u'id': u'dk', u'region': u'superiortemporal', u'x': None, u'y': None, u'z': None }, u'ind': { u'id': u'ind', u'region': u'superiortemporal', u'x': -59.91, u'y': -12.235, u'z': -26.325 }, u'ind.dural': { u'id': u'ind.dural', u'region': u'superiortemporal', u'x': -59.692081, u'y': -12.535966, u'z': -26.175064 }, u'mni': { u'id': u'mni', u'region': None, u'x': -71.2307, u'y': -28.8535, u'z': -9.78374566316842 }, u'tal': { u'id': u'tal', u'region': None, u'x': -67.94285, u'y': -29.3608, u'z': -6.578205 } }, u'channel_1': 10, u'channel_2': 11, u'code': u'LPOG10-LPOG11', u'id': u'lpog.10-lpog.11', u'is_explicit': False, u'is_stim_only': False, u'type_1': u'G', u'type_2': u'G' }, } } } pairs_array = TalReader('').from_dict(pairs_dict) channel_array = np.array( sorted([[89, 90], [90, 91], [91, 92], [65, 66], [66, 67], [67, 68], [69, 70], [70, 71], [71, 72], [73, 74], [74, 75], [75, 76], [76, 77], [77, 78], [78, 79], [79, 80], [1, 2], [1, 9], [10, 11]])) assert pairs_array.channel.shape == channel_array.shape assert (pairs_array.channel == channel_array).all()
def test_with_version_no(): fname = osp.join(osp.dirname(__file__), 'data', 'pairs.json') tal_reader = TalReader(filename=fname) tal_reader.read()
def test_talreader(): pairinfo = TalReader( filename=osp.join(osp.dirname(__file__), 'data', 'pairs.json')).read() _ = pairinfo.atlases.avg[['x', 'y', 'z']] _ = pairinfo.atlases.mni.region
osp.join(reference_index_root, 'protocols', 'r1', 'subjects', subject, 'localizations', '0', 'neuroradiology'), osp.join(test_index_root, 'protocols', 'r1', 'subjects', subject, 'localizations', '0', 'neuroradiology')) except OSError as ose: if ose.errno != 17: raise ose return run_montage_import(inputs, force=True) if __name__ == '__main__': for subject in bipolar_subjects: logger.set_subject(subject, 'R1') sucess, _ = make_bipolar_montage(subject) if sucess: tal = TalReader(filename=pairs_path_template.format( protocols_root=test_index_root, subject=subject)) new_bipolar_pairs = tal.get_bipolar_pairs() jr = JsonIndexReader( osp.join(reference_index_root, 'protocols', 'r1.json')) task_event_files = list( jr.aggregate_values('task_events', subject=subject, montage=0)) events = CMLEventReader(filename=task_event_files[0]).read() eeg = EEGReader(events=events[:1], channels=np.array([]), start_time=0.0, end_time=0.1).read() hdf_bipolar_pairs = eeg.bipolar_pairs.values new_bipolar_pairs = new_bipolar_pairs.astype( hdf_bipolar_pairs.dtype) if not np.in1d(hdf_bipolar_pairs, new_bipolar_pairs).all(): logger.info(
def test_talreader_on_database(): old_reader = TalReader(filename='/Volumes/rhino_root/data/eeg/R1234D/tal/R1234D_talLocs_database_bipol.mat') jr = JsonIndexReader('/Volumes/rhino_root/protocols/r1.json') new_reader = TalReader(filename=jr.get_value('pairs',subject='R1234D',experiment='FR1')) assert new_reader.get_bipolar_pairs() == old_reader.get_bipolar_pairs() assert new_reader.get_monopolar_channels() == old_reader.get_monopolar_channels()
def test_old_behavior_warning(): with pytest.deprecated_call(): TalReader(filename=osp.join(osp.dirname(__file__), 'data', 'pairs.json'), unpack=False).read()
def test_old_behavior(): pairinfo = TalReader(filename=osp.join(osp.dirname(__file__), 'data', 'pairs.json'), unpack=False).read() assert pairinfo.dtype['atlases'] is np.dtype(object)
def test_old_behavior_warning(): with pytest.warns(FutureWarning): TalReader(filename=osp.join(osp.dirname(__file__), 'data', 'pairs.json'), unpack=False).read()
t = time.time() pow_vec_orig = [] pow_vec_recon = [] print(len(recon_files)) print(len(orig_files)) assert (len(recon_files) == len(events)) experiment = 'FR1' jr = JsonIndexReader(rhino_root + '/protocols/r1.json') # Build JSON reader pairs_path = jr.get_value('pairs', subject=subject, experiment=experiment) tal_reader = TalReader(filename=pairs_path) monopolar_channels = tal_reader.get_monopolar_channels() bipolar_channels = tal_reader.get_bipolar_pairs() recon_files = np.sort(recon_files) orig_files = np.sort(orig_files) data_orig_vec = [] data_recon_vec = [] for i, (recon_file, orig_file) in enumerate(zip(recon_files, orig_files)): if i % 100 == 0: print(i) fname_recon = subject_dir + recon_file fname_orig = subject_dir + orig_file
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
os.symlink(osp.join(reference_index_root,'protocols','r1','subjects',subject,'localizations','0','neuroradiology'), osp.join(test_index_root,'protocols','r1','subjects',subject,'localizations','0','neuroradiology')) except OSError as ose: if ose.errno != 17: raise ose return run_montage_import(inputs,force=True) if __name__ == '__main__': for subject in bipolar_subjects: logger.set_subject(subject,'R1') sucess, _ =make_bipolar_montage(subject) if sucess: tal = TalReader(filename=pairs_path_template.format(protocols_root=test_index_root, subject= subject)) new_bipolar_pairs = tal.get_bipolar_pairs() jr = JsonIndexReader(osp.join(reference_index_root,'protocols','r1.json')) task_event_files = list(jr.aggregate_values('task_events',subject=subject,montage=0)) events = CMLEventReader(filename=task_event_files[0]).read() eeg = EEGReader(events=events[:1],channels = np.array([]),start_time=0.0,end_time=0.1).read() hdf_bipolar_pairs = eeg.bipolar_pairs.values new_bipolar_pairs = new_bipolar_pairs.astype(hdf_bipolar_pairs.dtype) if not np.in1d(hdf_bipolar_pairs,new_bipolar_pairs).all(): logger.info('\n\n%s missing from new_bipolar_pairs\n\n'%str(hdf_bipolar_pairs[~np.in1d(hdf_bipolar_pairs,new_bipolar_pairs)])) if not np.in1d(new_bipolar_pairs,hdf_bipolar_pairs).all(): logger.info('\n\n%s missing from new_bipolar_pairs\n\n'%str(new_bipolar_pairs[~np.in1d(new_bipolar_pairs,hdf_bipolar_pairs)]))