pub struct EegData {
pub channel_labels: Vec<String>,
pub data: Vec<Vec<f64>>,
pub sampling_rates: Vec<f64>,
pub duration: f64,
pub annotations: Vec<Annotation>,
pub stim_channel_indices: Vec<usize>,
pub is_discontinuous: bool,
pub record_onsets: Vec<f64>,
}Expand description
Raw EEG signal data read from a data file.
Stores multichannel time-series data as a channel × samples matrix,
where each inner Vec<f64> represents one channel’s signal in physical units.
Also carries annotations parsed from the file (EDF+ TAL, BDF+ status, or
BrainVision markers).
Fields§
§channel_labels: Vec<String>Channel labels in order.
data: Vec<Vec<f64>>Signal data: one Vec<f64> per channel, all in physical units (e.g., µV).
sampling_rates: Vec<f64>Sampling rate per channel in Hz.
duration: f64Total duration in seconds.
annotations: Vec<Annotation>Annotations parsed from the data file (EDF+ TAL, BDF+ status, .vmrk markers).
stim_channel_indices: Vec<usize>Indices of channels detected as stimulus/trigger channels.
is_discontinuous: boolWhether this recording is from an EDF+D/BDF+D discontinuous file.
If true, there may be gaps in the time axis — use record_onsets
to reconstruct the true timeline.
record_onsets: Vec<f64>Actual onset time of each data record in seconds (from EDF+ TAL).
For continuous recordings this is empty or [0, dur, 2*dur, ...].
For discontinuous (EDF+D), these give the real timestamps of each record,
which may have gaps.
Implementations§
Source§impl EegData
impl EegData
Sourcepub fn n_channels(&self) -> usize
pub fn n_channels(&self) -> usize
Number of channels.
Sourcepub fn n_samples(&self, channel: usize) -> usize
pub fn n_samples(&self, channel: usize) -> usize
Number of samples for the given channel index.
Sourcepub fn channel_by_name(&self, name: &str) -> Option<&[f64]>
pub fn channel_by_name(&self, name: &str) -> Option<&[f64]>
Get a single channel’s data by label.
Sourcepub fn times(&self, channel: usize) -> Option<Vec<f64>>
pub fn times(&self, channel: usize) -> Option<Vec<f64>>
Generate a times array in seconds for the given channel (like MNE’s raw.times).
Returns one f64 per sample: [0.0, 1/sr, 2/sr, ...].
Sourcepub fn get_data_with_times(&self) -> (Vec<Vec<f64>>, Vec<f64>)
pub fn get_data_with_times(&self) -> (Vec<Vec<f64>>, Vec<f64>)
Get the data together with the times array (like MNE’s get_data(return_times=True)).
Sourcepub fn select_channels(&self, names: &[&str]) -> EegData
pub fn select_channels(&self, names: &[&str]) -> EegData
Select a subset of channels by name (include), returning a new EegData.
Sourcepub fn exclude_channels(&self, names: &[&str]) -> EegData
pub fn exclude_channels(&self, names: &[&str]) -> EegData
Exclude channels by name, returning a new EegData with all other channels.
Sourcepub fn time_slice(&self, start_sec: f64, end_sec: f64) -> EegData
pub fn time_slice(&self, start_sec: f64, end_sec: f64) -> EegData
Extract a time window (in seconds) from all channels.
Sourcepub fn convert_units(&mut self, unit_map: &HashMap<String, f64>)
pub fn convert_units(&mut self, unit_map: &HashMap<String, f64>)
Convert channel data to different units by applying a scale factor.
unit_map maps channel name → scale factor. For example, to convert
from µV to V: {"EEG1": 1e-6}.
Sourcepub fn pick_types(
&self,
types: &[ChannelType],
channel_types: &[ChannelType],
) -> EegData
pub fn pick_types( &self, types: &[ChannelType], channel_types: &[ChannelType], ) -> EegData
Select channels by type (like MNE’s pick_types).
types should be a list of ChannelType variants to keep. Requires
that channel_types is available (from channels.tsv).
Sourcepub fn concatenate(&mut self, other: &EegData) -> Result<(), String>
pub fn concatenate(&mut self, other: &EegData) -> Result<(), String>
Concatenate another EegData in time (appending samples).
Both must have the same channels in the same order. Annotations from
other are time-shifted by self.duration.
Sourcepub fn reject_by_annotation(&self, pattern: &str) -> EegData
pub fn reject_by_annotation(&self, pattern: &str) -> EegData
Remove (zero-out) data segments that overlap with annotations matching
a description pattern (like MNE’s reject_by_annotation).
Returns a new EegData where samples overlapping “BAD” annotations
(or annotations matching pattern) are replaced with f64::NAN.
Source§impl EegData
impl EegData
Sourcepub fn filter(
&self,
l_freq: Option<f64>,
h_freq: Option<f64>,
order: usize,
) -> EegData
pub fn filter( &self, l_freq: Option<f64>, h_freq: Option<f64>, order: usize, ) -> EegData
Apply a bandpass filter to all channels (like MNE’s raw.filter(l_freq, h_freq)).
Uses a Butterworth IIR filter with zero-phase filtfilt application.
l_freq and h_freq are in Hz. If l_freq is None, applies lowpass only.
If h_freq is None, applies highpass only.
Sourcepub fn notch_filter(&self, freq: f64, quality: f64) -> EegData
pub fn notch_filter(&self, freq: f64, quality: f64) -> EegData
Remove power line noise at freq Hz and its harmonics (like MNE’s raw.notch_filter()).
Sourcepub fn resample(&self, new_sr: f64) -> EegData
pub fn resample(&self, new_sr: f64) -> EegData
Resample all channels to a new sampling rate (like MNE’s raw.resample()).
Applies an anti-aliasing lowpass filter before downsampling.
Sourcepub fn set_average_reference(&self) -> EegData
pub fn set_average_reference(&self) -> EegData
Re-reference to the average of all channels (like MNE’s raw.set_eeg_reference('average')).
Subtracts the mean across channels at each time point.
Sourcepub fn set_reference(&self, ref_channel: &str) -> EegData
pub fn set_reference(&self, ref_channel: &str) -> EegData
Re-reference to a specific channel (like MNE’s raw.set_eeg_reference([ch_name])).
Sourcepub fn epoch(
&self,
tmin: f64,
tmax: f64,
event_desc: Option<&str>,
) -> Vec<EegData>
pub fn epoch( &self, tmin: f64, tmax: f64, event_desc: Option<&str>, ) -> Vec<EegData>
Extract epochs around events (like MNE’s mne.Epochs(raw, events, tmin, tmax)).
Returns a Vec of EegData, one per event matching event_desc.
tmin and tmax are relative to event onset in seconds.
If event_desc is None, epochs around all annotations.
Sourcepub fn average_epochs(epochs: &[EegData]) -> Option<EegData>
pub fn average_epochs(epochs: &[EegData]) -> Option<EegData>
Average a list of epochs to compute an ERP (Event-Related Potential).
All epochs must have the same shape. Like MNE’s epochs.average().
Sourcepub fn compute_psd(&self, n_fft: Option<usize>) -> (Vec<f64>, Vec<Vec<f64>>)
pub fn compute_psd(&self, n_fft: Option<usize>) -> (Vec<f64>, Vec<Vec<f64>>)
Compute power spectral density using Welch’s method (like MNE’s raw.compute_psd()).
Returns (frequencies, psd) where psd[ch] is the power spectrum for each channel.
n_fft is the FFT window size (default: sampling rate = 1 Hz resolution).
Trait Implementations§
Source§impl TimeSeries for EegData
impl TimeSeries for EegData
Source§fn n_channels(&self) -> usize
fn n_channels(&self) -> usize
Source§fn n_samples(&self) -> usize
fn n_samples(&self) -> usize
Source§fn channel_names(&self) -> &[String]
fn channel_names(&self) -> &[String]
Source§fn sampling_rate(&self) -> f64
fn sampling_rate(&self) -> f64
Source§fn channel_means(&self) -> Vec<f64>
fn channel_means(&self) -> Vec<f64>
Source§fn channel_stds_with_means(&self, means: &[f64]) -> Vec<f64>
fn channel_stds_with_means(&self, means: &[f64]) -> Vec<f64>
Source§fn channel_stds(&self) -> Vec<f64>
fn channel_stds(&self) -> Vec<f64>
Source§fn z_score(&self) -> Vec<Vec<f64>>
fn z_score(&self) -> Vec<Vec<f64>>
Vec<Vec<f64>>.Source§fn window(&self, start_sec: f64, end_sec: f64) -> Vec<Vec<f64>>
fn window(&self, start_sec: f64, end_sec: f64) -> Vec<Vec<f64>>
Vec<Vec<f64>>. Read moreSource§fn epochs(&self, window_sec: f64) -> Vec<Vec<Vec<f64>>>
fn epochs(&self, window_sec: f64) -> Vec<Vec<Vec<f64>>>
Source§fn epochs_with_stride(
&self,
window_sec: f64,
stride_sec: f64,
) -> Vec<Vec<Vec<f64>>>
fn epochs_with_stride( &self, window_sec: f64, stride_sec: f64, ) -> Vec<Vec<Vec<f64>>>
Source§fn to_flat_vec(&self) -> Vec<f64>
fn to_flat_vec(&self) -> Vec<f64>
Vec<f64> (row-major). Read moreSource§fn to_column_major(&self) -> Vec<f64>
fn to_column_major(&self) -> Vec<f64>
Vec<f64> in column-major order (samples × channels). Read moreSource§fn shape(&self) -> (usize, usize)
fn shape(&self) -> (usize, usize)
Source§fn log_variance(&self) -> Vec<f64>
fn log_variance(&self) -> Vec<f64>
Source§fn band_power(&self) -> Vec<f64>
fn band_power(&self) -> Vec<f64>
Source§fn peak_to_peak(&self) -> Vec<f64>
fn peak_to_peak(&self) -> Vec<f64>
max - min.