def __init__(self, action_id_0, action_id_1, actions, channel_group=None, max_dissimilarity=10, dissimilarity_function=None, verbose=False): data_path_0 = get_data_path(actions[action_id_0]) data_path_1 = get_data_path(actions[action_id_1]) self._actions = actions self.action_id_0 = action_id_0 self.action_id_1 = action_id_1 self._channel_group = channel_group self.action_ids = [action_id_0, action_id_1] self.max_dissimilarity = max_dissimilarity self.dissimilarity_function = dissimilarity_function self._verbose = verbose if channel_group is None: channel_groups = get_channel_groups(data_path_0) self.matches = {} self.templates = {} self.unit_ids = {} for chan in channel_groups: self.matches[chan] = dict() self.templates[chan] = list() self.unit_ids[chan] = list() else: self.matches = {channel_group: dict()} self.templates = {channel_group: list()} self.unit_ids = {channel_group: list()} for channel_group in self.matches.keys(): unit_annotations_0 = load_unit_annotations( data_path_0, channel_group=channel_group) unit_annotations_1 = load_unit_annotations( data_path_1, channel_group=channel_group) unit_ids_0 = [] unit_ids_1 = [] for st in unit_annotations_0: unit_ids_0.append(get_unit_id(st)) for st in unit_annotations_1: unit_ids_1.append(get_unit_id(st)) self.unit_ids[channel_group] = [ np.array(unit_ids_0), np.array(unit_ids_1) ] self.templates[channel_group] = [ compute_templates(self.waveforms_0(channel_group)), compute_templates(self.waveforms_1(channel_group)) ] if len(unit_annotations_0) > 0 and len(unit_annotations_1) > 0: self._do_dissimilarity(channel_group) self._do_matching(channel_group)
def __init__(self, actions, action_list=None, channel_group=None, max_dissimilarity=None, max_timedelta=None, verbose=False, progress_bar=None, data_path=None): self.data_path = Path.cwd() if data_path is None else Path(data_path) self.data_path.mkdir(parents=True, exist_ok=True) self.action_list = [a for a in actions ] if action_list is None else action_list self._actions = actions self._channel_group = channel_group self.max_dissimilarity = max_dissimilarity or np.inf self.max_timedelta = max_timedelta or datetime.MAXYEAR self._verbose = verbose self._pbar = tqdm if progress_bar is None else progress_bar if self._channel_group is None: dp = get_data_path(self._actions[self.action_list[0]]) self._channel_groups = get_channel_groups(dp) else: self._channel_groups = [self._channel_group]
def waveforms_1(self, channel_group): action_1 = self._actions[self.action_id_1] data_path_1 = get_data_path(action_1) spike_trains_1 = load_spiketrains(data_path_1, channel_group=channel_group, load_waveforms=True) return [np.array(sptr.waveforms) for sptr in spike_trains_1]
def load_waveforms(self, action_id, unit_id, channel_group): action = self._actions[action_id] data_path = get_data_path(action) spike_trains = load_spiketrains( data_path, channel_group=channel_group, load_waveforms=True) wfs = [np.array(sptr.waveforms) for sptr in spike_trains if get_unit_id(sptr)==unit_id] if len(wfs) != 1: raise ValueError( f'Unable to load waveforms from unit {unit_id}' + f' in {action_id} channel group {channel_group}') return wfs[0]