mne_rt.tools.simulate_raw#
- mne_rt.tools.simulate_raw(brain_label: str, frequency: float, amplitude: float, duration: float, gap_duration: float, n_repetition: int, start: float, data_type: str = 'eeg', sfreq: float = 256.0, n_eeg_channels: int = 64, iir_filter: list = [0.2, -0.2, 0.04], add_eog_artifacts: bool = True, fname_save: str | Path | None = None, verbose: bool | str | None = None) RawArray[source]#
Generate a synthetic EEG or MEG recording with a sinusoidal source.
A forward solution is created for the
fsaveragetemplate brain and a sinusoidal dipole is injected into the specified cortical label. The signal is projected to sensor space, optionally repeated with inter-epoch gaps, sensor noise is added, and the result is returned (and optionally saved) as anmne.io.RawArray.- Parameters:
- brain_label
str Regexp matching a cortical label in the fsaverage parcellation (e.g.
"bankssts-lh"for alpha,"precentral-lh"for motor).- frequency
float Frequency of the simulated sine wave (Hz).
- amplitude
float Amplitude scaling factor. Multiplied by
10e-9for EEG or1e-12for MEG; pass1.0for a standard physiological signal.- duration
float Duration of each signal epoch (seconds).
- gap_duration
float Silence gap between consecutive epochs (seconds).
- n_repetition
int Number of epochs to simulate.
- start
float Start time of the first epoch (seconds from recording start).
- data_type{“eeg”, “meg”}, default “eeg”
Sensor modality to simulate.
"meg"creates a magnetometer (gradiometer-free) sensor layout using theVectorview-alltemplate.- sfreq
float, default 256.0 Sampling frequency (Hz). Used only when
data_type="eeg"to build the synthetic sensor layout.- n_eeg_channels
int, default 64 Number of EEG channels. Must be one of the standard MNE montage channel counts (32, 64, 128, or 256 channels of
biosemi*/easycap*montages). Ignored whendata_type="meg".- iir_filterarray_like, default [0.2, -0.2, 0.04]
IIR denominator coefficients passed to
mne.simulation.add_noise().- add_eog_artifactsbool, default
True If
True, add simulated EOG blink artefacts.- fname_save
str|Path|None, defaultNone Path to write the output
.fiffile. IfNone, the file is saved todata/simulated/<label>_<freq>Hz_<data_type>-raw.fifrelative to the repository root (or current working directory).- verbosebool |
str|int|None, defaultNone MNE verbosity level.
- brain_label
- Returns:
- raw
mne.io.Raw The simulated raw recording.
- raw
- Raises:
ValueErrorIf
data_typeis not"eeg"or"meg".
Notes
The function requires the MNE
fsaveragedataset which is downloaded automatically on first call viamne.datasets.fetch_fsaverage().For MEG, a Vectorview-all info template is used (magnetometers + planar gradiometers). For EEG, a
biosemi64(orbiosemi32/biosemi128for other channel counts) standard layout is created programmatically.Examples
Simulate alpha-band EEG in the left parieto-occipital region:
from mne_rt.tools.simulation import simulate_raw raw = simulate_raw( brain_label="bankssts-lh", frequency=10.0, amplitude=1.0, duration=2.0, gap_duration=1.0, n_repetition=5, start=0.0, data_type="eeg", )
Simulate beta-band MEG over left motor cortex:
raw = simulate_raw( brain_label="precentral-lh", frequency=20.0, amplitude=1.0, duration=2.0, gap_duration=1.0, n_repetition=5, start=0.0, data_type="meg", )