示例#1
0
def _min_curr_expl():
    from neurodynex3.tools import plot_tools, input_factory

    durations = [1, 2, 5, 10, 20, 50, 100, 200]
    min_amp = [8.6, 4.45, 2., 1.15, .70, .48, 0.43, .4]
    i = 1
    t = durations[i]
    I_amp = min_amp[i] * b2.namp

    input_current = input_factory.get_step_current(t_start=10,
                                                   t_end=10 + t - 1,
                                                   unit_time=b2.ms,
                                                   amplitude=I_amp)

    state_monitor, spike_monitor = simulate_exponential_IF_neuron(
        I_stim=input_current, simulation_time=(t + 20) * b2.ms)

    plot_tools.plot_voltage_and_current_traces(
        state_monitor,
        input_current,
        title="step current",
        firing_threshold=FIRING_THRESHOLD_v_spike,
        legend_location=2)
    plt.show()
    print("nr of spikes: {}".format(spike_monitor.count[0]))
示例#2
0
def test_simulate_HH_neuron():
    """Test Hodgkin-Huxley model: simulate_HH_neuron()"""
    current = input_factory.get_step_current(0, 1, b2.ms, 100. * b2.uA)
    state_monitor = HH.simulate_HH_neuron(current, simulation_time=1. * b2.ms)
    max_voltage = max(state_monitor.vm[0] / b2.mV)
    # print("max_voltage:{}".format(max_voltage))
    assert max_voltage > 50., "simulation error: max voltage is not > 50"
示例#3
0
def getting_started():
    """
    An example to quickly get started with the Hodgkin-Huxley module.
    """
    current = input_factory.get_step_current(10, 45, b2.ms, 7.2 * b2.uA)
    state_monitor = simulate_HH_neuron(current, 70 * b2.ms)
    plot_data(state_monitor, title="HH Neuron, step current")
示例#4
0
def test_simulate_LIF_neuron():
    """Test LIF model: simulate_LIF_neuron(short pulse, 1ms, default values)"""
    c = input_factory.get_step_current(0, 9, 0.1 * b2.ms, .02 * b2.uA)
    m, spike_monitor = LIF.simulate_LIF_neuron(c, simulation_time=1.1 * b2.ms)
    nr_spikes = spike_monitor.count[0]
    # print("nr_spikes:{}".format(nr_spikes))
    assert nr_spikes > 0, \
        "simulation error: Pulse current did not trigger a spike. " \
        "Check if the LIF default values did change."
def test_simulate_exponential_IF_neuron():
    """Test if simulates simulate_AdEx_neuron generates two spikes"""
    current = input_factory.get_step_current(0, 0, 1. * b2.ms, 0.5 * b2.nA)
    state_monitor, spike_monitor = AdEx.simulate_AdEx_neuron(
        I_stim=current, simulation_time=1.5 * b2.ms)
    nr_spikes = spike_monitor.count[0]
    # print("nr_spikes:{}".format(nr_spikes))
    assert nr_spikes == 2, \
        "simulation error: Pulse current did not trigger exactly two spikes. " \
        "Check if the AdEx default values did change."
示例#6
0
def getting_started():
    """
    Simple example to get started
    """

    from neurodynex3.tools import plot_tools
    current = input_factory.get_step_current(10, 200, 1. * b2.ms, 65.0 * b2.pA)
    state_monitor, spike_monitor = simulate_AdEx_neuron(I_stim=current, simulation_time=300 * b2.ms)
    plot_tools.plot_voltage_and_current_traces(state_monitor, current)
    plot_adex_state(state_monitor)
    print("nr of spikes: {}".format(spike_monitor.count[0]))
示例#7
0
def test_simulate_exponential_IF_neuron():
    """Test exponential-integrate-and-fire model"""
    c = input_factory.get_step_current(0,
                                       2,
                                       1 * b2.ms,
                                       amplitude=8.5 * b2.namp)
    m, spike_monitor = exp_IF.simulate_exponential_IF_neuron(
        I_stim=c, simulation_time=2.5 * b2.ms)
    nr_spikes = spike_monitor.count[0]
    # print("nr_spikes:{}".format(nr_spikes))
    assert nr_spikes == 1, \
        "simulation error: Pulse current did not trigger exactly one spike. " \
        "Check if the exp-IF default values did change."
示例#8
0
def getting_started():
    """
    An example to quickly get started with the LIF module.
    Returns:

    """
    # specify step current
    step_current = input_factory.get_step_current(t_start=100,
                                                  t_end=200,
                                                  unit_time=b2.ms,
                                                  amplitude=1.2 * b2.namp)
    # run the LIF model
    (state_monitor,
     spike_monitor) = simulate_LIF_neuron(input_current=step_current,
                                          simulation_time=300 * b2.ms)

    # plot the membrane voltage
    plot_tools.plot_voltage_and_current_traces(
        state_monitor,
        step_current,
        title="Step current",
        firing_threshold=FIRING_THRESHOLD)
    print("nr of spikes: {}".format(len(spike_monitor.t)))
    plt.show()

    # second example: sinusoidal current. note the higher resolution 0.1 * b2.ms
    sinusoidal_current = input_factory.get_sinusoidal_current(
        500,
        1500,
        unit_time=0.1 * b2.ms,
        amplitude=2.5 * b2.namp,
        frequency=150 * b2.Hz,
        direct_current=2. * b2.namp)
    # run the LIF model
    (state_monitor,
     spike_monitor) = simulate_LIF_neuron(input_current=sinusoidal_current,
                                          simulation_time=200 * b2.ms)
    # plot the membrane voltage
    plot_tools.plot_voltage_and_current_traces(
        state_monitor,
        sinusoidal_current,
        title="Sinusoidal input current",
        firing_threshold=FIRING_THRESHOLD)
    print("nr of spikes: {}".format(spike_monitor.count[0]))
    plt.show()
示例#9
0
def getting_started():
    """
    A simple example
    """
    import neurodynex3.tools.plot_tools as plot_tools
    input_current = input_factory.get_step_current(t_start=20,
                                                   t_end=120,
                                                   unit_time=b2.ms,
                                                   amplitude=0.8 * b2.namp)
    state_monitor, spike_monitor = simulate_exponential_IF_neuron(
        I_stim=input_current, simulation_time=180 * b2.ms)
    plot_tools.plot_voltage_and_current_traces(
        state_monitor,
        input_current,
        title="step current",
        firing_threshold=FIRING_THRESHOLD_v_spike)
    print("nr of spikes: {}".format(spike_monitor.count[0]))
    plt.show()
示例#10
0
def getting_started():
    """A simple code example to get started.
    """
    current = input_factory.get_step_current(500,
                                             510,
                                             unit_time=b2.us,
                                             amplitude=3. * b2.namp)
    voltage_monitor, cable_model = simulate_passive_cable(
        length=0.5 * b2.mm,
        current_injection_location=[0.1 * b2.mm],
        input_current=current,
        nr_compartments=100,
        simulation_time=2 * b2.ms)

    # provide a minimal plot
    plt.figure()
    plt.imshow(voltage_monitor.v / b2.volt)
    plt.colorbar(label="voltage")
    plt.xlabel("time index")
    plt.ylabel("location index")
    plt.title("vm at (t,x), raw data voltage_monitor.v")
    plt.show()
def test_neurons_run():
    """Test if neuron functions are runnable."""
    import brian2 as b2
    from neurodynex3.tools import input_factory
    from neurodynex3.neuron_type import neurons
    # create an input current

    input_current = input_factory.get_step_current(1, 2, 1. * b2.ms,
                                                   0.1 * b2.pA)

    # get an instance of class NeuronX
    a_neuron_of_type_X = neurons.NeuronX(
    )  # we do not know if it's type I or II
    state_monitor = a_neuron_of_type_X.run(input_current, 2 * b2.ms)
    assert isinstance(state_monitor, b2.StateMonitor
                      ), "a_neuron_of_type_X.run did not return a StateMonitor"

    a_neuron_of_type_Y = neurons.NeuronY(
    )  # we do not know if it's type I or II
    state_monitor = a_neuron_of_type_Y.run(input_current, 2 * b2.ms)
    assert isinstance(state_monitor, b2.StateMonitor
                      ), "a_neuron_of_type_Y.run did not return a StateMonitor"
示例#12
0
def getting_started():
    """
    simple demo to get started

    Returns:

    """
    from neurodynex3.tools import input_factory

    # create an input current
    input_current = input_factory.get_step_current(50, 150, 1. * b2.ms,
                                                   0.5 * b2.pA)

    # get an instance of class NeuronX
    a_neuron_of_type_X = NeuronX()
    # simulate it and get the state variables
    state_monitor = a_neuron_of_type_X.run(input_current, 200 * b2.ms)
    # plot state vs. time
    plot_data(state_monitor, title="Neuron of Type X")

    # get an instance of class NeuronY
    a_neuron_of_type_Y = NeuronY()
    state_monitor = a_neuron_of_type_Y.run(input_current, 200 * b2.ms)
    plot_data(state_monitor, title="Neuron of Type Y")
示例#13
0
from neurodynex3.tools import input_factory
import matplotlib.pyplot as plt
import numpy as np

# integration time step in milliseconds
b2.defaultclock.dt = 0.01 * b2.ms

# DEFAULT morphological and electrical parameters
CABLE_LENGTH = 500. * b2.um  # length of dendrite
CABLE_DIAMETER = 2. * b2.um  # diameter of dendrite
R_LONGITUDINAL = 0.5 * b2.kohm * b2.mm  # Intracellular medium resistance
R_TRANSVERSAL = 1.25 * b2.Mohm * b2.mm**2  # cell membrane resistance (->leak current)
E_LEAK = -70. * b2.mV  # reversal potential of the leak current (-> resting potential)
CAPACITANCE = 0.8 * b2.uF / b2.cm**2  # membrane capacitance
DEFAULT_INPUT_CURRENT = input_factory.get_step_current(2000,
                                                       3000,
                                                       unit_time=b2.us,
                                                       amplitude=0.2 * b2.namp)
DEFAULT_INPUT_LOCATION = [CABLE_LENGTH / 3]  # provide an array of locations
# print("Membrane Timescale = {}".format(R_TRANSVERSAL*CAPACITANCE))


def simulate_passive_cable(current_injection_location=DEFAULT_INPUT_LOCATION,
                           input_current=DEFAULT_INPUT_CURRENT,
                           length=CABLE_LENGTH,
                           diameter=CABLE_DIAMETER,
                           r_longitudinal=R_LONGITUDINAL,
                           r_transversal=R_TRANSVERSAL,
                           e_leak=E_LEAK,
                           initial_voltage=E_LEAK,
                           capacitance=CAPACITANCE,
                           nr_compartments=200,


# plot I and vm
plot_tools.plot_voltage_and_current_traces(
state_monitor, step_current, title="min input", firing_threshold=LIF.FIRING_THRESHOLD)
print("nr of spikes: {}".format(spike_monitor.count[0]))  # should be 0

LIF.getting_started()

print("resting potential: {}".format(LIF.V_REST))

# create a step current with amplitude = I_min
I_min= 0.002001*b2.uamp #need to find explaination
step_current = input_factory.get_step_current(
    t_start=5, t_end=100, unit_time=b2.ms,
    amplitude=I_min)  # set I_min to your value

# run the LIF model.
# Note: As we do not specify any model parameters, the simulation runs with the default values
(state_monitor,spike_monitor) = LIF.simulate_LIF_neuron(input_current=step_current, simulation_time = 100 * b2.ms)


# create a step current with amplitude = I_min
import matplotlib.pyplot as plt

tup=[]
#for loop for current in 0nA to 100 nA
for i in range(0,100,5) :
  I_min= i*b2.namp #need to find explaination
  step_current = input_factory.get_step_current(