Page 1 of 1

Record from multiple neurons

Posted: Wed Apr 08, 2020 6:47 pm
by Mrohani57
Hi everyone,

I have a fascicle in PNS, consist of 'fiberNum' fibers, I need to record from each one of these fibers,
I have tried this in HOC:
objref vvec, tvec,rcrd

tvec = new Vector(timeStepsNum)
rcrd = new Vector(timeStepsNum)
vvec = new Matrix(timeStepsNum,fiberNum)
tvec.record(&t, dt) // record time
for k=0, fiberNum-1{
rcrd.record(&node[k][node2check].v( 0.5 ), dt)
vvec.setcol(rcrd,k)
}

and this in NEURON-python :
node_v= h.Vector()
for i in range(fiberNum):
node_v.record(h.node[node2check](0.5)._ref_v)
voltage[:,i]=node_v.to_python()
t=h.Vector()
t.record(h._ref_t)

and none of them are working, I mean voltage and vvec are both empty,
what is the source of the problem?

Re: Record from multiple neurons

Posted: Thu Apr 09, 2020 12:13 am
by ramcdougal
The basic sequence is to: (1) for each location, create a vector and do the record; (2) finitialize (this is done automatically if you use run() (h.run() in Python)); (3) simulate for some time; then (4) store the results as you wish.

With respect to (1), you are only ever creating a single vector. If you're recording time series, you need a separate vector for each value being recorded. Create new vectors and store them in a list using a for loop or list comprehension. e.g. if in Python I wanted to store the membrane potentials at the center of a list of sections my_secs:

Code: Select all

my_secs_v = [h.Vector().record(sec(0.5)._ref_v) for sec in my_secs]
For (2) and (3): this wasn't in your snippet, but presumably it's happening somewhere. In particular, there simulation MUST be initialized after recording is setup or no values will be recorded.

For (4), you're trying to store values before the simulation has been run. There are no values to store at that point.

For what it's worth, node_v.to_python() is equivalent to list (node_v). I'm guessing voltage is a numpy array? I'm not sure, but you probably don't need to do the to_python since Vectors are iterable... It's very rare to need to copy a Vector into another data type. If the Vector doesn't work directly without conversion, usually vector.as_numpy() will work and that has essentially no overhead as it reuses the memory instead of making a copy.

Re: Record from multiple neurons

Posted: Thu Apr 09, 2020 12:05 pm
by ted
To emphasize what ramcdougal wrote
For (4), you're trying to store values before the simulation has been run. There are no values to store at that point.
(and remove any ambiguity that there might still be), the Vector record() method captures values "on the fly" in the course of a simulation. If you execute one or more Vector record() statements, the vector(s) that will capture values will remain empty until you either call finitialize() (which will capture the value(s) at time t == 0), or call run() or do something equivalent (like
finitialize()
fadvance()
etc.). For more information about Vector record(), read the Programmers' Reference entry.