A quick question. When I create a Network
object whose NeuronGroup
elements use in their equations some TimedArray
s, where are these latter, stored within the Network
attributes/methods?
Consider, for example, the following sample code:
# Brian module
import os
from brian2 import *
code_dir = os.path.abspath('./code_testing') # It is better to provide always the absolute path
set_device('cpp_standalone',directory=code_dir,build_on_run=False)
device.delete(force=True) # Clean codegen directory for safety
defaultclock.dt = 5e-4*second
# Sample code
N_neurons = 10
duration = 1.0*second
pars = { 'vl': 0.0,
'vr': 10.0,
'vt': 20.0,
'taum': 20. * second,
'trpn': 2. * second,
'ix': 20.0,
'sx': 2.0,
'ICs': 10.*np.ones(N_neurons),
'ratet': 5000.0}
# Generate TimedArray
ta = np.tile(0.5 * np.arange(0, N_neurons), (int(duration // (0.1 * second)), 1))
stimulus = TimedArray(ta, dt=0.1 * second,name='stim')
def neuron_simulation(N_neurons,pars,stimulus):
# LIF with parametrized noise input
eqs = Equations('''
# LIF equation
dv/dt = (vl-v + ix*stimulus(t,i))/taum + sx*stimulus(t,i)*xi/(taum**.5) : 1 (unless refractory)
ix : 1
sx : 1
''')
cells = NeuronGroup(N_neurons, eqs,
threshold='v>=vt',
reset='v+=vr-vt',
refractory='trpn',
method='euler',
namespace=pars,
name='Neu', order=0)
cells.ix = pars['ix']
cells.sx = pars['sx']
l = [cells]
return Network(l)
nnet = neuron_simulation(N_neurons,pars,stimulus=stimulus)
# Add Monitor
mon = StateMonitor(nnet['Neu'],variables=['v'],record=True,dt=1*ms,name='v_mon')
nnet.add(mon)
# Run
nnet.run(duration=duration,report='text')
# Build
device.build(directory=code_dir)
# Show
plt.plot(mon.t_,mon.v_.T)
plt.show()
– First, I tried to access nnet.objects
or nnet['Neu'].contained_objects
but I could not find my stim
Timed Array. Where is it?
– Second, I would like to add a TimedArray or manipulate my stim
one after creating nnet
. Can I do so just by adding it to the network by nnet.add(<my_timedarray>)
?
– Third, is there a way I could specify my timed array stimulus to my NeuronGroup
after creating it (rather than passing it as an input argument as it is now), hoping that building everything at the end, Brian
is sufficiently smart to resolve dependencies? In this case, do I need to define my TimedArray
always in the global scope w.r.t. the method defining my NeuronGroup
object (in my case neuron_simulation
)?
Thanks.