Skip to content
This repository has been archived by the owner on Dec 12, 2022. It is now read-only.

Commit

Permalink
Fixed issue #3
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichau committed Sep 4, 2022
1 parent 9d625d2 commit 68fc012
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
7 changes: 5 additions & 2 deletions nest/nest_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def __init__(self, **kwds):
# Establish interneuron connections
self.form_connections()

self.multimeter = None
self.spikerecorder = None

# ADMINISTRATIVE VARIABLES
self.save_figures = kwds.get('save_figures', False)
self.show_figures = kwds.get('show_figures', True)
Expand Down Expand Up @@ -313,7 +316,7 @@ def create_grid(self) -> list:
for m in range(self.m):
for n in range(self.n):
K = random.randint(self.k_min, self.k_max)
nc = nest.Create(_NEURON_MODEL_NAME, K)
nc = nest.Create(_NEURON_MODEL_NAME, K, {'tau_m': 20.0})
circuit_list.append(WTACircuit(nc, (n, m)))
self.circuits = circuit_list
return circuit_list
Expand All @@ -324,7 +327,7 @@ def form_connections(self) -> None:
'p': 1.0,
'allow_autapses': False}
syn_dict = {"synapse_model": _SYNAPSE_MODEL_NAME,
# 'delay': 3.
'delay': 3.
}

# Iterate over each WTACircuit object and establish connections to every other population with p(d)
Expand Down
23 changes: 15 additions & 8 deletions nest/nest_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,19 @@ def run_simulation(inpgen, t):
nest.Simulate(t)


def measure_node_collection(nc, inpgen=None, t_sim=5000.0) -> None:
def measure_node_collection(network, nc, inpgen=None, t_sim=5000.0, save_figures=False, readout_size=20):
"""
Simulates given **NodeCollection** for **t_sim** and plots the recorded spikes, membrane potential and presented
patterns. Requires an **InputGenerator** object for pattern input generation.
"""
multimeter = nest.Create('multimeter')
multimeter.set(record_from=['V_m'])
spikerecorder = nest.Create('spike_recorder')
nest.Connect(multimeter, nc)
nest.Connect(nc, spikerecorder)
# TODO: randomly sample [readout_size] neurons from Network and measure them (replace nc)
if network.multimeter is None:
network.multimeter = nest.Create('multimeter')
network.multimeter.set(record_from=['V_m'])
nest.Connect(network.multimeter, nc)
if network.spikerecorder is None:
network.spikerecorder = nest.Create('spike_recorder')
nest.Connect(nc, network.spikerecorder)

if inpgen is None:
nest.Simulate(t_sim)
Expand All @@ -77,15 +80,16 @@ def measure_node_collection(nc, inpgen=None, t_sim=5000.0) -> None:
fig.set_figwidth(8)
fig.set_figheight(6)
# MEMBRANE POTENTIAL
dmm = multimeter.get()
dmm = network.multimeter.get()
Vms = dmm["events"]["V_m"]
ts = dmm["events"]["times"]

ax1.plot(ts, Vms)
ax1.set_title("t_sim= %d, t_start= %d" % (t_sim, (nest.biological_time - t_sim)))
ax1.set_ylabel("Membrane potential (mV)")

# SPIKE EVENTS
dSD = spikerecorder.get("events")
dSD = network.spikerecorder.get("events")
evs = dSD["senders"]
ts = dSD["times"]

Expand All @@ -101,8 +105,11 @@ def measure_node_collection(nc, inpgen=None, t_sim=5000.0) -> None:
ax3.plot(np.add(time_shift, st[i]), [i]*len(st[i]), ".", color='orange')

ax3.set_ylabel("Input channels")
ax3.set_xlim(time_shift, nest.biological_time)
ax3.set_xlabel("time (ms)")

if save_figures:
plt.savefig("simulation_%ds.png" % int(nest.biological_time/1000.0))
plt.show()


Expand Down

0 comments on commit 68fc012

Please # to comment.