gui not accessible and graphs not updating while running simulations from Python
Posted: Tue Apr 17, 2018 9:42 am
Hi,
I am migrating from hoc based control of Neuron, to a Python + hoc system. I am now able to run the simulations as I wanted and record the results. I am using Spyder for writing and to execute the commands. I initiate the model using:
from neuron import h, gui
import numpy
import matplotlib.pyplot as plt...etc.
I run the simulations using a for loop, exemplified below, that should update a graph after every simulation run. This actually does not happen, instead, the graph is updated only when exiting the loop. I try then to use graphs on neuron instead, but while running the simulation I can´t press anything in the Neuron gui, much in contrast to what happens if I use the HOC code. That applies to any menu in the Nueron gui.
Any suggestion to improve this behavior? Thanks, Claudio.
def RunSim():
global Savearray
V_vec=h.Vector(Pms['timestep']*Pms['expdur'])
t_vec=h.Vector(Pms['timestep']*Pms['expdur'])
V_vec.record(h.soma(0.5)._ref_v)
t_vec.record(h._ref_t)
for Run_n in range(0,Pms['batchRepetitions']): # the run loop
if Run_n!=0:
Pms[changewhatstring]=Pms[changewhatstring]+Pms['batchIncrement']
CClamp_stim() # changes the Iclamp properties in this example.
h.finitialize(-75)
h.fcurrent()
h.run()
if Run_n==0:
Pt_vec=t_vec.to_python()
Pt_vec=Pt_vec[:-1]
Savearray[Run_n]=Pt_vec
PV_vec=V_vec.to_python()
PV_vec=PV_vec[:-1]
Savearray[Run_n+1]=PV_vec
if Run_n!=0:
fig_temp=plt.plot(Savearray[0],Savearray[Run_n+1])
else:
fig_temp= plt.figure(figsize=(8,4)) # Default figsize is (8,6)
fig_temp=plt.plot(Savearray[0],Savearray[Run_n+1])
fig_temp=plt.xlabel('time')
fig_temp=plt.ylabel('mV')
plt.show()
Savearray=Savearray.T
numpy.savetxt("Results.csv", Savearray, delimiter=",")
I am migrating from hoc based control of Neuron, to a Python + hoc system. I am now able to run the simulations as I wanted and record the results. I am using Spyder for writing and to execute the commands. I initiate the model using:
from neuron import h, gui
import numpy
import matplotlib.pyplot as plt...etc.
I run the simulations using a for loop, exemplified below, that should update a graph after every simulation run. This actually does not happen, instead, the graph is updated only when exiting the loop. I try then to use graphs on neuron instead, but while running the simulation I can´t press anything in the Neuron gui, much in contrast to what happens if I use the HOC code. That applies to any menu in the Nueron gui.
Any suggestion to improve this behavior? Thanks, Claudio.
def RunSim():
global Savearray
V_vec=h.Vector(Pms['timestep']*Pms['expdur'])
t_vec=h.Vector(Pms['timestep']*Pms['expdur'])
V_vec.record(h.soma(0.5)._ref_v)
t_vec.record(h._ref_t)
for Run_n in range(0,Pms['batchRepetitions']): # the run loop
if Run_n!=0:
Pms[changewhatstring]=Pms[changewhatstring]+Pms['batchIncrement']
CClamp_stim() # changes the Iclamp properties in this example.
h.finitialize(-75)
h.fcurrent()
h.run()
if Run_n==0:
Pt_vec=t_vec.to_python()
Pt_vec=Pt_vec[:-1]
Savearray[Run_n]=Pt_vec
PV_vec=V_vec.to_python()
PV_vec=PV_vec[:-1]
Savearray[Run_n+1]=PV_vec
if Run_n!=0:
fig_temp=plt.plot(Savearray[0],Savearray[Run_n+1])
else:
fig_temp= plt.figure(figsize=(8,4)) # Default figsize is (8,6)
fig_temp=plt.plot(Savearray[0],Savearray[Run_n+1])
fig_temp=plt.xlabel('time')
fig_temp=plt.ylabel('mV')
plt.show()
Savearray=Savearray.T
numpy.savetxt("Results.csv", Savearray, delimiter=",")