using single input to python tool box to pass all channels

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

using single input to python tool box to pass all channels

Post by HA3 »

I have make the following editing on the averaging signal example in python tutorial, and I apply it on 3 channels with one input to the python scripting toolbox and one output , but it's always gives me that there is one input and one output, I conclude that we have to do channel localization and pass each channel to an input of the python toolbox, for example if i have 3 channels, then I should have 3 input signal to that toolbox and the same thing applies to the output of the toolbox, is that necessary?

the expected output of my code is to average each channel.

Code: Select all

# we use numpy to compute the mean of an array of values
import numpy

 # let's define a new box class that inherits from OVBox
class MyOVBox(OVBox):
    def __init__(self):
    	OVBox.__init__(self)
    # we add a new member to save the signal header information we will receive
    	self.signalHeader = None

    # The process method will be called by openvibe on every clock tick
    def process(self):
       # we iterate over all the input chunks in the input buffer
      x = len(self.input)
      print ("the size is ", x) 
      for i in range(len(self.input)):
       for chunkIndex in range( len(self.input[i]) ):
          # 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[i][chunkIndex]) == OVSignalHeader):
             self.signalHeader = self.input[i].pop()
             outputHeader = OVSignalHeader(
             self.signalHeader.startTime,
             self.signalHeader.endTime,
             [1, self.signalHeader.dimensionSizes[1]],
             ['Mean']+self.signalHeader.dimensionSizes[1]*[''],
             self.signalHeader.samplingRate)
             self.output[i].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[i][chunkIndex]) == OVSignalBuffer):
             chunk = self.input[i].pop()
             numpyBuffer = numpy.array(chunk).reshape(tuple(self.signalHeader.dimensionSizes))
             numpyBuffer = numpyBuffer.mean(axis=0)
             chunk = OVSignalBuffer(chunk.startTime, chunk.endTime, numpyBuffer.tolist())
             self.output[i].append(chunk)
          # if it's a end-of-stream we just forward that information to the output
          elif(type(self.input[i][chunkIndex]) == OVSignalEnd):
             self.output[i].append(self.input[i].pop())

 # Finally, we notify openvibe that the box instance 'box' is now an instance of MyOVBox.
 # Don't forget that step !!
box = MyOVBox()
the output for the

Code: Select all

print ("the size is ", x) 
statement always gives me one , and the oscillator is generate 3 channels !,and I expect to have 3 element (or channels) in the

Code: Select all

self.input
not one!

this my scenario and the configuration of sinus oscillator which is generate 3 channels
delete.png
delete.png (18.86 KiB) Viewed 2161 times
My operating system is ubuntu 14.04 , using openViBE1.0.0
Attachments
delete.png
delete.png (31.47 KiB) Viewed 2161 times

gserrier
Posts: 71
Joined: Tue Apr 01, 2014 8:22 am

Re: using single input to python tool box to pass all channe

Post by gserrier »

Hi,
You are confusing stream and stream structure.

You box have only one input, so self.input is size 1. For example, if the signal display was a python box, self.input would be equal to 3.

The channel is not a characteristic of the box, but of the stream. As you are using the signal type stream, the stream will have a fix structure (see http://openvibe.inria.fr/stream-structures/). It will be composed of a 2-dimensional matrix of size [N x M] with N the amount of channel, and M the amount of samples by channel.

Guillaume

Post Reply