def _get_patterns(self, cell): def _find_classes(trains,ev): """Classify spike trains""" tr_cl =[x[(x>ev[0]) & (x<ev[-1]) ] for x in trains] cl = np.array([np.sum(2**(np.unique(np.searchsorted(ev,y))-1)) for y in tr_cl]) cl[cl<0]=0 return cl def _filter_spikes(spt,stim,win): i=np.searchsorted(stim,spt); spt2=(spt-stim[i-1]); spikes=spt[(spt2<win[1]) & (spt2>=win[0])] return spikes dataset = dashboard.read_dataset(self.io_filter, cell) spt = dataset['spt'] stim = dataset['stim'] ev = np.sort(self.root.h5filter.get_cached_string(cell, "events")) try: win = [ev[0], ev[-1]] except IndexError: ev = [0, 30] win = ev dataset['events'] = ev spt = _filter_spikes(spt, stim, win) dataset['spt'] = spt trains = basic.SortSpikes(spt, stim, win) cl = _find_classes(trains, ev) return dataset, cl
def event_selector(self, cellid): dataset = dashboard.read_dataset(self.io_filter, cellid) spt = dataset['spt'] stim = dataset['stim'] psth, time = basic.CalcPSTH(spt, stim) data = [{'x': x, 'y': int(y)} for x, y in zip(time, psth)] template = self.env.get_template('event_selector.html') doc = doc2html(self.__doc__) return template.render(cellid=str(cellid), data=json.dumps(data), doc=doc)