def test_eeg_read_incomplete_data(self): e_path_incomplete = '/Volumes/rhino_root/data/events/RAM_PS/R1104D_events.mat' if sys.platform.startswith('win'): e_path_incomplete = 'D:/data/events/RAM_PS/R1104D_events.mat' base_event_reader = BaseEventReader(filename=e_path_incomplete) base_events = base_event_reader.read() sess_1 = base_events[base_events.session == 1] sess_3 = base_events[base_events.session == 3] sess_5 = base_events[base_events.session == 5] sess_7 = base_events[base_events.session == 7] sess_1[440].eegoffset = 2000000000000 sess_1[444].eegoffset = 2000000000000 sess_1[434].eegoffset = 2000000000000 shuffled_sess_events = np.hstack((sess_3, sess_7, sess_1, sess_5)).view(np.recarray) eeg_reader = EEGReader(events=shuffled_sess_events, channels=np.array(['002', '003']), start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time) base_eegs = eeg_reader.read() if eeg_reader.removed_bad_data(): print('REMOVED BAD DATA !!!!!!!!!!!!!') events = base_eegs['events'].data.view(np.recarray) if not isinstance(events, Events): events = Events(events) from ptsa.data.rawbinwrapper import RawBinWrapper events = events.add_fields(esrc=np.dtype(RawBinWrapper)) # ------------- using PTSAevent reader functions to prepare events for reading old-ptsa-style ptsa_event_reader = PTSAEventReader() ptsa_event_reader.attach_rawbinwrapper_groupped(events) eegs = events.get_data(channels=['002', '003'], start_time=self.start_time, end_time=self.end_time, buffer_time=self.buffer_time, eoffset='eegoffset', keep_buffer=True, eoffset_in_time=False, verbose=True) npt.assert_array_equal(eegs[:, :, :-1], base_eegs.data)
def read(self): """ Reads Matlab event file , converts it to np.recarray and attaches rawbinwrappers (if appropriate flags indicate so) :return: Events object. depending on flagg settings the rawbinwrappers may be attached as well """ # calling base class read fcn evs = BaseEventReader.read(self) # in case evs is simply recarray if not isinstance(evs, Events): evs = Events(evs) if self.attach_rawbinwrapper: evs = evs.add_fields(esrc=np.dtype(RawBinWrapper)) if self.use_groupped_rawbinwrapper: # this should be default choice - much faster execution self.attach_rawbinwrapper_groupped(evs) else: # used for debugging purposes self.attach_rawbinwrapper_individual(evs) return evs
def read(self): ''' Reads Matlab event file , converts it to np.recarray and attaches rawbinwrappers (if appropriate flags indicate so) :return: Events object. depending on flagg settings the rawbinwrappers may be attached as well ''' # calling base class read fcn evs = BaseEventReader.read(self) # in case evs is simply recarray if not isinstance(evs, Events): evs = Events(evs) if self.attach_rawbinwrapper: evs = evs.add_fields(esrc=np.dtype(RawBinWrapper)) if self.use_groupped_rawbinwrapper: # this should be default choice - much faster execution self.attach_rawbinwrapper_groupped(evs) else: # used for debugging purposes self.attach_rawbinwrapper_individual(evs) return evs
# sys.exit() for field in matevs.dtype.names: try: newevs[field] = matevs[field] except ValueError: if ((field == 'stimAmp') and (np.all(np.array(matevs[field],np.str)=='X'))): matevs[field].fill(np.nan) newevs[field] = matevs[field] else: # not sure what's going on, so raise the same error as above newevs[field] = matevs[field] events = Events(newevs) events = events.add_fields(esrc=np.dtype(RawBinWrapper)) good_indices = np.ones(len(events),np.bool) for e,event in enumerate(events): try: event['esrc'] = RawBinWrapper(event['eegfile']) except IOError: print('No EEG files for',event['subject'],event['session'],event['eegfile']) good_indices[e] = False events = events[good_indices] start_time = -0.6 end_time = 1.6 buf = 1
# sys.exit() for field in matevs.dtype.names: try: newevs[field] = matevs[field] except ValueError: if ((field == 'stimAmp') and (np.all(np.array(matevs[field], np.str) == 'X'))): matevs[field].fill(np.nan) newevs[field] = matevs[field] else: # not sure what's going on, so raise the same error as above newevs[field] = matevs[field] events = Events(newevs) events = events.add_fields(esrc=np.dtype(RawBinWrapper)) good_indices = np.ones(len(events), np.bool) for e, event in enumerate(events): try: event['esrc'] = RawBinWrapper(event['eegfile']) except IOError: print('No EEG files for', event['subject'], event['session'], event['eegfile']) good_indices[e] = False events = events[good_indices] start_time = -0.6 end_time = 1.6 buf = 1
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)
'catFR2':{ 'output_path': rhino_mount+'/data10/scratch/cweidema/RAM/RAM_catFR/RAM_catFR2_power/hdf5_files_sess', 'ev_file': rhino_mount+'/home1/cweidema/Christoph/Analyses/RAM/RAM_catFR/data/RAM_catFR2_events20151106.npy' }, 'FR1':{ 'output_path': rhino_mount+'/data10/scratch/cweidema/RAM/RAM_FR/RAM_FR1_power/hdf5_files_sess', 'ev_file': rhino_mount+'/home1/cweidema/Christoph/Analyses/RAM/RAM_FR/data/RAM_FR1_events20151106.npy' }, 'FR2':{ 'output_path': rhino_mount+'/data10/scratch/cweidema/RAM/RAM_FR/RAM_FR2_power/hdf5_files_sess', 'ev_file': rhino_mount+'/home1/cweidema/Christoph/Analyses/RAM/RAM_FR/data/RAM_FR2_events20151106.npy' } } ev = Events(np.load(pow_params[exp]['ev_file'])) ev = ev.add_fields(esrc=np.dtype(RawBinWrapper)) ev = ev[ev['type']=='WORD'] good_indices = np.ones(len(ev),np.bool) for e,event in enumerate(ev): try: event['esrc'] = RawBinWrapper(rhino_mount+event['eegfile']) except IOError: print('No EEG files for',event['subject'],event['session'],event['eegfile']) good_indices[e] = False ev = ev[good_indices] start_time = -0.6 end_time = 1.6 buf = 1 baseline = (-.6,-.4)