Skip to content

Commit

Permalink
Merge pull request #1 from apdavison/hk/add-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshKhilawala committed Jul 24, 2024
2 parents 1b358db + 221d8ac commit 45f5fa2
Show file tree
Hide file tree
Showing 4 changed files with 1,103 additions and 71 deletions.
49 changes: 30 additions & 19 deletions examples/one_neuron_example.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# encoding: utf-8
"""
A simple native NEST example of simulating One Neuron with the help of PyNN.
A conversion to PyNN of the "One neuron example" from the NEST examples gallery.
See: https://nest-simulator.readthedocs.io/en/stable/auto_examples/one_neuron.html
Usage: one_neuron_example.py [-h] [--plot-figure] [--debug DEBUG] simulator
Expand All @@ -27,23 +29,23 @@
# === Define parameters ========================================================

cell_params = {
"v_rest": -70.0, # (mV)
"v_reset": -70.0, # (mV)
"cm": 0.250, # (nF)
"tau_m": 10, # (ms)
"tau_refrac": 2, # (ms)
"tau_syn_E": 2, # (ms)
"tau_syn_I": 2, # (ms)
"v_thresh": -55.0, # (mV)
"i_offset": 0.376, # (nA)
"v_rest": -70.0, # (mV)
"v_reset": -70.0, # (mV)
"cm": 0.250, # (nF)
"tau_m": 10, # (ms)
"tau_refrac": 2, # (ms)
"tau_syn_E": 2, # (ms)
"tau_syn_I": 2, # (ms)
"v_thresh": -55.0, # (mV)
"i_offset": 0.376, # (nA)
}

# === Build the network ========================================================

sim.setup(timestep=0.1) # (ms)
sim.setup(timestep=0.1) # (ms)

cell_type = sim.IF_curr_alpha(**cell_params)
neuron = sim.Population(1, cell_type, label="Neuron 1")
neuron = sim.Population(1, cell_type, initial_values={"v": -70.0}, label="Simulation result")
neuron.record("v")


Expand All @@ -54,23 +56,32 @@
data_v = neuron.get_data().segments[0].filter(name="v")[0]

if options.plot_figure:
figure_filename = normalized_filename("Results", "one_neuron_example", "png",
options.simulator, sim.num_processes())
from neo import AsciiSignalIO
from quantities import kHz

reference_data = AsciiSignalIO(
"one_neuron_example_reference_data.txt", sampling_rate=1 * kHz
).read_block()

figure_filename = normalized_filename(
"Results", "one_neuron_example", "png", options.simulator, sim.num_processes()
)
Figure(
Panel(
data_v[:,0],
reference_data.segments[0].analogsignals[0],
data_v[:, 0],
xticks=True,
yticks=True,
xlabel="Time (in ms)",
ylabel="Membrane Potential (mV)"
ylabel="Membrane Potential (mV)",
line_properties=[{"lw": 3}, {"lw": 1}],
data_labels=["Reference data", "Simulation result"]
),
title="One Neuron",
annotations="One Neuron Example using PyNN"
annotations=f"One Neuron Example using PyNN (simulator: {options.simulator})",
).save(figure_filename)
print(figure_filename)

# === Clean up and quit ========================================================

sim.end()


Loading

0 comments on commit 45f5fa2

Please sign in to comment.