def make_spike_signal(ts, dur, tmax, loval=0, hival=1, dt=0.1): """Helper function: Square-pulse spike signal between two levels, loval and hival. Pulses occur at times given by ts array for duration given by dur scalar, from time 0 to tmax. Returns a single-entry dictionary of Variable objects with key 'Istim'. Default loval = 0, hival = 1. To improve performance with adaptive time-step solvers, three (two before, one after) points are added before and after each pulse, with a minimum step time given by dt. """ assert len(ts) > 0, "No spike time events provided!" assert isincreasing(ts), "This function expects strictly increasing times" assert ts[0] != 0, "This function does not support initial step up at t=0" assert dur > dt, "Duration must be larger than dt" times = [0] vals = [loval] # check that ts are separated by at least dur+4*dt assert all(np.diff(ts) > dur+4*dt), "Separate events by at least 4*dt" assert tmax > ts[-1]+dur, "tmax must be larger than last event end time" for t in ts: times.extend([t-2.9*dt, t-dt, t, t+dur-dt, t+dur, t+dur+dt]) vals.extend([loval, loval, hival, hival, hival, loval]) if tmax > ts[-1]+dur+dt: times.append(tmax) vals.append(loval) coorddict = {'Istim': vals} vpts = Pointset(coorddict=coorddict, indepvararray=times) return pointset_to_vars(vpts, discrete=False)
def make_noise_signal(dt, t_end, mean, stddev, num_cells, seed=None): """Helper function: Gaussian white noise at sample rate = dt for 1 or more cells, for a duration of t_end.""" if seed is not None: np.random.seed(seed) N = ceil(t_end*1./dt) t = np.linspace(0, t_end, N) coorddict = {} for cellnum in range(num_cells): coorddict['noise%i' % (cellnum+1)] = np.random.normal(0, stddev, N) vpts = Pointset(coorddict=coorddict, indepvararray=t) return pointset_to_vars(vpts, discrete=False)