Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing specific values from an array after integrating ODE

Tags:

python

arrays

ode

I apologize if this is a very silly/simple question. I'm trying to model a neuron in a noisy network using Python, and I'm hoping to compute the time between neuron spiking (i.e. the interspike interval). The relevant part of my code is the following (a postdoc helped me code this):

def dALLdt(X, t):
        V, m, h, n = X
        dVdt = (I_app(t)+I_syn(spks,t)-I_Na(V, m, h) - I_K(V, n) - I_L(V)) / C_m
        dmdt = alpha_m(V)*(1.0-m) - beta_m(V)*m
        dhdt = alpha_h(V)*(1.0-h) - beta_h(V)*h
        dndt = alpha_n(V)*(1.0-n) - beta_n(V)*n
        return np.array([dVdt, dmdt, dhdt, dndt])

X = [ic]
for i in t[1:]:
    dx = dALLdt(X[-1],i)
    x = X[-1]+dt*(dx)
    X.append(x)    

X = np.array(X)    
V = X[:,0]        
m = X[:,1]
h = X[:,2]
n = X[:,3]

When I created a figure from this using the standard "plt.plot(t, V, 'k')", I create the following image:

enter image description here

What I would like to do, and seemingly can't figure out how to do, is figuring out the value of t when the neuron spikes (of course the spike itself has width, so as long as I'm consistent in how I'm measuring it, that width doesn't matter much). For consistency, I'd like to say the neuron spikes when V is at its peak. My thought of how to do this is basically to say that when V hits a certain value (e.g. 30), have python print the time it happens (since it'll happen twice per spike, once on the way up and once on the way down, then I can simply average the two to get an approximate spike time). The problem is that I have no idea how to actually tell Python to print all the times when V is above 30 and haven't been able to find any sample code which does it. Can anyone please help with this? Thank you! :)

like image 499
Brenton Avatar asked Jul 30 '26 03:07

Brenton


1 Answers

idx = np.argwhere(V > 30)[:,0] # get index of V where the value is > 30 and make it 1-d array t[idx] # the array of t where V > 30

From this subset of ts you should be able to do some interpolation to find out the peak time.

like image 173
Hun Avatar answered Aug 01 '26 20:08

Hun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!