using neuron.h.Graph() through python

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

Moderator: hines

Post Reply
adamimos
Posts: 45
Joined: Mon Jan 25, 2010 4:49 pm

using neuron.h.Graph() through python

Post by adamimos »

Hey, I'm trying to use the graphing using neuron.h.Graph() as opposed to converting the data to a numpy array and then using pylab. In order to test things out I'm trying to use the most simple code to make a graph (which I pretty much copied from the NEURON and Python paper):

Code: Select all

from neuron import h

soma = h.Section()
soma.insert('pas')
g=h.Graph()
g.size(0,5,-80,40)
g.addvar('v(0.5)', sec = soma)
h.dt = 0.025
tstop = 5
vinit = -65

def initialize():
    h.finitialize(vinit)
    h.fcurrent()

def integrate():
    g.begin()
    while h.t< tstop:
        h.fadvance()
        g.plot(h.t)
    g.flush()

initialize()
integrate()


raw_input("hi")

what happens is that I get a square window popping up that is blank (it's just white and blank). Any idea what is going on? Thanks.
adamimos
Posts: 45
Joined: Mon Jan 25, 2010 4:49 pm

Re: using neuron.h.Graph() through python

Post by adamimos »

I hate to just bombard with questions. But here is a more important problem: When i try to import the GUI i get this:

Code: Select all

In [1]: from neuron import gui
MPI_Initialized==false, disabling MPI functionality.
NEURON -- Release 7.1 (359:7f113b76a94b) 2009-10-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html

python(73824,0x7fff7004dbe0) malloc: *** error for object 0x1026d04b8: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap
Similarly,

Code: Select all

In [1]: import neuron
MPI_Initialized==false, disabling MPI functionality.
NEURON -- Release 7.1 (359:7f113b76a94b) 2009-10-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html


In [2]: neuron.h.xopen("$(NEURONHOME)/lib/hoc/stdrun.hoc")
python(75273,0x7fff7004dbe0) malloc: *** error for object 0x1028dee98: incorrect checksum for freed object - object was probably modified after being freed.
*** set a breakpoint in malloc_error_break to debug
Abort trap

If anyone has any idea what is going on that would be greatly appreciated.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: using neuron.h.Graph() through python

Post by ted »

adamimos wrote:Hey, I'm trying to use the graphing using neuron.h.Graph() as opposed to converting the data to a numpy array and then using pylab.
. . .
what happens is that I get a square window popping up that is blank (it's just white and blank). Any idea what is going on? Thanks.
Beats the heck out of me. I just tried your code and it worked perfectly well, right down to printing "hi" in the xterm and waiting for a user reply before returning to the >>> prompt. I see a typical NEURON Graph that shows a plot of v(0.5), which starts from an initial value of -65 mV at t=0 and decays monoexponentially toward -70 mV (e_pas).

But I'm using Linux, and I suspect you aren't. Do I correctly guess that you're using NEURON under MSWin? If so, which version of MSWin?
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: using neuron.h.Graph() through python

Post by ted »

adamimos wrote:I hate to just bombard with questions. But here is a more important problem: When i try to import the GUI i get this
I don't see any of this--no error msgs at all.

If you're using MSWin, maybe that's where the problem lies. If you haven't already said so, which version of what OS are you using?

If it's MSWin, I see that a new alpha installer came out just day before yesterday--at
http://www.neuron.yale.edu/ftp/neuron/versions/alpha/
look for
nrn-7.2.alpha-400-setup.exe
Seems like the problems you're encountering would be fairly common, hence likely to have been fixed in this more recent installer.
adamimos
Posts: 45
Joined: Mon Jan 25, 2010 4:49 pm

Re: using neuron.h.Graph() through python

Post by adamimos »

hey, thanks for the reply. I'm actually using OS X.
adamimos
Posts: 45
Joined: Mon Jan 25, 2010 4:49 pm

Re: using neuron.h.Graph() through python

Post by adamimos »

Well in any case now, I've gotten acces to a linux box, so I should be good. However, it'd be helpful if anyone knew what was going on. Thanks.


I'm not sure if this helps solve the mystery at all: every once in a while when I try "from neuron import gui" in python it will actually work, and I will get the main menu bar popping up. However, the vast majority of the time I get that checksum error. Strange...
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: using neuron.h.Graph() through python

Post by hines »

I can't reproduce the problem on my osx 10.4 i686 machine. Both the
standard 7.1 distribution and my latest sources are working for your
test case.
adamimos
Posts: 45
Joined: Mon Jan 25, 2010 4:49 pm

Re: using neuron.h.Graph() through python

Post by adamimos »

hines wrote:I can't reproduce the problem on my osx 10.4 i686 machine. Both the
standard 7.1 distribution and my latest sources are working for your
test case.
no problem, thanks for your help. after playing around with it a bit more, if you do from neuron import * at the begining, and then do from neuron import gui at the end, it seems to work. I'm not sure exactly what the problem is, but this code works:

Code: Select all

from neuron import *

soma = h.Section()

soma.insert('pas')
g=h.Graph()
g.size(0,5,-80,-40)
g.addvar('v(0.5)', sec = soma)
h.dt = 0.025
tstop = 5
vinit = -65

def initialize():
    h.finitialize(vinit)
    h.fcurrent()

def integrate():
    g.begin()
    while h.t< tstop:
        h.fadvance()
        g.plot(h.t)
    g.flush()

initialize()
integrate()


from neuron import gui


raw_input("hi")
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: using neuron.h.Graph() through python

Post by patoorio »

Hi,

I want to re-float this issue because I'm having it with Ubuntu 12.04 x64, with python 2.7.3 and Neuron 7.2. It also happens with Debian (latest 64bit), python 2.6.6 and neuron 7.2. In both cases I have spyder (2.1.9 in Ubuntu; 2.1.11 in Debian) but it also happens in ipython.
I have to say that successfully went to the process of compiling neuron as a python module, having to install one or another package until it compiled correctly. Maybe I'm still missing some package, library or module?
I know I can go with pylab's plotting facilities, but I want to know that everything else works as it should.
BTW, I'm using exaclty the same code as in the 'Python + Neuron' paper (Front Neurosci); i just added the raw_input line at the end

Best Regards
patoorio
Posts: 81
Joined: Wed Jan 30, 2008 12:46 pm

Re: using neuron.h.Graph() through python

Post by patoorio »

Solved by adding

Code: Select all

h.graphList[0].append(g)
That worked for me.

Also, the behavior of the plot is better if I use

Code: Select all

g.size(0,h.tstop,-80,40)
In this way the time scale will adjust automatically as tstop is changed.

Regards
Post Reply