#!/usr/bin/python """ Test adex model """ import numpy as np from neuron import h import neuron import matplotlib.pyplot as plt from collections import OrderedDict import weave from .gif.Filter_Rect_LogSpaced import * class AdEx: def __init__(self): pass self.dt = 0.025 self.tstop = 250.0 self.eta = ( Filter_Rect_LogSpaced() ) # nA, spike-triggered current (must be instance of class Filter) self.gamma = ( Filter_Rect_LogSpaced() ) # mV, spike-triggered movement of the firing threshold (must be instance of class Filter) def runone(self, pars, dt=0.025, tstop=250): self.cell = self.create_Adex_model(pars) self.dt = 0.025 self.tstop = tstop # for inj in np.linspace(pars['I']*0.5, pars['I']*2.0, 3): inj = pars["I"] stim = h.Vector() self.Vm = h.Vector() self.Vm.record(self.cell(0.5)._ref_Vm_AdEx, sec=self.cell) istim = h.iStim(0.5, sec=self.cell) istim.delay = 5.0 istim.dur = 1e9 # these actually do not matter... istim.iMax = 0.0 stim = np.zeros(int(tstop / h.dt)) stim[int(20 / h.dt) : int(220 / h.dt)] = inj cmd = h.Vector(stim) # cmd.play(istim._ref_i, h.dt, 0, sec=cell) cmd.play(self.cell(0.5)._ref_is_AdEx, h.dt, 0, sec=self.cell) rtime = h.Vector() rtime.record(h._ref_t) h.finitialize() h.t = 0.0 h.dt = self.dt while h.t < self.tstop: h.fadvance() tb = np.array(rtime) vcell = self.Vm.to_python() return (tb, vcell) def run_gifAI(self, pars, dt=0.025, tstep=250.0): # Model parameters self.simulate(pars["I"], -65.0, pars) def plot_trace(self, i, panel, tb, vcell): axi = self.ax[i] axi.plot(tb, vcell) axi.set_ylim([-100, 10]) axi.set_title(panel) def create_Adex_model(self, pars): cell = h.Section() cell.L = 50 cell.insert("AdEx") cell(0.5).cm_AdEx = pars["cm"] cell(0.5).gl_AdEx = pars["gl"] cell(0.5).el_AdEx = pars["el"] cell(0.5).vt_AdEx = pars["Vt"] cell(0.5).delt_AdEx = pars["dt"] cell(0.5).a_AdEx = pars["a"] cell(0.5).tauw_AdEx = pars["tauw"] cell(0.5).b_AdEx = pars["b"] cell(0.5).vr_AdEx = pars["Vr"] cell(0.5).refract_AdEx = 0.025 return cell def create_GIF_model(self, pars): cell = h.Section() cell.L = 50 cell.insert("GIF") cell(0.5).cm_GIF = pars["cm"] cell(0.5).gl_GIF = pars["gl"] cell(0.5).el_GIF = pars["el"] cell(0.5).vt_GIF = pars["Vt_star"] cell(0.5).vr_GIF = pars["Vr"] cell(0.5).refract_GIF = pars["Tref"] cell(0.5).DV_GIF = pars["DV"] cell(0.5).lambda0_GIF = pars["lambda0"] cell(0.5).b_GIF = pars["b"] return cell # # The following are from Gif.py... def simulate(self, I, V0, pars): """ Simulate the spiking response of the GIF model to an input current I (nA) with time step dt. V0 indicate the initial condition V(0)=V0. The function returns: - time : ms, support for V, eta_sum, V_T, spks - V : mV, membrane potential - eta_sum : nA, adaptation current - V_T : mV, firing threshold - spks : ms, list of spike times """ # Input parameters p_T = len(I) p_dt = self.dt # Model parameters p_gl = pars["gl"] p_C = pars["cm"] p_El = pars["el"] p_Vr = pars["Vr"] p_Tref = pars["Tref"] p_Vt_star = pars["Vt_star"] p_DV = pars["DV"] p_lambda0 = pars["lambda0"] # Model kernels (p_eta_support, p_eta) = self.eta.getInterpolatedFilter(self.dt) p_eta = p_eta.astype("double") p_eta_l = len(p_eta) (p_gamma_support, p_gamma) = self.gamma.getInterpolatedFilter(self.dt) p_gamma = p_gamma.astype("double") p_gamma_l = len(p_gamma) # Define arrays V = np.array(np.zeros(p_T), dtype="double") I = np.array(I, dtype="double") spks = np.array(np.zeros(p_T), dtype="double") eta_sum = np.array(np.zeros(p_T + 2 * p_eta_l), dtype="double") gamma_sum = np.array(np.zeros(p_T + 2 * p_gamma_l), dtype="double") # Set initial condition V[0] = V0 code = """ #include int T_ind = int(p_T); float dt = float(p_dt); float gl = float(p_gl); float C = float(p_C); float El = float(p_El); float Vr = float(p_Vr); int Tref_ind = int(float(p_Tref)/dt); float Vt_star = float(p_Vt_star); float DeltaV = float(p_DV); float lambda0 = float(p_lambda0); int eta_l = int(p_eta_l); int gamma_l = int(p_gamma_l); float rand_max = float(RAND_MAX); float p_dontspike = 0.0 ; float lambda = 0.0 ; float r = 0.0; for (int t=0; t p_dontspike) { if (t+1 < T_ind-1) spks[t+1] = 1.0; t = t + Tref_ind; if (t+1 < T_ind-1) V[t+1] = Vr; // UPDATE ADAPTATION PROCESSES for(int j=0; j