Skip to content

Commit

Permalink
add nest based examples for PyNN
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshKhilawala committed Jul 3, 2022
1 parent 99cb268 commit ad3ce3b
Show file tree
Hide file tree
Showing 3 changed files with 166 additions and 0 deletions.
49 changes: 49 additions & 0 deletions examples/nest/one_neuron_noise_PyNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
Conversion of NEST example script one_neuron_with_noise.py
"""

import pyNN.nest as sim
from pyNN.utility.plotting import Figure, Panel

sim.setup()

parameters = {
'v_rest': -70,
'cm': 0.25,
'tau_m': 10.0,
'tau_refrac': 2.0,
'tau_syn_E': 2.0,
'tau_syn_I': 2.0,
'i_offset': 0.376,
'v_reset': -70.0,
'v_thresh': -55.0
}


neuron = sim.Population(1, sim.IF_curr_alpha(**parameters), initial_values={"v": -70})
noise = sim.Population(2, sim.SpikeSourcePoisson(rate=[80000, 15000]))

neuron.record("v")


# weight = [0.0012, -0.001] # nA
weight = 0.0012
delay = 1.0

connections = sim.Projection(
neuron, noise,
sim.AllToAllConnector(),
sim.StaticSynapse(weight=weight, delay=delay))

sim.run(1000.0)

data_1 = neuron.get_data().segments[0].analogsignals[0]
assert data_1.name == "v"

Figure(
Panel(
data_1,
xticks=True,
yticks=True
)
).show()
58 changes: 58 additions & 0 deletions examples/nest/oneneuron_pyNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""
Conversion of NEST example script oneneuron.py
"""

import pyNN.nest as sim
from pyNN.utility.plotting import Panel, Figure

sim.setup()

parameters = {
'v_rest': -70,
'cm': 0.25,
'tau_m': 10.0,
'tau_refrac': 2.0,
'tau_syn_E': 2.0,
'tau_syn_I': 2.0,
'i_offset': 0.376,
'v_reset': -70.0,
'v_thresh': -55.0
}


neuron = sim.Population(1, sim.IF_curr_alpha(**parameters), initial_values={"v": -70})
neuron.record("v")

sim.run(200.0)


data_1 = neuron.get_data().segments[0].analogsignals[0]

assert data_1.name == "v"

Figure(
Panel(
data_1,
xticks=True,
yticks=True
)
).show()


neuron.set(i_offset=0.450)


sim.run(1000.0)

data_2 = neuron.get_data().segments[0].analogsignals[0]

assert data_2.name == "v"

Figure(

Panel(
data_2,
xticks=True,
yticks=True
)
).show()
59 changes: 59 additions & 0 deletions examples/nest/twoneurons_pyNN.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""
Conversion of NEST example script twoneurons.py
"""

import pyNN.nest as sim
from pyNN.utility.plotting import Figure, Panel


sim.setup()


parameters_1 = {
'v_rest': -70,
'cm': 0.25,
'tau_m': 10.0,
'tau_refrac': 2.0,
'tau_syn_E': 2.0,
'tau_syn_I': 2.0,
'i_offset': 0.376,
'v_reset': -70.0,
'v_thresh': -55.0
}
parameters_2 = parameters_1.copy()
parameters_2["i_offset"] = 0.0

neuron_1 = sim.Population(1, sim.IF_curr_alpha(**parameters_1), initial_values={"v": -70})
neuron_2 = sim.Population(1, sim.IF_curr_alpha(**parameters_2), initial_values={"v": -70})

neuron_1.record("v")
neuron_2.record("v")

weight = 0.02 # nA
delay = 1.0

connections = sim.Projection(
neuron_1, neuron_2,
sim.AllToAllConnector(),
sim.StaticSynapse(weight=weight, delay=delay))

sim.run(1000.0)

data_1 = neuron_1.get_data().segments[0].analogsignals[0]
data_2 = neuron_2.get_data().segments[0].analogsignals[0]

assert data_1.name == "v"

Figure(
Panel(
data_1,
xticks=True,
yticks=True
),
Panel(
data_2,
xticks=True,
yticks=True
)
).show()

0 comments on commit ad3ce3b

Please sign in to comment.