Using netstim output as a source for vecstim

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

Post Reply
cwei_h

Using netstim output as a source for vecstim

Post by cwei_h » Thu Aug 01, 2013 7:46 am

Greetings,
The idea here is to use NetStim to generate a train of stimuli, save it using Vector, and then using this Vector object as a source for VecStim.

Using the code below, I could generate a train of stimuli with no problem (see stim0 ), but when i check the output from vecstim, it gives me a single stimuli ( see rec0 ). The two should be the same :( Could you give me some pointers?

Code: Select all

 
import neuron
from neuron import h
from numpy import *
  
TSTOP          = 10000
h("objref nil");
netstim0 = h.NetStim()
netstim0.start    = 100      # start 100 ms after netcon.delay
netstim0.noise    = 1        # no mpi works fine if noise is set to zero
netstim0.number   = 1e9     # 1 
netstim0.interval = 2        # 25

nc0 = h.NetCon(netstim0, h.nil)
stim0 = h.Vector()
nc0.record(stim0)
h.finitialize(-65)
neuron.run(TSTOP)
print array(stim0)

vs0 = h.VecStim()
vs0.play(stim0)
nc0 = h.NetCon(vs0, h.nil)
rec0 = h.Vector()
nc0.record(rec0)

h.finitialize(-65)
neuron.run(TSTOP)
print array(rec0)

ted
Site Admin
Posts: 5572
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using netstim output as a source for vecstim

Post by ted » Thu Aug 01, 2013 1:43 pm

These statements
nc0 = h.NetCon(netstim0, h.nil)
nc0.record(stim0)
set up vector recording of times at which netstim0 generates events. After that, you can do anything you like to nc0, but that won't stop the recording of events to stim0--every run you launch will overwrite the previous contents of stim0 with new event times generated by netstim0.

The fact that even a single event is recorded to rec0 is entirely an accident of the way that NEURON's standard run system is organized and how your program is parsed. Why do I say this? Simply comment out everything from
vs0 = h.VecStim()
down, and append these statements
h.finitialize()
print array(stim0)
and you'll see that initialization clears the contents of stim0--as it must, in order to prepare stim0 for recording of new event times. The fact that rec0 records a single event suggests that the event queue is initialized (meaning that the first event that is to be delivered is put on the queue) before recording vectors are reset.

So what to do about your code's problem? You could destroy netstim0. Or you could create a new hoc vector that contains a copy of stim0's contents, and use the new vector to drive the VecStim.

A suggestion for future development and debugging: until you're sure that something works, it's a good idea to use small numbers and short durations, like TSTOP = 10, nsetstim0.start = 1, and netstim0.number = 10.

cwei_h

Re: Using netstim output as a source for vecstim

Post by cwei_h » Thu Aug 01, 2013 10:07 pm

I tried destroying netstim0.
Works great,
Thanks very much =D

ted
Site Admin
Posts: 5572
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Using netstim output as a source for vecstim

Post by ted » Fri Aug 02, 2013 10:08 am

Glad that it works. Thanks for using NEURON!

Post Reply