def read(self): ''' :return:np.recarray representing tal struct array (originally defined in Matlab file) ''' from ptsa.data.MatlabIO import read_single_matlab_matrix_as_numpy_structured_array struct_names = ['bpTalStruct', 'subjTalEvents'] # struct_names = ['bpTalStruct'] if self.struct_name not in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, self.struct_name, verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array else: raise AttributeError( 'Could not read tal struct data for the specified struct_name=' + self.struct_name) else: for sn in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, sn, verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array raise AttributeError( 'Could not read tal struct data. Try specifying struct_name argument :' '\nTalReader(filename=e_path, struct_name=<name_of_struc_to_read>)' )
def read(self): """ :return:np.recarray representing tal struct array (originally defined in Matlab file) """ from ptsa.data.MatlabIO import read_single_matlab_matrix_as_numpy_structured_array struct_names = ["bpTalStruct", "subjTalEvents"] # struct_names = ['bpTalStruct'] if self.struct_name not in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, self.struct_name, verbose=False ) if self.tal_struct_array is not None: return self.tal_struct_array else: raise AttributeError("Could not read tal struct data for the specified struct_name=" + self.struct_name) else: for sn in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, sn, verbose=False ) if self.tal_struct_array is not None: return self.tal_struct_array raise AttributeError( "Could not read tal struct data. Try specifying struct_name argument :" "\nTalReader(filename=e_path, struct_name=<name_of_struc_to_read>)" )
def read(self): """ :return: np.recarray representing tal struct array (originally defined in Matlab file) """ if not self._json: from ptsa.data.MatlabIO import read_single_matlab_matrix_as_numpy_structured_array struct_names = ['bpTalStruct','subjTalEvents'] # struct_names = ['bpTalStruct'] if self.struct_name not in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array(self.filename, self.struct_name,verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array else: raise AttributeError('Could not read tal struct data for the specified struct_name='+self.struct_name) else: for sn in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array(self.filename,sn,verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array else: with open(self.filename) as fp: pairs= json.load(fp) self.tal_struct_array = self.from_dict(pairs) return self.tal_struct_array raise AttributeError('Could not read tal struct data. Try specifying struct_name argument :' '\nTalReader(filename=e_path, struct_name=<name_of_struc_to_read>)')
def read(self): """ :return: np.recarray representing tal struct array """ if not self._json: from ptsa.data.MatlabIO import read_single_matlab_matrix_as_numpy_structured_array struct_names = ['bpTalStruct', 'subjTalEvents'] # struct_names = ['bpTalStruct'] if self.struct_name not in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, self.struct_name, verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array else: raise AttributeError( 'Could not read tal struct data for the specified struct_name=' + self.struct_name) else: for sn in struct_names: self.tal_struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, sn, verbose=False) if self.tal_struct_array is not None: return self.tal_struct_array else: with open(self.filename) as fp: pairs = json.load(fp) self.tal_struct_array = self.from_dict(pairs, unpack=self.unpack) return self.tal_struct_array raise AttributeError( 'Could not read tal struct data. Try specifying struct_name argument :' '\nTalReader(filename=e_path, struct_name=<name_of_struc_to_read>)' )
def read_matlab(self): """ Reads Matlab event file and returns corresponging np.recarray. Path to the eegfile is changed w.r.t original Matlab code to account for the following: 1. /data dir of the database might have been mounted under different mount point e.g. /Users/m/data 2. use_reref_eeg is set to True in which case we replaces 'eeg.reref' with 'eeg.noreref' in eegfile path :return: np.recarray representing events """ # extract matlab matrix (called 'events') as numpy structured array struct_array = read_single_matlab_matrix_as_numpy_structured_array( self.filename, 'events') evs = struct_array if 'eegfile' in evs.dtype.names: 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): # MAKE THIS CHECK STRONGER indicator[i] = (len(str(evs[i].eegfile)) > 3) # indicator[i] = (type(evs[i].eegfile).__name__.startswith('unicode')) & (len(str(evs[i].eegfile)) > 3) evs = evs[indicator] # determining data_dir_prefix in case rhino /data filesystem was mounted under different root if self.normalize_eeg_path: data_dir_prefix = self.find_data_dir_prefix() for i, ev in enumerate(evs): ev.eegfile = join( data_dir_prefix, str(pathlib.Path(str(ev.eegfile)).parts[1:])) evs = self.normalize_paths(evs) # if not self.use_reref_eeg: if self._alter_eeg_path_flag: evs = self.modify_eeg_path(evs) if self.eliminate_nans: # this is evs = self.replace_nans(evs) return evs
def read_matlab(self): """ Reads Matlab event file and returns corresponging np.recarray. Path to the eegfile is changed w.r.t original Matlab code to account for the following: 1. /data dir of the database might have been mounted under different mount point e.g. /Users/m/data 2. use_reref_eeg is set to True in which case we replaces 'eeg.reref' with 'eeg.noreref' in eegfile path :return: np.recarray representing events """ # extract matlab matrix (called 'events') as numpy structured array struct_array = read_single_matlab_matrix_as_numpy_structured_array(self.filename, 'events') evs = struct_array if 'eegfile' in evs.dtype.names: 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): # MAKE THIS CHECK STRONGER indicator[i] = (len(str(evs[i].eegfile)) > 3) # indicator[i] = (type(evs[i].eegfile).__name__.startswith('unicode')) & (len(str(evs[i].eegfile)) > 3) evs = evs[indicator] # determining data_dir_prefix in case rhino /data filesystem was mounted under different root if self.normalize_eeg_path: data_dir_prefix = self.find_data_dir_prefix() for i, ev in enumerate(evs): ev.eegfile = join(data_dir_prefix, str(pathlib.Path(str(ev.eegfile)).parts[1:])) evs = self.normalize_paths(evs) # if not self.use_reref_eeg: if self._alter_eeg_path_flag: evs = self.modify_eeg_path(evs) if self.eliminate_nans: # this is evs = self.replace_nans(evs) return evs