sccn / lsl_archived

Multi-modal time-synched data transmission over local network
242 stars 133 forks source link

Scripted Actions for LabRecorder #120

Open hoangtran355 opened 8 years ago

hoangtran355 commented 8 years ago

Hello I want to write a script that makes LabRecorder automatically stops recording, saves file and restart with a new recording after every 5 seconds. I think this can be done by writing some code in script actions part of the config file, but I don't know how to do it. Can someone help? Thanks.

dmedine commented 8 years ago

The latest version of LabRecorder is written in C++ and does not yet support scripting. However, previous versions (<=1.10) were written in Python and support scripting -- in Python (obviously). You can get this version on our ftp server: ftp://sccn.ucsd.edu/pub/software/LSL/Apps/LabRecorder-1.10.zip

You will need to run it using Python2.7, 32-bit. It does not run well in OSX, but is fine in Linux and Windows as far as I can tell.

There is an example in the config file (in the src folder) which demonstrates scripting actions for this program. Hope that helps!

ps Eventually, we will incorporate a Lua interpreter into the newer version of LabRecorder so that scripting is supported there as well...

On 6/9/2016 9:22 PM, hoangtran355 wrote:

Hello I want to write a script that makes LabRecorder automatically stops recording, saves file and restart with a new recording after every 5 seconds. I think this can be done by writing some code in script actions part of the config file, but I don't know how to do it. Can someone help? Thanks.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/120, or mute the thread https://github.com/notifications/unsubscribe/ADch7qWFRmzsEbz8XeW0U8pe6yZBDIM9ks5qKOaWgaJpZM4IynFK.

hoangtran355 commented 8 years ago

Hello @dmedine Thank you for your respond! I have successfully run the python version of LabRecorder. However, I still stuck at writing the script (I'm new to python) and the example doesn't help much. Could you provide some more detailed example? Thank you a lot.

dmedine commented 8 years ago

It does seem that stopping a recording every 5 seconds remotely is not very straight forward. Are you sure this is necessary? LSL and the XDF format were designed to encapsulate long recording sessions into one file. It is easy enough to look at 5 second long chunks after the fact. Furthermore, you need more than 10 seconds or so of data in order for the timestamp linearization algorithm in load_xdf to work properly. 5 seconds of data alone will not provide reliable time information.

chkothe commented 8 years ago

I agree, that is not one of the triggered scripts that the LabRecorder supports (these scripts run in response to the user pressing start, stop, and so on). The shortest reasonable recording is perhaps 30 seconds long, and if you want to automate that I would suggest you either hack the LabRecorder, or, which might be easier, you use AutoHotKey or a similar desktop automation tool to simulate mouse clicks on the LabRecorder buttons at the desired intervals.

On Thu, Jun 23, 2016 at 11:59 AM, David Medine notifications@github.com wrote:

It does seem that stopping a recording every 5 seconds remotely is not very straight forward. Are you sure this is necessary? LSL and the XDF format were designed to encapsulate long recording sessions into one file. It is easy enough to look at 5 second long chunks after the fact. Furthermore, you need more than 10 seconds or so of data in order for the timestamp linearization algorithm in load_xdf to work properly. 5 seconds of data alone will not provide reliable time information.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/120#issuecomment-228150659, or mute the thread https://github.com/notifications/unsubscribe/AFEl6Knm0bDcjAvyBYDUHm1B_LfMNe_vks5qOtevgaJpZM4IynFK .

hoangtran355 commented 8 years ago

Thank both of you for your information! In fact, I'm trying to get these 5s long chunk data and feed them to a real-time BCI system. We attempt to classify 3 classes of mental state for 3 different tasks. We use 5s interval because it would be hard for one to keep the mind stay in one state (I mean, to keep the mind focus on 1 task without thinking of other things) for a longer interval. But as you pointed out, this doesn't seem an ideal experiment design. Do you have any suggestion about this issue?

cboulay commented 8 years ago

Without knowing all the details, the experiment seems fine. I think maybe there's a problem in how you're approaching the signal processing and data storage.

Your application should create another LSL stream to send out marker data, i.e. information about stimulus presentation. LabRecorder should record both the neural data and the marker data continuously. It will contain some "useless" inter-trial data but that's OK. In fact it can be nice to have that data for normalization or filtering purposes.

I'm assuming you're going to do offline classification of some training data before online feedback in a separate Matlab or Python script. You would load the full continuous data and marker streams, perform filtering, artifact removal, then you'd slice your neural data into 5-second segments based on the marker times.

I can give you more information about how you might want to setup your online signal processing and feedback but I would need to know what software you're using and what kind of signal features you're interested in.

hoangtran355 commented 8 years ago

hi @cboulay My setup is like this: Collect the signal data from Epoc+ using OpenVibe Acquisition Server. Then feed the data stream to LSL, saved it to .xdf files and import to matlab using load_xdf.m Could you please clarify me about "stimulus presentation"? What is it used for? (sorry for such a naive question). I noticed that OpenVibe sent 2 streams to LSL. They are openvibeMarker and openvibeSignal. I'm not sure about openvibeMarker so I didn't use it.

I wrote a small tutorial about how I setup everything in windows. The tutorial is in the attached .doc file in case you want to take a look. Thank you for your help.

Tutorial Setup Emotiv Epoc+ in Windows.docx

cboulay commented 8 years ago

There's actually an emotiv_app branch of this repo or you can just download the emotiv app from the ftp: ftp://sccn.ucsd.edu/pub/software/LSL/Apps/Emotiv-beta.zip. So you don't need OpenVibe acquisition server for that part.

Also, after hearing more about your use case, you don't need the Python version of LabRecorder. You should use the LabRecorder.exe from the ftp or build it yourself.

You're still missing some key ingredients.

  1. You need markers in the data file that indicate when you gave instructions to the participant about which mental state to attempt. Usually you'd write a simple program that gave a visual cue on the monitor or played an auditory cue, and at the same time that program would send a marker on the marker stream.
  2. Your offline analysis script in Matlab will load the xdf file that contains both the EEG stream and the Marker stream. Analyze the Marker stream to figure out the timestamps of when the task-cue was presented. Use that time stamp to slice up your EEG stream into trials. Then you'll have to do some feature extraction and machine-learning. How you do that is up to you. In the end, your offline analysis should give you a model that transforms brain signal features into a decision variable.
  3. Then you need online analysis to process data in real-time to extract these features and transform them into the decision variable. This will usually be output as yet another LSL stream called the "Control" stream. Then some app will read the control stream and transform that value into some form visual/auditory/tactile feedback.
dmedine commented 8 years ago

BTW, there is a gotcha on the emotiv app and that is that you need the version of edk.dll that comes with the premium version of their SDK. The open source sdk does not have all the required functions in edk.dll.

On 6/24/16 7:00 AM, Chadwick Boulay wrote:

There's actually an emotiv_app branch of this repo or you can just download the emotiv app from the ftp. So you don't need OpenVibe acquisition server for that part.

Also, after hearing more about your use case, you don't need the Python version of LabRecorder. You should use the LabRecorder.exe from the ftp.

You're still missing some key ingredients.

  1. You need markers in the data file that indicate when you gave instructions to the participant about which mental state to attempt. Usually you'd write a simple program that gave a visual cue on the monitor or played an auditory cue, and at the same time that program would send a marker on the marker stream.
  2. Your offline analysis script in Matlab will load the xdf file that contains both the EEG stream and the Marker stream. Analyze the Marker stream to figure out the timestamps of when the task-cue was presented. Use that time stamp to slice up your EEG stream into trials. Then you'll have to do some feature extraction and machine-learning. How you do that is up to you. In the end, your offline analysis should give you a model that transforms brain signal features into a decision variable.
  3. Then you need online analysis to process data in real-time to extract these features and transform them into the decision variable. This will usually be output as yet another LSL stream called the "Control" stream. Then some app will read the control stream and transform that value into some form visual/auditory/tactile feedback.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/120#issuecomment-228353286, or mute the thread https://github.com/notifications/unsubscribe/ADch7hZ_7y1w8umQdu_-OmVHk0haHOCfks5qO-MSgaJpZM4IynFK.

hoangtran355 commented 8 years ago

I'm not sure if I can run the emotiv app, because I only have an research SDK, not an Premium version. Anyway, I feel okay with the Openvibe acquisition server. Thank you for your instructions, it's really useful. I will try it and tell you if I meet a problem.