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 fsaverage template 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 an mne.io.RawArray.

Parameters:
brain_labelstr

Regexp matching a cortical label in the fsaverage parcellation (e.g. "bankssts-lh" for alpha, "precentral-lh" for motor).

frequencyfloat

Frequency of the simulated sine wave (Hz).

amplitudefloat

Amplitude scaling factor. Multiplied by 10e-9 for EEG or 1e-12 for MEG; pass 1.0 for a standard physiological signal.

durationfloat

Duration of each signal epoch (seconds).

gap_durationfloat

Silence gap between consecutive epochs (seconds).

n_repetitionint

Number of epochs to simulate.

startfloat

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 the Vectorview-all template.

sfreqfloat, default 256.0

Sampling frequency (Hz). Used only when data_type="eeg" to build the synthetic sensor layout.

n_eeg_channelsint, 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 when data_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_savestr | Path | None, default None

Path to write the output .fif file. If None, the file is saved to data/simulated/<label>_<freq>Hz_<data_type>-raw.fif relative to the repository root (or current working directory).

verbosebool | str | int | None, default None

MNE verbosity level.

Returns:
rawmne.io.Raw

The simulated raw recording.

Raises:
ValueError

If data_type is not "eeg" or "meg".

Notes

The function requires the MNE fsaverage dataset which is downloaded automatically on first call via mne.datasets.fetch_fsaverage().

For MEG, a Vectorview-all info template is used (magnetometers + planar gradiometers). For EEG, a biosemi64 (or biosemi32/biosemi128 for 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",
)