User defined function to set play vectors
Posted: Wed Nov 22, 2023 3:39 pm
I wanted to make this post to get some clarification about the behavior I am observing and also in case anyone else runs into a similar issue.
I am using the Vector.play method to set the values of a parameter inside one of my mod files. I started with a toy example that I found here in the forums viewtopic.php?p=19985&hilit=play+vectors#p19985. I made some minor modifications, mainly using single segment Sections.
For my use case it made sense to have my own function to set the play vectors, so I used the same code but took out the portion setting the play vectors and used it to create a function
However, when I did this I saw my recorded variables xxp1 and xxp2 were zero for all time points. After trying a bunch of different things I got it to work once I returned the data and time Vectors that I created inside my set_play_vecs function so they are available outside the scope of the function.
I also found that I could get it to work if I first made the time and data Vectors into global variables
Can anyone explain why these variables need to be available outside the scope of my function? I'm guessing the data Vector itself is still being referenced to during the simulation.
I am using the Vector.play method to set the values of a parameter inside one of my mod files. I started with a toy example that I found here in the forums viewtopic.php?p=19985&hilit=play+vectors#p19985. I made some minor modifications, mainly using single segment Sections.
For my use case it made sense to have my own function to set the play vectors, so I used the same code but took out the portion setting the play vectors and used it to create a function
Code: Select all
def set_play_vec(cell):
data = h.Vector([0,5,17,2,4,38,22,43,1, 1])
time = h.Vector([1,2,3,4,5,6,7,8,9,10])
data.play(cell(0.5).playtest._ref_xx, time, True)
# Create NEURON Section
my_cell = h.Section("neurite")
# Set play vector
set_play_vec(my_cell)
t = h.Vector().record(h._ref_t)
xxp1 = h.Vector().record(my_cell(0.1).playtest._ref_xx)
xxp2 = h.Vector().record(my_cell(0.9).playtest._ref_xx)
h.finitialize(-65 * mV)
h.continuerun(10 * ms)
plt.plot(t, xxp1, label="xxp1")
plt.plot(t, xxp2, label="xxp2")
plt.legend()
plt.show()
Code: Select all
def set_play_vec(cell):
data = h.Vector([0,5,17,2,4,38,22,43,1, 1])
time = h.Vector([1,2,3,4,5,6,7,8,9,10])
data.play(cell(0.5).playtest.xx, time, True)
return data, time
# Create NEURON Section
my_cell = h.Section(name='neurite')
# Set play vector
data, time = set_play_vec(my_cell)
t = h.Vector().record(h._ref_t)
xxp1 = h.Vector().record(my_cell(0.1).playtest._ref_xx)
xxp2 = h.Vector().record(my_cell(0.9).playtest._ref_xx)
h.finitialize(-65 * mV)
h.continuerun(10 * ms)
plt.plot(t, xxp1, label="xxp1")
plt.plot(t, xxp2, label="xxp2")
plt.legend()
plt.show()
Code: Select all
global data
global time
data = h.Vector([ 1,5,17,2,4,38,22,43,1, 1])
time = h.Vector([1,2,3,4,5,6,7,8,9,10])