def read(self): from MatlabIO import read_single_matlab_matrix_as_numpy_structured_array # extract matlab matrix (called 'events') as numpy structured array struct_array = read_single_matlab_matrix_as_numpy_structured_array(self.__event_file, 'events') evs = Events(struct_array) if self.eliminate_events_with_no_eeg: # eliminating events that have no eeg file indicator = np.empty(len(evs), dtype=bool) for i, ev in enumerate(evs): indicator[i] = (type(evs[i].eegfile).__name__.startswith('unicode')) & (len(str(evs[i].eegfile)) > 3) evs = evs[indicator] self.__events = evs return self.__events
def read(self): from MatlabIO import read_single_matlab_matrix_as_numpy_structured_array # extract matlab matrix (called 'events') as numpy structured array struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.__event_file, 'events') evs = Events(struct_array) if self.eliminate_events_with_no_eeg: # eliminating events that have no eeg file indicator = np.empty(len(evs), dtype=bool) indicator[:] = False for i, ev in enumerate(evs): indicator[i] = (type( evs[i].eegfile).__name__.startswith('unicode')) & (len( str(evs[i].eegfile)) > 3) evs = evs[indicator] self.__events = evs return self.__events
def get_sub_events(task, sub, eliminate_events_with_no_eeg=True, rhino_prefix='/', ignore_no_params=False): """Returns all events for a given task and subject identifier Keyword arguments: task -- string of task name sub -- string of subject identifier eliminate_events_with_no_eeg -- (default: True) Do not return events for which no corresponding eeg file exists. rhino_prefix -- (default: '/') To get data if rhino is mounted as an external volume from a local computer. ignore_no_params -- (default: False) Automatically handles IOError when no params.txt file is found for a subject. """ from MatlabIO import read_single_matlab_matrix_as_numpy_structured_array e_path = rhino_prefix+'/data/events/'+task+'/'+sub+'_events.mat' # extract matlab matrix (called 'events') as numpy structured array struct_array = read_single_matlab_matrix_as_numpy_structured_array(e_path, 'events') evs = Events(struct_array) if eliminate_events_with_no_eeg: # eliminating events that have no eeg file indicator = np.empty(len(evs), dtype=bool) indicator[:] = False for i, ev in enumerate(evs): indicator[i] = (type(evs[i].eegfile).__name__.startswith('unicode')) & (len(str(evs[i].eegfile)) > 3) #Due to numpy upgrade evs = Events(evs[indicator]) evs = evs.add_fields(esrc=np.dtype(RawBinWrapper)) import pathlib #This may throw and error for a few subjects who have no params file. Should be written to handle this elegantly. if ignore_no_params: try: for ev in evs: try: eeg_file_path = join(rhino_prefix, str(pathlib.Path(str(ev.eegfile)).parts[1:])) ev.esrc = RawBinWrapper(eeg_file_path) #self.raw_data_root=str(eeg_file_path) except TypeError: print 'skipping event with eegfile=',ev.eegfile pass except IOError: print('No params.txt or .params file found for '+sub) else: for ev in evs: try: eeg_file_path = join(rhino_prefix, str(pathlib.Path(str(ev.eegfile)).parts[1:])) ev.esrc = RawBinWrapper(eeg_file_path) #self.raw_data_root=str(eeg_file_path) except TypeError: print 'skipping event with eegfile=',ev.eegfile pass return(evs)