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")
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=10, t_end=190, unit_time=b2.ms, amplitude=20 * b2.namp)

    # run the LIF model
    (state_monitor, spike_monitor) = simulate_LIF_neuron(input_current=step_current, simulation_time=200 * b2.ms)

    # plot the membrane voltage
    plot_tools.plot_voltage_and_current_traces(state_monitor, step_current,
                                               title="Leaky Integrate-and-Fire Neuron", 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)
 
    (state_monitor, spike_monitor) = simulate_LIF_neuron(
        input_current=sinusoidal_current, simulation_time=200 * b2.ms)

    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()
Example #3
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"
def _min_curr_expl():
    from neurodynex.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]))
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()
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."
Example #7
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 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=1.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."
Example #9
0
def getting_started():
    """
    A simple example
    """
    import neurodynex.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()
Example #10
0
def getting_started():
    """
    Simple example to get started
    """

    from neurodynex.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]))
def getting_started():
    """
    Simple example to get started
    """

    from neurodynex.tools import plot_tools
    current = input_factory.get_step_current(10, 200, 1. * b2.ms, 500 * b2.pA)
    ic = input_factory.get_zero_current()
    state_monitor, spike_monitor = simulate_AdEx_neuron(I_stim=current,
                                                        simulation_time=300 *
                                                        b2.ms)
    # plot_tools.plot_network_activity(rate_monitor, spike_monitor, state_monitor)
    # plt.show()

    plot_tools.plot_voltage_and_current_traces(state_monitor,
                                               current,
                                               title="AdEx neuron simulations")
    plt.show()
    plot_adex_state(state_monitor)

    print("nr of spikes: {}".format(spike_monitor.count[0]))
Example #12
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()
Example #13
0
def test_neurons_run():
    """Test if neuron functions are runnable."""
    import brian2 as b2
    from neurodynex.tools import input_factory
    from neurodynex.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"
def getting_started():
    """
    simple demo to get started

    Returns:

    """
    from neurodynex.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")
Example #15
0
plt.figure("Fig1")
plot_tools.plot_voltage_and_current_traces(
    state_monitor1, input_current, title="step current", firing_threshold=exp_IF.FIRING_THRESHOLD_v_spike)
plt.show()
"""

i = 4  # change i and find the value that goes into min_amp
durations = [1, 2, 5, 10, 20, 50, 100]
min_amp = [0., 4.42, 0., 1.10, .70, .48, 0.]

t = durations[i]
I_amp = min_amp[i] * b2.namp
title_txt = "I_amp={}, t={}".format(I_amp, t * b2.ms)

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 = exp_IF.simulate_exponential_IF_neuron(
    I_stim=input_current, simulation_time=(t + 20) * b2.ms)

plt.figure(1)
plot_tools.plot_voltage_and_current_traces(
    state_monitor,
    input_current,
    title=title_txt,
    firing_threshold=exp_IF.FIRING_THRESHOLD_v_spike,
    legend_location=2)
print("nr of spikes: {}".format(spike_monitor.count[0]))

plt.figure(2)
Example #16
0
            resistance = self.resistance
        if (threshold == None):
            threshold = self.threshold
        eqs = "dv/dt = (-(v-v_rest) +delta_t*exp((v-rheo_threshold)/delta_t)+ resistance * current(t,i))/(time_scale) : volt"
        neuron = b2.NeuronGroup(1,
                                model=eqs,
                                reset="v=v_reset",
                                threshold="v>threshold",
                                method="euler")
        neuron.v = v_rest
        voltage_monitor = b2.StateMonitor(neuron, ["v"], record=True)
        spike_monitor = b2.SpikeMonitor(neuron)
        net = b2.Network(neuron, voltage_monitor, spike_monitor)
        net.run(time)
        return voltage_monitor, spike_monitor


lif_neuron = expLIF()
print('7 repetitive spikes : current = 0.8 nA')
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 = lif_neuron.simulate(current=input_current,
                                                   time=200 * b2.ms)
plot_tools.plot_voltage_and_current_traces(
    state_monitor,
    input_current,
    title="step current",
    firing_threshold=lif_neuron.threshold)
print("nr of spikes: {}".format(spike_monitor.count[0]))
Example #17
0
import matplotlib.pyplot as plt
from neurodynex.adex_model import AdEx
from neurodynex.tools import plot_tools, input_factory
"""
MEMBRANE_TIME_SCALE_tau_m = 5 * b2.ms
MEMBRANE_RESISTANCE_R = 500*b2.Mohm
V_REST = -70.0 * b2.mV
V_RESET = -51.0 * b2.mV
RHEOBASE_THRESHOLD_v_rh = -50.0 * b2.mV
SHARPNESS_delta_T = 2.0 * b2.mV
ADAPTATION_VOLTAGE_COUPLING_a = 0.5 * b2.nS
ADAPTATION_TIME_CONSTANT_tau_w = 100.0 * b2.ms
SPIKE_TRIGGERED_ADAPTATION_INCREMENT_b = 7.0 * b2.pA
"""

current = input_factory.get_step_current(10, 250, 1. * b2.ms, 65.0 * b2.pA)
# Variare l'adaptation voltage coupling influisce sul numero di spikes
# Il bursting si ottiene cambiando il valore del reset del potenziale, ovviamente
# in tal modo ti posizioni in un altro punto dello spazio delle fasi
# "a" cambia anche la posizione dei punti di equilibrio a seconda della positività o negatività

state_monitor, spike_monitor = AdEx.simulate_AdEx_neuron(I_stim=current,
                                                         simulation_time=400 *
                                                         b2.ms,
                                                         a=-0.5 * b2.nS,
                                                         v_reset=-46 * b2.mV)

plt.figure(1)
plot_tools.plot_voltage_and_current_traces(state_monitor, current)
print("nr of spikes: {}".format(spike_monitor.count[0]))
plt.figure(2)
Example #18
0
idx_t_end = int(round(slow_ramp_t_end*b2.ms / b2.defaultclock.dt))
voltage_slow = state_monitor1.vm[0,idx_t_end]
print("voltage_slow = {} V".format(voltage_slow))

# Qui sotto invece un aumento repentino della corrente
b2.defaultclock.dt = 0.02*b2.ms
fast_ramp_t_end = 100
fast_ramp_current = input_factory.get_ramp_current(50, fast_ramp_t_end,
    0.1*b2.ms, 0.*b2.uA, 4.5*b2.uA)
state_monitor2 = HH.simulate_HH_neuron(fast_ramp_current, 40 * b2.ms)
idx_t_end = int(round(fast_ramp_t_end*0.1*b2.ms / b2.defaultclock.dt))
voltage_fast = state_monitor2.vm[0,idx_t_end]
print("voltage_fast = {} V".format(voltage_fast))

Una cosa importante che cambia è lo step temporale con il quale aumenta
la corrente. Questo dipende dal parametro dopo slow/fast_ramp_t_end.
Questo fa in modo che la fast current vada da cinque a dieci msecondi.
Uno si chiede "ma perché non mettere come prima b2.ms e rapportarsi a
questa unità di misura?", misteri della fede.

HH.plot_data(state_monitor1, title="Slow")
HH.plot_data(state_monitor2, title="Fast")
"""

# Hyperpolarizing current in grado di creare uno spike
I = -5
corrente = input_factory.get_step_current(10, 90, b2.ms, I*b2.uA)
state_monitor = HH.simulate_HH_neuron(corrente, 100 * b2.ms)
HH.plot_data(state_monitor, title="Hyperpolarizing current")
plt.show()
Example #19
0
from neurodynex.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,
Example #20
0
la corrente di soglia per ottenere un firing tonico in entrambi
è di 0.38 pAmp, quindi è con questa corrente che ho la biforcazione
saddle-note onto/off limit cycle.
"""

T = 1200 * b2.ms
f1 = []
f2 = []
I = []
I_ist = 0.01

neuronX = neurons.NeuronX()
neuronY = neurons.NeuronY()

while I_ist < 0.90:
    input_current = input_factory.get_step_current(100, 1100, b2.ms,
                                                   I_ist * b2.pA)
    state_monitor1 = neuronX.run(input_current, T)
    state_monitor2 = neuronY.run(input_current, T)
    spike_stats1 = spike_tools.get_spike_stats(state_monitor1, 0 * b2.mV)
    spike_stats2 = spike_tools.get_spike_stats(state_monitor2, 0 * b2.mV)
    f1.append(spike_stats1[0] / T)
    f2.append(spike_stats2[0] / T)
    I_ist += 0.01
    I.append(I_ist)
"""
print(f1)
print(f2)
print(I)
"""

plt.figure(1)