Difference between revisions of "DataHub"

From TSG Doc
Jump to navigation Jump to search
 
(20 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{Infobox software
 
{{Infobox software
 
| name                  = DataHub
 
| name                  = DataHub
| 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          = {{bulleted list
+
{{Infobox tsg
        | [https://docs.openbci.com/ Documentation]
+
  | downloads          = {{bulleted list
 +
      | [https://surfdrive.surf.nl/files/index.php/s/zSpGD53mDQGuPKW viewer & streamer]
 
     }}
 
     }}
    | manuals            = {{bulleted list
+
  | manuals            = {{bulleted list
        | [https://docs.openbci.com/ Documentation]
+
      | [https://labstreaminglayer.readthedocs.io/ Documentation]
    }}
+
      | [https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html LSL Validation]
    | header2            = Templates
+
      | [https://labstreaminglayer.readthedocs.io/info/supported_devices.html Supported Devices and Tools]
    | data2              = *[https://surfdrive.surf.nl/files/index.php/s/LN5KRN9cB3mvPp3 Template 2017 (zip)]]
+
  }}
 +
  | templates            = {{bulleted list
 +
      | [https://surfdrive.surf.nl/files/index.php/s/qggfMMKsnUIDO0k example scripts (zip)]
 
   }}
 
   }}
 
}}
 
}}
Line 58: Line 47:
 
==Usage==
 
==Usage==
 
=== Python ===
 
=== Python ===
A short example for sending lsl streaming data:
+
Example demonstrating how to send LSL stream and marker data:
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
#!/usr/bin/env python
+
#!/usr/bin/env python3.10
 +
# -*- coding: utf-8 -*-
  
import threading
+
import time
 +
import random
 +
import keyboard
 
from pylsl import StreamInfo, StreamOutlet
 
from pylsl import StreamInfo, StreamOutlet
  
def getData():
+
from pylsl import local_clock
     while running:
+
 
        buffer_in = getSensorData()
+
# --- Setup Marker Stream ---
        send_data = True
+
print("Setting up marker stream...")
        time.sleep(0.001)
+
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"
 +
)
  
info = StreamInfo(
+
channels = data_info.desc().append_child("channels")
    name='MyStream',  
+
for name in ["A", "B", "C", "D"]:
     type='COP',
+
     chan = channels.append_child("channel")
     channel_count=4,  
+
     chan.append_child_value("name", name)
     nominal_srate = 200,  
+
     chan.append_child_value("unit", "unitless")
     source_id='BalanceBoard_stream'
+
     chan.append_child_value("type", "TestData")
    )
 
outlet = StreamOutlet(info)  
 
  
threading.Thread(target=getData).start()
+
data_outlet = StreamOutlet(data_info, chunk_size=1)
while running == True:
+
 
if send_data:
+
# --- Start Streaming ---
outlet.push_chunk(buffer_in)
+
print("Start streaming... Press 'q' to stop.")
send_data = False
+
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>
 
</syntaxhighlight>
  
A short example for receiving lsl data:
+
=== Matlab ===
<syntaxhighlight lang="python" line>
+
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.
#!/usr/bin/env python
+
 
 +
A short example for sending lsl streaming data:
 +
<syntaxhighlight lang="matlab" line>
 +
%% instantiate the library
 +
disp('Loading library...');
 +
lib = lsl_loadlib();
  
from pylsl import StreamInlet, resolve_stream
+
% make a new stream outlet
 +
disp('Creating a new streaminfo...');
 +
info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');
  
streams = resolve_stream('name', 'MyStream')
+
disp('Opening an outlet...');
#streams = resolve_streams()
+
outlet = lsl_outlet(info);
  
inlet = StreamInlet(streams[0])
+
% send data into the outlet, sample by sample
while True:
+
disp('Now transmitting data...');
     sample, timestamp = inlet.pull_sample()
+
while true
     print(timestamp, sample)
+
     outlet.push_sample(randn(8,1));
 +
     pause(0.01);
 +
end
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==References==  
+
A short example for receiving lsl streaming data:
<references />
+
<syntaxhighlight lang="matlab" line>
 +
%% 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});
  
==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 11:24, 28 April 2025

DataHub
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

The TSG uses the version 1.15.0. 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:

 1#!/usr/bin/env python3.10
 2# -*- coding: utf-8 -*-
 3
 4import time
 5import random
 6import keyboard
 7from pylsl import StreamInfo, StreamOutlet
 8
 9from pylsl import local_clock
10
11# --- Setup Marker Stream ---
12print("Setting up marker stream...")
13marker_info = StreamInfo(
14    name="MarkerStream",
15    type="Markers",
16    channel_count=1,
17    nominal_srate=0,  # Irregular sampling
18    channel_format="string",
19    source_id="MarkerSource"
20)
21marker_outlet = StreamOutlet(marker_info, chunk_size=1)
22
23# --- Setup Data Stream ---
24print("Setting up data stream...")
25data_info = StreamInfo(
26    name="TestStream",
27    type="TestData",
28    channel_count=4,
29    nominal_srate=100,
30    channel_format="float32",
31    source_id="TestStream_Source"
32)
33
34channels = data_info.desc().append_child("channels")
35for name in ["A", "B", "C", "D"]:
36    chan = channels.append_child("channel")
37    chan.append_child_value("name", name)
38    chan.append_child_value("unit", "unitless")
39    chan.append_child_value("type", "TestData")
40
41data_outlet = StreamOutlet(data_info, chunk_size=1)
42
43# --- Start Streaming ---
44print("Start streaming... Press 'q' to stop.")
45marker_outlet.push_sample(["Start"])
46
47while not keyboard.is_pressed('q'):
48    random_numbers = [random.randint(1, 2) for _ in range(4)]
49    data_outlet.push_sample(random_numbers)
50    time.sleep(0.01)
51
52marker_outlet.push_sample(["Stop"])
53print("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:

 1%% instantiate the library
 2disp('Loading library...');
 3lib = lsl_loadlib();
 4
 5% make a new stream outlet
 6disp('Creating a new streaminfo...');
 7info = lsl_streaminfo(lib,'BioSemi','EEG',8,100,'cf_float32','sdfwerr32432');
 8
 9disp('Opening an outlet...');
10outlet = lsl_outlet(info);
11
12% send data into the outlet, sample by sample
13disp('Now transmitting data...');
14while true
15    outlet.push_sample(randn(8,1));
16    pause(0.01);
17end

A short example for receiving lsl streaming data:

 1%% instantiate the library
 2disp('Loading the library...');
 3lib = lsl_loadlib();
 4
 5% resolve a stream...
 6disp('Resolving an EEG stream...');
 7result = {};
 8while isempty(result)
 9    result = lsl_resolve_byprop(lib,'type','EEG'); end
10
11% create a new inlet
12disp('Opening an inlet...');
13inlet = lsl_inlet(result{1});
14
15disp('Now receiving data...');
16while true
17    % get data from the inlet
18    [vec,ts] = inlet.pull_sample();
19    % and display it
20    fprintf('%.2f\t',vec);
21    fprintf('%.5f\n',ts);
22end