TheusHen 52c98dcdfa Add EEG processing and visualization components
- Implemented mne_tools.py for converting sample records to MNE Raw format.
- Created models.py to define data structures for sample, event, and error packets.
- Developed pyqt_focus.py for a PyQt-based focus monitoring GUI with real-time EEG data visualization.
- Added 
eflex_bridge.py to manage the EEG engine instance.
- Introduced simulator.py to simulate EEG data packets for testing purposes.
- Established a web dashboard in pendulum_web.py for live EEG data display and diagnostics.
- Configured project dependencies in pyproject.toml and 
equirements.txt.
- Added batch and PowerShell scripts for running and stopping the Reflex application.
- Created 
xconfig.py for Reflex application configuration.
2026-02-28 17:56:04 -03:00

32 lines
794 B
Python

from __future__ import annotations
from typing import Sequence
import mne
import numpy as np
from .models import SampleRecord
def samples_to_mne_raw(
samples: Sequence[SampleRecord],
sample_rate_hz: float,
channel_names: Sequence[str] = ("EEG1", "EEG2", "EEG3", "EEG4"),
) -> mne.io.BaseRaw:
if len(samples) == 0:
raise ValueError("No samples available to convert to MNE Raw.")
data_uv = np.array(
[[s.ch1_uv, s.ch2_uv, s.ch3_uv, s.ch4_uv] for s in samples],
dtype=np.float64,
)
data_v = (data_uv.T) * 1e-6
info = mne.create_info(
ch_names=list(channel_names),
sfreq=float(sample_rate_hz),
ch_types=["eeg"] * len(channel_names),
)
raw = mne.io.RawArray(data_v, info, verbose="ERROR")
return raw