def _prepend_db_root(cls, protocols_root, index): """ Prepends the protocols_root onto elements of index that contain the basename of protocols_root and look like paths. """ protocols_basename = os.path.basename(protocols_root) for k, v in list(index.items()): if isinstance(v, dict): cls._prepend_db_root(protocols_root, v) elif isinstance(v, string_types): v_path = pathlib.Path(str(v)) root = str(v_path.parts[0]) if root == protocols_basename: index[k] = os.path.join(protocols_root, str(v_path.parts[1:]))
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