DataHub: Difference between revisions

From TSG Doc
Jump to navigation Jump to search
mNo edit summary
 
(40 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Infobox software
{{Infobox software
| name                  = DataHub
| name                  = Lab Streaming Layer
| logo                  =
| screenshot            =
| caption                =
| developer              = Christian Kothe; Chadwick Boulay.
| developer              = Christian Kothe; Chadwick Boulay.
| released              = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| discontinued          =
| latest release version =
| latest release date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| latest preview version =
| latest preview date    = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| installed version      =
| installed version date = <!-- {{Start date and age|YYYY|MM|DD|df=yes}} -->
| status                = -in development-
| status                = -in development-
| programming language  = C, C++, Python, Java, C#, MATLAB
| programming language  = C, C++, Python, Java, C#, MATLAB
| operating system      = Windows, Linux, MacOS, Android, iOS
| operating system      = Windows, Linux, MacOS, Android, iOS
| platform              =
| size                  =
| language              =
| genre                  = Data collection
| genre                  = Data collection
| license                = Open source
| license                = Open source
| website                = [https://labstreaminglayer.readthedocs.io/info/intro.html LSL webpage]
| website                = [https://labstreaminglayer.readthedocs.io/info/intro.html LSL webpage]
| resources              =  
}}
  {{Infobox tsg
 
    | child              = yes
=== Resources ===
    | downloads          =
{{Infobox tsg
    | manuals            = {{bulleted list
  | downloads          = {{bulleted list
        | [https://docs.unity3d.com/Manual/index.html Official Documentation]
      | {{Surfdrive|https://surfdrive.surf.nl/s/GLSnbBaYsbEWjPX|Viewer & Streamer}}
     }}
     }}
  | manuals            = {{bulleted list
      | [https://labstreaminglayer.readthedocs.io/ Documentation]
      | [https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html LSL Validation]
      | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
  }}
  | templates            = {{bulleted list
      | {{Surfdrive|https://surfdrive.surf.nl/s/gPenWNAqq8AXa7x|Example Scripts}}
   }}
   }}
}}
}}
Line 46: Line 39:


===Versions===
===Versions===
The TSG uses the version 1.15.0. Open a command to find your version used:
Pylsl version 1.16.2 is installed on our [[Lab Computer]]s. Open a command and type the following to find the version used:


<code style="background-color:#000; color:#fff; padding:1px 3px;">c:>python</code><br/>
<code style="background-color:#000; color:#fff; padding:1px 3px;">c:>python</code><br/>
Line 53: Line 46:


==Usage==
==Usage==
''(Under Construction)''<br/>
=== Python ===
We are working on templates and tips. Stay tuned!
Example demonstrating how to send LSL stream and marker data:
*[[Unity/Timing]]
<syntaxhighlight lang="python" line>
#!/usr/bin/env python3.10
# -*- coding: utf-8 -*-
 
import time
import random
import keyboard
from pylsl import StreamInfo, StreamOutlet
 
from pylsl import local_clock
 
# --- Setup Marker Stream ---
print("Setting up marker stream...")
marker_info = StreamInfo(
    name="MarkerStream",
    type="Markers",
    channel_count=1,
    nominal_srate=0,  # Irregular sampling
    channel_format="string",
    source_id="MarkerSource"
)
marker_outlet = StreamOutlet(marker_info, chunk_size=1)
 
# --- Setup Data Stream ---
print("Setting up data stream...")
data_info = StreamInfo(
    name="TestStream",
    type="TestData",
    channel_count=4,
    nominal_srate=100,
    channel_format="float32",
    source_id="TestStream_Source"
)
 
channels = data_info.desc().append_child("channels")
for name in ["A", "B", "C", "D"]:
    chan = channels.append_child("channel")
    chan.append_child_value("name", name)
    chan.append_child_value("unit", "unitless")
    chan.append_child_value("type", "TestData")
 
data_outlet = StreamOutlet(data_info, chunk_size=1)
 
# --- Start Streaming ---
print("Start streaming... Press 'q' to stop.")
marker_outlet.push_sample(["Start"])
 
while not keyboard.is_pressed('q'):
    random_numbers = [random.randint(1, 2) for _ in range(4)]
    data_outlet.push_sample(random_numbers)
    time.sleep(0.01)
 
marker_outlet.push_sample(["Stop"])
print("Streaming stopped.")
</syntaxhighlight>
 
=== Matlab ===
Please, read the instructions on the GitHub labstreaminglayer website (https://github.com/labstreaminglayer/liblsl-Matlab) on how to prepare Matlab to work with LSL. You can either use the latest release for your Matlab version, or if that doesn't workout well, build it from the source files. Make sure to add the liblsl-Matlab folder to your path recursively to make it available to your own scripts.
 
A short example for sending lsl streaming data:
<syntaxhighlight lang="matlab" line>
%% instantiate the library
disp('Loading library...');
lib = lsl_loadlib();
 
% make a new stream outlet
disp('Creating a new streaminfo...');
info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');
 
disp('Opening an outlet...');
outlet = lsl_outlet(info);
 
% send data into the outlet, sample by sample
disp('Now transmitting data...');
while true
    outlet.push_sample(randn(8,1));
    pause(0.01);
end
</syntaxhighlight>
 
A short example for receiving lsl streaming data:
<syntaxhighlight lang="matlab" line>
%% instantiate the library
disp('Loading the library...');
lib = lsl_loadlib();


===Builds===
% resolve a stream...
We advise not to run your experiment from the Unity Editor, this will cause unwanted overhead that harms the performance. You can create a PC Standalone build to run it on our [[Computers | lab computers]].
disp('Resolving an EEG stream...');
result = {};
while isempty(result)
    result = lsl_resolve_byprop(lib,'type','EEG'); end


==References==
% create a new inlet
<references />
disp('Opening an inlet...');
inlet = lsl_inlet(result{1});


==External Links== <!-- Optional -->
disp('Now receiving data...');
*{{Official website|https://unity3d.com}}
while true
*[https://docs.unity3d.com/Manual/index.html Official Documentation]
    % get data from the inlet
    [vec,ts] = inlet.pull_sample();
    % and display it
    fprintf('%.2f\t',vec);
    fprintf('%.5f\n',ts);
end</syntaxhighlight>

Latest revision as of 15:24, 11 August 2026

Lab Streaming Layer
Developer(s)Christian Kothe; Chadwick Boulay.
Development status-in development-
Written inC, C++, Python, Java, C#, MATLAB
Operating systemWindows, Linux, MacOS, Android, iOS
TypeData collection
LicenseOpen source
WebsiteLSL webpage

Resources

DataHub
Downloads
Manuals
Templates

The DataHub Makes use of the lab streaming layer. The lab streaming layer (LSL) is a system for the unified collection of measurement time series in research experiments that handles both the networking, time-synchronization, (near-) real-time access as well as optionally the centralized collection, viewing and disk recording of the data.


Installation

Our support for LSL is mainly done in python. Download python here: Please choose a 64 bit version.. Run the installer and make sure to add Python to the file path (it's an option in the installer). Open a command prompt, start with upgrading the pip installer by typing:
c:>python -m pip install --upgrade pip
Then:
c:>pip install pylsl

more info: cross platform pylsl

Versions

Pylsl version 1.16.2 is installed on our Lab Computers. Open a command and type the following to find the version used:

c:>python
>>> import pylsl
>>> print(pylsl.__version__)

Usage

Python

Example demonstrating how to send LSL stream and marker data:

#!/usr/bin/env python3.10
# -*- coding: utf-8 -*-

import time
import random
import keyboard
from pylsl import StreamInfo, StreamOutlet

from pylsl import local_clock

# --- Setup Marker Stream ---
print("Setting up marker stream...")
marker_info = StreamInfo(
    name="MarkerStream",
    type="Markers",
    channel_count=1,
    nominal_srate=0,  # Irregular sampling
    channel_format="string",
    source_id="MarkerSource"
)
marker_outlet = StreamOutlet(marker_info, chunk_size=1)

# --- Setup Data Stream ---
print("Setting up data stream...")
data_info = StreamInfo(
    name="TestStream",
    type="TestData",
    channel_count=4,
    nominal_srate=100,
    channel_format="float32",
    source_id="TestStream_Source"
)

channels = data_info.desc().append_child("channels")
for name in ["A", "B", "C", "D"]:
    chan = channels.append_child("channel")
    chan.append_child_value("name", name)
    chan.append_child_value("unit", "unitless")
    chan.append_child_value("type", "TestData")

data_outlet = StreamOutlet(data_info, chunk_size=1)

# --- Start Streaming ---
print("Start streaming... Press 'q' to stop.")
marker_outlet.push_sample(["Start"])

while not keyboard.is_pressed('q'):
    random_numbers = [random.randint(1, 2) for _ in range(4)]
    data_outlet.push_sample(random_numbers)
    time.sleep(0.01)

marker_outlet.push_sample(["Stop"])
print("Streaming stopped.")

Matlab

Please, read the instructions on the GitHub labstreaminglayer website (https://github.com/labstreaminglayer/liblsl-Matlab) on how to prepare Matlab to work with LSL. You can either use the latest release for your Matlab version, or if that doesn't workout well, build it from the source files. Make sure to add the liblsl-Matlab folder to your path recursively to make it available to your own scripts.

A short example for sending lsl streaming data:

%% instantiate the library
disp('Loading library...');
lib = lsl_loadlib();

% make a new stream outlet
disp('Creating a new streaminfo...');
info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');

disp('Opening an outlet...');
outlet = lsl_outlet(info);

% send data into the outlet, sample by sample
disp('Now transmitting data...');
while true
    outlet.push_sample(randn(8,1));
    pause(0.01);
end

A short example for receiving lsl streaming data:

%% instantiate the library
disp('Loading the library...');
lib = lsl_loadlib();

% resolve a stream...
disp('Resolving an EEG stream...');
result = {};
while isempty(result)
    result = lsl_resolve_byprop(lib,'type','EEG'); end

% create a new inlet
disp('Opening an inlet...');
inlet = lsl_inlet(result{1});

disp('Now receiving data...');
while true
    % get data from the inlet
    [vec,ts] = inlet.pull_sample();
    % and display it
    fprintf('%.2f\t',vec);
    fprintf('%.5f\n',ts);
end