plotting with the python box

Concerning processing components: filters, file load/save, visualizations, communication ...
Post Reply
ddvlamin
Posts: 160
Joined: Thu Aug 13, 2009 8:39 am
Location: Ghent University
Contact:

plotting with the python box

Post by ddvlamin »

Hi,

First of all, I'm very happy with the python box in OpenViBE. I think it will make the life of some researchers a bit easier.

For some external experiments I was asked to create a display that shows the target and non-target ERP's in a superimposed fashion, instead of using OpenViBE's display box showing the two potentials next to each other (making it hard to compare the two waveforms).

To this end I wrote a small python script which uses the matplotlib package to make matlab like plots. When I execute a simple scenario the first time, it plots the curves well, but the second time I run the scenario within the same instance of OpenVIBE, it seems to crash given this exception:

Code: Select all

OpenViBE-designer-dynamic: /builddir/build/BUILD/Python-2.7/Modules/gcmodule.c:326: visit_decref: Assertion `gc->gc.gc_refs != 0' failed.

Program received signal SIGABRT, Aborted.
0x00000038850330c5 in raise () from /lib64/libc.so.6
(gdb) backtrace
#0  0x00000038850330c5 in raise () from /lib64/libc.so.6
#1  0x0000003885034a76 in abort () from /lib64/libc.so.6
#2  0x000000388502b905 in __assert_fail () from /lib64/libc.so.6
#3  0x00000038a2719d8e in ?? () from /usr/lib64/libpython2.7.so.1.0
#4  0x00000038a269da45 in ?? () from /usr/lib64/libpython2.7.so.1.0
#5  0x00000038a271a497 in ?? () from /usr/lib64/libpython2.7.so.1.0
#6  0x00000038a271af09 in ?? () from /usr/lib64/libpython2.7.so.1.0
#7  0x00000038a26e965b in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#8  0x00000038a26ea71d in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#9  0x00000038a26eb04d in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#10 0x00000038a26e963a in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#11 0x00000038a26ea71d in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#12 0x00000038a26eb04d in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#13 0x00000038a2671c62 in ?? () from /usr/lib64/libpython2.7.so.1.0
#14 0x00000038a2648fc3 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#15 0x00000038a265a65f in ?? () from /usr/lib64/libpython2.7.so.1.0
#16 0x00000038a2648fc3 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#17 0x00000038a26e3a87 in PyEval_CallObjectWithKeywords () from /usr/lib64/libpython2.7.so.1.0
#18 0x00007fffedaf9d92 in OpenViBEPlugins::Python::CBoxAlgorithmPython::uninitialize (this=0x244aeb0)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-plugins/python/trunc/src/ovpCBoxAlgorithmPython.cpp:802
#19 0x00007ffff580d664 in OpenViBEToolkit::TBoxAlgorithm<OpenViBE::Plugins::IBoxAlgorithm>::uninitialize (this=0x244af48, rBoxAlgorithmContext=<value optimized out>)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-toolkit/trunc/include/openvibe-toolkit/box-algorithms/ovtkTBoxAlgorithm.h:37
#20 0x00007ffff70219d1 in OpenViBE::Kernel::CSimulatedBox::uninitialize (this=0x2503690)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-kernel-omk/trunc/src/openvibe-kernel/kernel/player/ovkCSimulatedBox.cpp:789
#21 0x00007ffff6ff2071 in OpenViBE::Kernel::CScheduler::uninitialize (this=0x25bfe30)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-kernel-omk/trunc/src/openvibe-kernel/kernel/player/ovkCScheduler.cpp:285
#22 0x00007ffff7015f28 in OpenViBE::Kernel::CPlayer::uninitialize (this=0x25bfdc0)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-kernel-omk/trunc/src/openvibe-kernel/kernel/player/ovkCPlayer.cpp:112
#23 0x000000000046707a in OpenViBEDesigner::CApplication::releasePlayer (this=0x7fffffffb400)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-applications/designer/trunc/src/ovdCApplication.cpp:1376
#24 0x00000000004671d9 in OpenViBEDesigner::CApplication::stopScenarioCB (this=0x7fffffffb400)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-applications/designer/trunc/src/ovdCApplication.cpp:1400
#25 0x0000000000460a15 in (anonymous namespace)::stop_scenario_cb (pButton=0xa5f1a0, pUserData=0x7fffffffb400)
    at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-applications/designer/trunc/src/ovdCApplication.cpp:172
#26 0x0000003888c0e03e in g_closure_invoke () from /lib64/libgobject-2.0.so.0
#27 0x0000003888c1ee87 in ?? () from /lib64/libgobject-2.0.so.0
#28 0x0000003888c287b5 in g_signal_emit_valist () from /lib64/libgobject-2.0.so.0
#29 0x0000003888c28b6d in g_signal_emit_by_name () from /lib64/libgobject-2.0.so.0
#30 0x0000003888c0e03e in g_closure_invoke () from /lib64/libgobject-2.0.so.0
#31 0x0000003888c1ee87 in ?? () from /lib64/libgobject-2.0.so.0
#32 0x0000003888c287b5 in g_signal_emit_valist () from /lib64/libgobject-2.0.so.0
#33 0x0000003888c28983 in g_signal_emit () from /lib64/libgobject-2.0.so.0
#34 0x0000003369a90a85 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#35 0x0000003888c0e03e in g_closure_invoke () from /lib64/libgobject-2.0.so.0
#36 0x0000003888c1e64c in ?? () from /lib64/libgobject-2.0.so.0
#37 0x0000003888c287b5 in g_signal_emit_valist () from /lib64/libgobject-2.0.so.0
#38 0x0000003888c28983 in g_signal_emit () from /lib64/libgobject-2.0.so.0
#39 0x0000003369a8f527 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#40 0x0000003369b4e223 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#41 0x0000003888c0e03e in g_closure_invoke () from /lib64/libgobject-2.0.so.0
#42 0x0000003888c1ec98 in ?? () from /lib64/libgobject-2.0.so.0
---Type <return> to continue, or q <return> to quit---
#43 0x0000003888c28555 in g_signal_emit_valist () from /lib64/libgobject-2.0.so.0
#44 0x0000003888c28983 in g_signal_emit () from /lib64/libgobject-2.0.so.0
#45 0x0000003369c85aef in ?? () from /usr/lib64/libgtk-x11-2.0.so.0
#46 0x0000003369b4bd33 in gtk_propagate_event () from /usr/lib64/libgtk-x11-2.0.so.0
#47 0x0000003369b4c103 in gtk_main_do_event () from /usr/lib64/libgtk-x11-2.0.so.0
#48 0x000000336a261a8c in ?? () from /usr/lib64/libgdk-x11-2.0.so.0
#49 0x0000003886c41e33 in g_main_context_dispatch () from /lib64/libglib-2.0.so.0
#50 0x0000003886c42610 in ?? () from /lib64/libglib-2.0.so.0
#51 0x0000003886c42c82 in g_main_loop_run () from /lib64/libglib-2.0.so.0
#52 0x0000003369b4b0b7 in gtk_main () from /usr/lib64/libgtk-x11-2.0.so.0
#53 0x000000000047d243 in go (argc=1, argv=0x7fffffffba48) at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-applications/designer/trunc/src/ovd_main.cpp:567
#54 0x000000000047d5aa in main (argc=1, argv=0x7fffffffba48) at /user/ddevlami/nas/home/openvibe_linux/trunk/openvibe-applications/designer/trunc/src/ovd_main.cpp:596
The python code is the following

Code: Select all

import numpy
import matplotlib.figure as fig
import matplotlib.pyplot as pyplot

class MyOVBox(OVBox):
	def __init__(self):
		OVBox.__init__(self)
		self.signalHeader = None

	def initialize(self):
		pyplot.ion() #nasty trick, if not in interactive mode python blocks when drawing (although it shouldn't)

	def uninitialize(self):
		pyplot.close() #close the figure
	
	def process(self):
		for inputIndex in range( len(self.input) ):
			for chunkIndex in range( len(self.input[inputIndex]) ):
				if(type(self.input[inputIndex][chunkIndex]) == OVSignalHeader):
					self.signalHeader = self.input[inputIndex].pop()
					self.data = numpy.zeros((2,self.signalHeader.dimensionSizes[1]))
				
				elif(type(self.input[inputIndex][chunkIndex]) == OVSignalBuffer):
					pyplot.cla() #clear the axes so that at any given time only two curves are shown
					chunk = self.input[inputIndex].pop()
					self.data[inputIndex,:] = numpy.array(chunk).reshape(tuple(self.signalHeader.dimensionSizes))
					x = numpy.arange(0,self.signalHeader.dimensionSizes[1],1)
					self.lines = [None] * len(self.input)
					self.lines[:] = pyplot.plot(x, self.data.transpose().tolist(), linewidth=1.0) #update line plots
	    				pyplot.draw()  
				
				elif(type(self.input[inputIndex][chunkIndex]) == OVSignalEnd):	 			
					self.input[inputIndex].pop()

box = MyOVBox()
Anybody any idea what the problem might be?

Best regards,
Dieter Devlaminck

jlegeny
Posts: 239
Joined: Tue Nov 02, 2010 8:51 am
Location: Mensia Technologies Paris FR
Contact:

Re: plotting with the python box

Post by jlegeny »

Hello Dieter,

I have tried your script and it works for me. Can you please specify your installation? Linux and python versions. Maybe your signal is somewhat particular (i have tried with p300 example from samples).

Cheers
Jozef

ddvlamin
Posts: 160
Joined: Thu Aug 13, 2009 8:39 am
Location: Ghent University
Contact:

Re: plotting with the python box

Post by ddvlamin »

Hi,

Ok as it is a draft script, I have not yet included certain checks, but each input actually expects a 1-channel signal (ERP on one channel). Maybe this is the cause of the error?

I included the scenario I used for testing, sorry for not doing that earlier. With this scenario I had no trouble (except that I can not execute it more than twice).

Linux version: Linux version 2.6.35.14-106.fc14.x86_64 (mockbuild@x86-09.phx2.fedoraproject.org) (gcc version 4.5.1 20100924 (Red Hat 4.5.1-4) (GCC) ) #1 SMP Wed Nov 23 13:07:52 UTC 2011

And python 2.7

Best regards,
Dieter Devlaminck
Attachments
python_test.xml
(15.61 KiB) Downloaded 277 times

ddvlamin
Posts: 160
Joined: Thu Aug 13, 2009 8:39 am
Location: Ghent University
Contact:

Re: plotting with the python box

Post by ddvlamin »

Hi,

I still have this problem when closing openvibe after running a scenario with the python box. I do not only have it on my linux machine but also on the windows 7 machines. Anyone that can give me a hint where this problem comes from?

If it worked for you, what python version did you use and how did you compile it, with optimization flags on? The error has something to do with the garbage collection of python and only occurs when I close OpenViBE. An errror when OpenViBE closes does not seem to be a big deal, but if you have to give this to experimenters in a hospital it is a big deal as on windows several screens about this error popup.

EDIT:

On windows 7 I have installed python 2.7 and I compile using visual studio 2010, hence using the vc10 runtime. Each time when I start OpenViBE I get this runtime error R6034: an application has made an attempt to load the C runtime library incorrectly. If I remove the python module this error does not seem to pop up. Apparently the python dll uses runtime vc90, maybe this is the cause of the problem? Is there a solution to this problem or am I the only one who has that problem?

Thanks
Dieter

Post Reply