time intervals using vec.record()...

Anything that doesn't fit elsewhere.
Post Reply
OJAG
Posts: 34
Joined: Wed Nov 14, 2007 4:46 am
Location: Bogota

time intervals using vec.record()...

Post by OJAG »

Hi all,

I am running simulations using networks of neurons and at the end I want to record the temporal traces of voltage of my 100 cells. As you probably know it is absolutely possible to do, but in my case I am expending long time just by writing the vectors to .m files since I am creating two columns data arrays for each cell, where the first is time and the second voltage. The problem I thing arises from using cycles like this

Code: Select all

for(r=0;r<size_v;r+=1){
                        sprint(strg.str,"t_v=rec_list_t_%s%g.o(%g).x(%g)",end,i,n_cels,r)
                        execute(strg.str)
                        sprint(strg1.str,"v=rec_list_v_%s%g.o(%g).x(%g)",end,i,n_cels,r)
                        execute(strg1.str)
                        traces_file.printf("%g %g\n", t_v,v)
                      } 

end=P,i=index1,ncel=index of the cell, r=iteration variable,t_v=time,v=voltage
where I first write each array element in one string then I execute it and then I write row by row in the output.m file, which takes a lot of time if you think that each vector contains at least 2e4 data rows and that I have 100 cells.

Question A: Is there any more efficient way to do the same but in an optimized way?
Question B: Is there any way to record only during a period of time much shorter than t stop I mean something like if(t>=tstart &&t<=tstp){vec.record(..)...} ?


Thanks a lot for any comment

Oscar Javier

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

Re: time intervals using vec.record()...

Post by ted »

The fastest way to write a bunch of Vectors to a file is to first merge them into a Matrix with the Matrix class's setcol method, then use the Matrix class's fprint method to print the whole matrix to the file--see http://www.neuron.yale.edu/neuron/stati ... atrix.html. A potential problem is that this doubles the storage requirement.

Unless you're using the local variable time step method, you could save space and time by recording time to just one Vector, and putting the time vector in only the first column of the Matrix.
Is there any way to record only during a period of time much shorter than t stop I mean something like if(t>=tstart &&t<=tstp){vec.record(..)...} ?
No. But you can get just the data you want by using the Vector class's indwhere to discover itstart and itstp (the first indices at which t>=tstart and t<tstp, respectively), then using the Vector class's c (copy) method to select the desired parts of the time and voltage vectors.

sec6
Posts: 39
Joined: Sat Mar 15, 2008 10:32 am

Re: time intervals using vec.record()...

Post by sec6 »

Is there any way to record only during a period of time much shorter than t stop I mean something like if(t>=tstart &&t<=tstp){vec.record(..)...} ?
No.
I think there is, actually.

First, create an FInitializeHandler instance

Code: Select all

FInitializeHandler(1, init) 
next, write the "init" routine which invokes the cvode.event method:

Code: Select all

def init():
	h.cvode.event(tstart,start)
next, write the "start" routine, which sets up recording, and again invokes the cvode.event method:

Code: Select all

def start():
	myVector.record(myCell)
	h.cvode.event(tstop,stop)
finally, write the "stop" routine, which stops vector recording.

Code: Select all

def stop()
	saveToDisk(myVec)
	h.delete(myVec)
I'm not completely sure about the trick of destroying the vector to stop recording -- I think it'll work, but it's possible it'll cause a segfault, due to a pointer, somewhere, referencing deallocated memory.

If that happens, you could try, instead of stopping recording, just making the sampling interval really long:

Code: Select all

def stop()
	saveToDisk(myVec)
	myVec.record(myCell,999999999)
Or you could continue recording, and throw away further recorded data. In that case, you should prevent the vector from growing without limit by letting the "stop" routine invoke cvode.event

Code: Select all

def stop()
	saveToDisk(myVec)
	myVec.resize(0)
	h.cvode.event(interval,resizeVector)
and writing the "resizeVector" routine:

Code: Select all

def resizeVector():
	myVec.resize(0)
I've done something very like the last version, in slightly more general form.
My code snippets are all in Python-esque pseudocode, but the same approach should apply in hoc.

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

Re: time intervals using vec.record()...

Post by ted »

Good suggestions, sec6. Another excellent use of the discrete event system.

Post Reply