Simulating the M/EEG data#

Obtaining the data#

Up to this point, we defined a bunch of sources and set up several coupling edges. However, no data was generated yet, and it’s time to fix that now.

First, you need to run the SourceSimulator.simulate() method of the sim object to actually simulate the waveforms of all previously defined sources:

sfreq = 250     # in Hz
duration = 30   # in seconds
sc = sim.simulate(sfreq, duration)

The result of this function call is a SourceConfiguration object that contains all simulated sources and their waveforms (with desired SNR and coupling).

Now you can use the SourceConfiguration.to_stc() and SourceConfiguration.to_raw() to obtain source time courses and sensor-space data, respectively. The projection to sensor space requires a forward model (mne.Forward) and an mne.Info object describing the sensor layout:

stc = sc.to_stc()

raw = sc.to_raw(fwd, info)

Reproducibility#

By design, the result of SourceSimulator.simulate() will differ every time you call the method, making it very easy to simulate multiple datasets under the same settings.

However, it is always possible to obtain a reproducible result if you provide a specific value of the random_state as shown below:

sc = sim.simulate(sfreq, duration, random_state=123)

The resulting source configuration, including the locations and waveforms of all sources, will be the same on every call.