コード例 #1
0
# step 1: need multiple input currents
    
I0 = np.linspace(1,10,10)
n_spikes = []

# step 2: choose a value T for time of stim

T0 = 200

# step 3: establish a voltage threshold for "spikes"

V = np.array()
Vth = 0

# step 4: for loop for each input current value in HH model

for k in range(0, len(I0)
    [V,m,n,h,t]=HH(I0[k], T0)
    spike = V[V > Vth]
    peaks = find_peaks(spike)[0]
    rate = len(peaks)
    fRateVector = fRateVector + [rate]
    
# step 5: attempt to plot everything and hope for the best
    
plt.figure()
plt.plot(fRateVector,I0)
plt.xlabel('Current')
plt.ylabel('Frequency')
コード例 #2
0
@author: lenovo

Generating firing rates at different I0
"""
from HH_functions import HH
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks

T0 = 1000
len_I0 = 20
frate = np.zeros(len_I0)
for I0 in range(0, len_I0, 1):
    I00 = I0
    [V, m, h, n, t] = HH(I00, T0)
    ##peakind = signal.find_peaks_cwt(np.shape(V),np.arange(1,2000))
    #peakind = find_peaks(np.reshape(V,-1),height=0)
    peakind = find_peaks(np.reshape(V, -1), height=-20)
    ##frate[I0]=1000/(peakind[0][1]- peakind[0][0])
    #frate[I0]=np.shape(peak)
    frate[I0] = len(peakind[0])
plt.figure()
III = range(len_I0)
plt.plot(III, frate)
plt.xlabel('Input Current/mA')
plt.ylabel('Firing Rate/Hz')
plt.title('F-I Curve for HH Model')
###################################
#numi0=0
#for I0 in range(40):
コード例 #3
0
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
from scipy.signal import savgol_filter
from HH_functions import HH

# for function instruction or parameters
import inspect
inspect.getsourcelines(HH)

T0 = 500
Input = np.linspace(0, 60, 100)
spikes = np.zeros((len(Input)))

#loop over inputs within input_array
for i in range(len(Input)):
    [V, m, h, n, t] = HH(Input[i], T0)
    V = np.concatenate(V)  #restructure V so each elements not arrays
    peaks = find_peaks(V,
                       prominence=(15,
                                   None))  #find peak via prominence critereion
    spikes[i] = len(peaks[0]) * 2  #estimate peak frequency within 1 sec [Hz]

plt.figure()
plt.plot(Input, spikes, lw=3)
plt.xlabel('Input [mA/cm^2]')
plt.ylabel('Firing rate [Hz]')

# Smoothed function via Savitsky-Golay filter
plt.plot(Input, savgol_filter(spikes, 45, 4))
plt.show
コード例 #4
0
ファイル: A02.py プロジェクト: eschlaf2/Case-Studies-Python
- `t` = the time axis of the simulation (useful for plotting).

## Part 2:  At low input current (`I0`), examine the HH dynamics.

  To understand how the HH model works, we'll start by focusing on the
  case when `I0` is small. Let's fix the input current to zero,

I0 = 0

and let's simulate the model for 100 ms,

T0 = 100

We've now defined both inputs to the `HH` function, and can execute it, as follows,

[V,m,h,n,t]=HH(I0,T0)

Notice that the function returns five outputs, which we assign to the variables `V`, `m`, `h`, `n`, and `t`.

<div class="question">

**Q:**  What are the dynamics of the voltage (variable `V`) resulting
from this simulation?<br>
HINT:  Plot `V` vs `t`.

</div>

<div class="question">

**Q:**   What are the dynamics of the gating variables (`m`, `h`, `n`)
resulting from this simulation?<br>
コード例 #5
0
"""

import numpy as np
from HH_functions import HH
import matplotlib.pyplot as plt

# Test for a range of currents
currents = np.arange(0, 200, 10)
firing_rates = np.zeros([len(currents), 1])

T0 = 15  # Input Current

# Test over all currents
for i in range(0, len(currents)):
    # Simulate the Hodgkin Huxley Model
    [Vs, ms, hs, ns, ts] = HH(currents[i], T0)

    # Test for a rise before the peak
    a = (Vs[0:len(Vs) - 2] < Vs[1:len(Vs) - 1])

    # Test for a fall after the peak
    b = (Vs[1:len(Vs) - 1] > Vs[2:])

    # Find spikes (spots with a rise before and a fall after)
    spikes = np.logical_and(a, b)

    # Count number of spikes
    firing_rates[i] = sum(spikes)

# Plot
plt.plot(currents, firing_rates)
コード例 #6
0
ファイル: HH_ficurve.py プロジェクト: bsetzer96/MA-666
@author: bever
"""
#NOTE: this will not work for the default HH function!
#edited the HH file to return dv and take in dt

import numpy as np
import matplotlib.pyplot as plt
from HH_functions import HH

T0 = 500  #number of time points
n = 200  # length of I vector
I = np.linspace(0, 100, n)  #input
dt = 0.01
T = T0 / dt  # [ms]
FI_rate = np.zeros(n)

for j in np.arange(n):
    I0 = I[j]
    V, m, h, n, t, dv = HH(I0, T0, dt)

    num_peaks = 0
    for i in np.arange(T - 1):
        if dv[int(i)] > 0 and dv[int(i + 1)] < 0:
            num_peaks = num_peaks + 1
    FI_rate[j] = num_peaks

plt.plot(I, FI_rate)
plt.xlabel("Imput current(I)")
plt.ylabel("Number of Spikes")
plt.show()
コード例 #7
0
#General import statements
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import find_peaks
from HH_functions import HH

#Brute force method of demonstrating F-I Curve for H-H Model

fRateVector = []  #Create vector to store firing rates
iRange = np.linspace(0, 25, 25)  #Set how many inputs to test

T0 = 400  #Set temporal length of simulation
#!! Note !! >100 is computationally expensive

for i in range(0, len(iRange)):
    I0 = iRange[i]  #Set input current
    [V, m, h, n, t] = HH(I0, T0)  #Run HH simulation
    V = np.reshape(V, -1)
    highV = V[V > 0]  #Collect Voltage only above 0 mV
    numPeaks = find_peaks(highV)[0]  #Find peaks on cropped voltage data
    fRate = len(numPeaks)  #Get number of spikes
    fRateVector = fRateVector + [fRate]

#Plotting...
plt.figure()
plt.plot(iRange, fRateVector)
plt.ylabel('Firing Rate (# of spikes)')
plt.xlabel('Current (Amps)')
plt.title('F-I Curve for HH Model')
コード例 #8
0
@author: kylie
"""

#F-I curve for Hodgkin-Huxley Model
import numpy as np
import math
import matplotlib.pyplot as plt
from HH_functions import HH
from scipy.signal import argrelextrema

T0 = 100  #set time for simulation
I = np.linspace(0, 50, 50)  #set range of input currents
Vth = -20  #set voltage threshold for "spike"
NumSpike = []  #create vector to store spikes
for i in range(0, len(I)):  #for each value of input current...
    [V, m, h, n, t] = HH(I[i], T0)  #simulate HH
    Vspike = V[
        V > Vth]  #extract voltages where voltage exceeds threshold as 'Vspike'
    spike_max = Vspike[argrelextrema(
        Vspike, np.greater)]  #extract the max voltages for Vspike
    fire_num = len(
        spike_max)  #calculating number of spikes during Vspike intervals
    NumSpike = NumSpike + [
        fire_num
    ]  #returning number of spikes to spike vector NumSpike
FR = [x / (T0 / 1000) for x in NumSpike]  #firing rate

plt.figure()
plt.plot(I, FR)
plt.ylabel('Firing Rate (Hz)')
plt.xlabel('Input Current (Amps)')