def get_spikes(self): spikes = {} for pop in chain(self._neuronal_populations, self._source_populations): spike_arr = pop.getSpikes() spikes[pop.label] = signals.SpikeList(spike_arr, id_list=range(pop.size)) return spikes
def process_spikes(ev, tmax, tmin=0.): """ Converts NEST events to dictionary of numpy arrays :param ev: NEST events :param tmax: max time until when to convert :param tmin: min time from which to convert :return: dict of parsed spikes """ senders = ev['senders'] times = ev['times'] idxs = np.where(times >= tmin) ev['senders'] = senders[idxs] ev['times'] = times[idxs] senders = senders[idxs] times = times[idxs] spikelist = [(senders[i], ev['times'][i]) for i in range(len(senders))] if len(senders) > 0: ids = np.arange(senders.min(), senders.max() + 1) else: ids = np.array([]) spike_trains = signals.SpikeList(spikelist, ids, t_start=tmin, t_stop=tmax) return {"ids": ids, "spike_list": spikelist, "spike_trains": spike_trains, 'ev': ev}
def get_rates(self, t_start, t_stop): """Calculates and returns mean rates for e and i populations. This uses the internally saved spikes which are available after calling run() :param t_start: start time :param t_stop: end time :return: dictionary of two rates """ print "Returning rates from %f to %f" % (t_start, t_stop) if t_start >= t_stop: raise ValueError("t_stop should be bigger than t_start.") ex_spiketrains_base = signals.SpikeList(self.spikes["e"]["spike_list"], self.spikes["e"]["ids"], t_start=t_start, t_stop=t_stop) ex_base = ex_spiketrains_base.mean_rate() in_spiketrains_base = signals.SpikeList(self.spikes["i"]["spike_list"], self.spikes["i"]["ids"], t_start=t_start, t_stop=t_stop) in_base = in_spiketrains_base.mean_rate() return {"e": ex_base, "i": in_base}
def read_spikes(self, params): """ Read a SpikeList object from a file and return the SpikeList object, created from the File and from the additional params that may have been provided Examples: >> params = {'id_list' : range(100), 't_stop' : 1000} >> handler.read_spikes(params) SpikeList Object (with params taken into account) """ p = self.__check_params(params) from NeuroTools import signals data = self.get_data() data, p = self._fix_id_list(data, p) return signals.SpikeList(data, p['id_list'], p['t_start'], p['t_stop'], p['dims'])
def spikestats(): ff = open('./data/0/spikes.dat', 'r') fdata = ff.readlines() lst = [] nid = 0 for l in fdata: ar = numpy.fromstring(l, sep=' ') for a in ar: lst.append((nid, a)) nid += 1 slist = signals.SpikeList(lst, range(0, nid)) slist.raster_plot() #pylab.figure() #pylab.imshow(spraster , interpolation='nearest', aspect='auto',cmap='hot') #pp = numpy.correlate(spraster[100, :], spraster[102,:], 'full'); #print pp; #pylab.plot(pp) pylab.show()