unexpected behavioure for python code

About the GUI application to design signal processing pipelines
Post Reply
HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

unexpected behavioure for python code

Post by HA3 »

I have write the following python code to python scripting toolbox, this code will read a matrix (or spatial filters) from a file, and multiply it with the incoming signal, but the problem is that the output will always be zeros, I have print the data before send it to the output pin of the python toolbox, but it's not zeros.

Code: Select all

 # we use numpy to compute the mean of an array of values
import numpy 
class MyOVBox(OVBox):
    def __init__(self):
    	OVBox.__init__(self)
    	self.signalHeader = None

    # The process method will be called by openvibe on every clock tick
    def initialize(self):

    def process(self):

       for chunkIndex in range( len(self.input[0])):
          # if it's a header we save it and send the output header (same as input, except it has only one channel named 'Mean'
          if(type(self.input[0][chunkIndex]) == OVSignalHeader):
             self.signalHeader = self.input[0].pop()
             outputHeader = OVSignalHeader(
             self.signalHeader.startTime,
             self.signalHeader.endTime,
             [1, self.signalHeader.dimensionSizes[1]],
             ['Mean']+self.signalHeader.dimensionSizes[1]*[''],
             self.signalHeader.samplingRate)
             self.output[0].append(outputHeader)

          # if it's a buffer we pop it and put it in a numpy array at the right dimensions
          # We compute the mean and add the buffer in the box output buffer
          elif(type(self.input[0][chunkIndex]) == OVSignalBuffer):
             chunk1 = self.input[0].pop()
             numpyBuffer = numpy.array(chunk1).reshape(tuple(self.signalHeader.dimensionSizes))
	     f = open ( '{path_to_file}' , 'r')
	     l = numpy.array([ map(float,line.split(',')) for line in f ])
	     temp = l.dot(numpyBuffer)	
	     temp = numpy.array(temp)
             chunk = OVSignalBuffer(chunk1.startTime, chunk1.endTime, temp.tolist())
	     print "chunk = " ,chunk
             #chunk is not equal to zero 
             self.output[0].append(chunk)
          # if it's a end-of-stream we just forward that information to the output
          elif(type(self.input[0][chunkIndex]) == OVSignalEnd):
             self.output[0].append(self.input[0].pop())

 # Finally, we notify openvibe that the box instance 'box' is now an instance of MyOVBox.
 # Don't forget that step !!
box = MyOVBox()
also, there is another 3 python scripting toolbox in my scenario, I'm using ubuntu 14.04 and openvibe1.0.0

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: unexpected behavioure for python code

Post by jtlindgren »

Hi, does the python-sinus-oscillator.xml box tutorial work and produce output? If yes, then you can copy the solution from there. If not, let us know, then there might be a bug somewhere.


Happy hacking,
Jussi

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

Yes, it's work,instead I have build my based on 'sinus-oscillator' code. also I have pass the variable "chunk1" as an output, and it's work. I have work hardly to see what is going on and I think that the problem is about passing this specific variable "chunk1". the size for this variable is 3-by-128.

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: unexpected behavioure for python code

Post by jtlindgren »

Is the size of the output matrix declared correctly in the sending of the header phase? The 3x128 should be declared there. Again, you can use the EBML spy to see whats coming out structurally.


Best,
Jussi

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

I'm sorry I was think that you mean the python code of "sinus-oscillator", I didn't know that there is an xml file. I have run this file, and it's work for a second then the openvibe-designer crashed and gives me the following message:
executing script file
terminate called without an active exception
./openvibe-designer.sh: line 54: 5773 Aborted

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

I have change the signal header to make the dimesoinSize = [3, self.signalHeader.dimensionSizes[1]], but the openvibe-designer.sh crashed
self.signalHeader = self.input[0].pop()
outputHeader = OVSignalHeader(
self.signalHeader.startTime,
self.signalHeader.endTime,
[3, self.signalHeader.dimensionSizes[1]],
['Mean']+self.signalHeader.dimensionSizes[1]*[''],
self.signalHeader.samplingRate)
self.output[0].append(outputHeader)
after crashing it's gives me the following message :
terminate called without an active exception
./openvibe-designer.sh: line 54: 6148 Aborted (core dumped)

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: unexpected behavioure for python code

Post by jtlindgren »

The tutorial scenario works ok for me on OV 1.0.1 and Ubuntu 14.04. Do you have the correct version of Python?

See here,

http://openvibe.inria.fr/tutorial-using ... -openvibe/


Jussi

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

I have install and build OV 1.0.1, and run the python_sinus_oscillator.xml, the scenario run perfectly for ~ 1 second then the OV designer crashed.
this is the output on the terminal after running this scenario

[
INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> Discovered Python is 2.7.6 (default, Mar 22 2014, 23:03:14)
[GCC 4.8.2] (linux2)
[ INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> Python Interpreter initialized
[ INF ] At time 0.000 sec <Box algorithm::(0x00001d15, 0x000035b2) aka Sinus generator> executing script file
[ INF ] At time 0.000 sec <Box algorithm::(0x0000432f, 0x00000c65) aka Mean> executing script file
[ INF ] At time 0.000 sec <Box algorithm::(0x000012bf, 0x0000401e) aka Clock stimulator> executing script file
terminate called without an active exception
does python version 2.7.6 makes a problem? should I have only 2.7.3 as said in the documentation?

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: unexpected behavioure for python code

Post by jtlindgren »

Unfortunately the scenario runs ok for me on Ubuntu 14.04 using the same Python. Its not possible to say based on your output what goes wrong. You can try

# ./linux-build --debug
# ../dist/openvibe-designer.sh --debug
gdb# run

when it crashes, you should get a backtrace with 'bt'. This trace might tell us something useful, although if the crash happens inside the python code,
its hard to debug this way.


Cheers
Jussi

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

I did what you told me to do, and the following message appears after debugging
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()

then I run the designer by command

Code: Select all

 gksudo sh openvibe-designer.sh --debug
and the following message was shown :
terminate called without an active exception
xauth: /tmp/libgksu-wWhWj3/.Xauthority
xauth_env: /home/user/.Xauthority
dir: /tmp/libgksu-wWhWj3
In python_sinus_oscillator.xml I removed the spectral Analysis boxes and the scenario works correctly, but in my scenario which does not contains any spectral analysis boxes the scenario still crashed when run.

jtlindgren
Posts: 775
Joined: Tue Dec 04, 2012 3:53 pm
Location: INRIA Rennes, FRANCE

Re: unexpected behavioure for python code

Post by jtlindgren »

Thank you for the effort, but unfortunately these don't really reveal what is the problem. :( Usually if there is a problem we can replicate it on the local machine and then debug it with whatever it takes (printfs in the C++ code in the worst case...), but as I said, the thing appears to be working ok for me on Ubuntu 14.04 so there's not much we can do on this end.


Jussi

HA3
Posts: 21
Joined: Sun Nov 23, 2014 5:32 am

Re: unexpected behavioure for python code

Post by HA3 »

The problem was in my python code :shock: , the dimension label does not meet the dimension size, so I edit my code as follow

Code: Select all

            for jj in range(3):
                dimensionLabels.append( 'channel'+str(jj) )
             dimensionLabels += self.signalHeader.dimensionSizes[1] *[' ']
             print "dimensions label = " , len(dimensionLabels)
             outputHeader = OVSignalHeader(
             self.signalHeader.startTime,
             self.signalHeader.endTime,
             [3, self.signalHeader.dimensionSizes[1]],
             dimensionLabels,
             self.signalHeader.samplingRate)
             self.output[0].append(outputHeader)
The scenario does not crash anymore , but the output is always zero.

My output has [3 , 128] matrix dimension, and the dimension label is as follow : ['channel1' , 'channel2' , 'channel3' , ' ' , ...., ' '] where the number of ' ' is 128, Is that correct? in the tutorial you give, it does not tell what is the dimensionLLabel size or structure.

Thanks,

P.S : for your information , the cause of the crash of sinus oscillator example was power spectrum display box.

Post Reply