Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions ShimmerLSL/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Introduction

The following shows how to use Lab Streaming Layer support on Consensys, in this example Lab Recorder is used to record the LSL stream, and a python script (_which is included here_) is used to convert the recorded xdf file into csv format.

# Consensys

First enable Lab Streaming Layer
![enable_LSL](https://github.com/user-attachments/assets/6c4c4a9f-7854-43f3-9845-e9783f129ded)
Next connect to the Shimmer device and start streaming as shown below
![2024-10-18_10h43_30](https://github.com/user-attachments/assets/c0c9de67-b885-4d84-bd60-4ed572288717)

# Lab Recorder

Select the Shimmer device you want to record and click Start, this will start recording the Shimmer device data to an xdf file.
_Should you not see the Shimmer device which is streaming in Consensys you can try clicking update_
![2024-10-18_10h43_56](https://github.com/user-attachments/assets/3c4f39e8-79d1-46bf-8703-98fd64f5e0e4)

# Python Script

Remember to update the file name and path below
![image](https://github.com/user-attachments/assets/efa92b1f-0957-4fd8-b7c3-837a06d24b39)
36 changes: 36 additions & 0 deletions ShimmerLSL/python/converttocsv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pyxdf
import pandas as pd

# Step 1: Load the XDF file
xdf_file_path = 'C:\\Users\\XX\\Documents\\CurrentStudy\\sub-P001\\ses-S001\\eeg\\sub-P001_ses-S001_task-Default_run-001_eeg.xdf'
streams, header = pyxdf.load_xdf(xdf_file_path)


# Iterate through the streams and save each as a CSV
for idx, stream in enumerate(streams):
# Extract data and timestamps
data = stream['time_series']
timestamps = stream['time_stamps']

# Attempt to retrieve channel names, fallback to generic names if not available
try:
channels = [ch['label'][0] for ch in stream['info']['desc'][0]['channels'][0]['channel']]
except (KeyError, TypeError, IndexError):
channels = [f'channel_{i}' for i in range(data.shape[1])]

# Retrieve the stream name
try:
stream_name = stream['info']['name'][0]
except (KeyError, TypeError, IndexError):
stream_name = f'stream_{idx+1}'

# Create a DataFrame
print(channels)
print(data)
df = pd.DataFrame(data, columns=channels)
df['time_stamps'] = timestamps

# Save DataFrame to CSV using the stream name
csv_file_path = f'{stream_name}.csv'
df.to_csv(csv_file_path, index=False)
print(f"Stream {idx+1} saved to {csv_file_path}")