get the left/right label from 'motor-imagery-CSP'

About the GUI application to design signal processing pipelines
Post Reply
dennis
Posts: 14
Joined: Sun Mar 30, 2014 8:42 am

get the left/right label from 'motor-imagery-CSP'

Post by dennis »

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

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

Re: get the left/right label from 'motor-imagery-CSP'

Post by jtlindgren »

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

dennis
Posts: 14
Joined: Sun Mar 30, 2014 8:42 am

Re: get the left/right label from 'motor-imagery-CSP'

Post by dennis »

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

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

Re: get the left/right label from 'motor-imagery-CSP'

Post by jtlindgren »

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

dennis
Posts: 14
Joined: Sun Mar 30, 2014 8:42 am

Re: get the left/right label from 'motor-imagery-CSP'

Post by dennis »

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

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

Re: get the left/right label from 'motor-imagery-CSP'

Post by jtlindgren »

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: Select all

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

dennis
Posts: 14
Joined: Sun Mar 30, 2014 8:42 am

Re: get the left/right label from 'motor-imagery-CSP'

Post by dennis »

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: Select all

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

Post Reply