OpenViBE forum

The OpenViBE community
It is currently Thu Oct 18, 2018 2:47 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Sat Sep 05, 2015 8:48 am 
Offline

Joined: Sun Mar 30, 2014 8:42 am
Posts: 14
Hi,
I want to add python script to 'motor-imagery-CSP' in 'bci-example' . now, the problem is that every epoch
is 11*32,means 11 chanels and 32 sampling points, it's not a trial! :( ,If i want to get every trial(Epoch Duration:4 seconds) by python from 'Generic stream reader'. what can i do? Or how can i get the 'start label' of every motor-imagery by python? Or if i can get the left/right label in every trial by python?
Thank you for your help :D


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 07, 2015 7:35 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 757
Location: INRIA Rennes, FRANCE
Hi Dennis,

the trial labels and timestamps are carried in the stimulation stream, you need to look into that stream to see the segmentation. To get a single trials data to python, you can either modify the scenario epocher to turn the stream to 4s data chunks, or alternatively assemble that 4s in python from the smaller blocks. The epochs are probably overlapping in the original scenario on purpose (simulates a sliding window over data). This can again be changed by modifying the epocher box params.


Happy hacking,
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 07, 2015 2:17 pm 
Offline

Joined: Sun Mar 30, 2014 8:42 am
Posts: 14
jtlindgren wrote:
Hi Dennis,

the trial labels and timestamps are carried in the stimulation stream, you need to look into that stream to see the segmentation. To get a single trials data to python, you can either modify the scenario epocher to turn the stream to 4s data chunks, or alternatively assemble that 4s in python from the smaller blocks. The epochs are probably overlapping in the original scenario on purpose (simulates a sliding window over data). This can again be changed by modifying the epocher box params.


Happy hacking,
Jussi


Hi Jussi
I'm very thank you for your help. But i'm not very understand yet :oops: .
1.Does 'the scenario epocher' means 'Time based epoching'?
2.When i connect 'Generic stream reader'(Output stream[stimulation]) to 'Python scripting'(Input stream[stimulation]),how i can get 'the trial labels'?

Good luck! :D
Dennis


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 07, 2015 2:44 pm 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 757
Location: INRIA Rennes, FRANCE
1. Yes
2. Please see

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

Then in the stream received by python, you have likely to look for some of the following numeric codes,

http://openvibe.inria.fr/stimulation-codes/

or alternatively there seems to be some type of map at share/[...]/StimulationsCodes.py which might also be useful.


Good luck,
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Sun Sep 13, 2015 3:16 pm 
Offline

Joined: Sun Mar 30, 2014 8:42 am
Posts: 14
jtlindgren wrote:
1. Yes
2. Please see

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

Then in the stream received by python, you have likely to look for some of the following numeric codes,

http://openvibe.inria.fr/stimulation-codes/

or alternatively there seems to be some type of map at share/[...]/StimulationsCodes.py which might also be useful.


Good luck,
Jussi



Hi Jussi,
I have taken much time to try as you say ,but there is always some problem.
when i print the 'Generic stream reader'(Output stream[stimulation]) ,there is nothing :? here is my code:

if(len(self.input[1])):
if(type(self.input[1][0]) == OVStimulation):
stim = self.input[1].pop()
print 'stimulation'
print 'input[1]:'
print type(self.input[1])
print len(self.input[1])
print self.input[1][0]

Is there something wrong with it ?

Good luck! :D
Dennis


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 14, 2015 8:28 am 
Offline

Joined: Tue Dec 04, 2012 3:53 pm
Posts: 757
Location: INRIA Rennes, FRANCE
Hi Dennis,

we don't usually provide basic coding help - a situation like this can be solved by basic skills in Python and careful inspection of whats contained in the different variables. Nevertheless, since reading stims is a very generic situation and we don't have currently have a related test for the python case, I wrote the following script to test that the stim passing works. And it seems that it does!

What the code does is to loop all the chunks received in the input socket 0 (the first one), tests that they are StimulationSet, and then prints out each stimulation in each such received set. The easiest way to test it is to get the input from the clock stimulator box (then you can be sure its not a problem of the file).

Code:
class MyOVBox(OVBox):
   def __init__(self):
      OVBox.__init__(self)
      
   def initialize(self):
      # nop
      return
      
   def process(self):
      for chunkIndex in range( len(self.input[0]) ):
         chunk = self.input[0].pop()
         if(type(chunk) == OVStimulationSet):
            for stimIdx in range(len(chunk)):
               stim=chunk.pop();
               print 'At time ', stim.date, ' received stim ', stim.identifier
         else:
            print 'Received chunk of type ', type(chunk), " looking for StimulationSet"
            
      return
      
   def uninitialize(self):
      # nop
      return

box = MyOVBox()



Happy hacking,
Jussi


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 17, 2015 12:41 pm 
Offline

Joined: Sun Mar 30, 2014 8:42 am
Posts: 14
jtlindgren wrote:
Hi Dennis,

we don't usually provide basic coding help - a situation like this can be solved by basic skills in Python and careful inspection of whats contained in the different variables. Nevertheless, since reading stims is a very generic situation and we don't have currently have a related test for the python case, I wrote the following script to test that the stim passing works. And it seems that it does!

What the code does is to loop all the chunks received in the input socket 0 (the first one), tests that they are StimulationSet, and then prints out each stimulation in each such received set. The easiest way to test it is to get the input from the clock stimulator box (then you can be sure its not a problem of the file).

Code:
class MyOVBox(OVBox):
   def __init__(self):
      OVBox.__init__(self)
      
   def initialize(self):
      # nop
      return
      
   def process(self):
      for chunkIndex in range( len(self.input[0]) ):
         chunk = self.input[0].pop()
         if(type(chunk) == OVStimulationSet):
            for stimIdx in range(len(chunk)):
               stim=chunk.pop();
               print 'At time ', stim.date, ' received stim ', stim.identifier
         else:
            print 'Received chunk of type ', type(chunk), " looking for StimulationSet"
            
      return
      
   def uninitialize(self):
      # nop
      return

box = MyOVBox()



Happy hacking,
Jussi



Hi Jussi,
I have try your method, and get the class label. I will try to cut the trial as the class. If i make success ,will tell you here :D
Thank you very much!
Good luck! :D
Dennis


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group
Americanized by Maël Soucaze.