meegsim.configuration.SourceConfiguration#

class meegsim.configuration.SourceConfiguration(src, sfreq, duration, random_state=None)[source]#

This class describes a simulated configuration of sources of brain activity and noise.

Attributes:
srcSourceSpaces

Source spaces object that stores all candidate source locations.

sfreqfloat

Sampling frequency of the simulated data, in Hz.

durationfloat

Length of the simulated data, in seconds.

random_stateint or None, optional

Random state that was used to generate the configuration.

Methods

plot(subject[, hemi, colors, scale_factors, ...])

Plot the source configuration.

to_raw(fwd, info[, sensor_noise_level])

Project the activity of all simulated sources to sensor space.

to_stc()

Obtain an stc object that contains data from all sources in the configuration.

__getitem__(name)[source]#

This function provides quick access to the simulated sources. The syntax is similar to list/dict access: sc[name] returns the corresponding source if it is present in the configuration.

Parameters:
namestr

Name of the source.

Returns:
sourcePointSource or PatchSource

The corresponding source.

Raises:
ValueError

In case there is no source with the provided name.

plot(subject, hemi='lh', colors=None, scale_factors=None, show_noise_sources=True, show_candidate_locations=False, **plot_kwargs)[source]#

Plot the source configuration. This function is built on top of mne.SourceEstimate.plot(), and the meaning of all parameters is kept the same unless mentioned.

Parameters:
subjectstr

The name of the subject.

hemistr

The hemisphere to plot. The values “both” and “split” are also supported.

colorsdict or None, optional

This dictionary can be used to override the default color palette, which is described in the Notes section below.

scale_factorsdict or None, optional

This dictionary can be used to override the default display size for sources of different types. See Notes for the default values.

show_noise_sourcesbool, optional

Controls whether noise sources should be displayed (True by default).

show_candidate_locationsbool, optional

Controls whether candidate source locations (all vertices present in the source space) should be displayed (False by default).

**kwargs: dict, optional

Additional parameters that should be passed to mne.SourceEstimate.plot().

Warning

Plotting all candidate locations might require lots of resources depending on the size of the source space.

Returns:
figuremne.viz.Brain or matplotlib.figure.Figure

The resulting figure.

Notes

The following parameters are used for plotting by default:

DEFAULT_COLORS = dict(
    point="green",
    patch="Oranges",
    noise="black",
    candidate="yellow"
)

DEFAULT_SCALE_FACTORS = dict(
    point=0.75,
    noise=0.3,
    candidate=0.05
)

DEFAULT_PLOT_KWARGS = dict(
    background="w",
    cortex="low_contrast",
    colorbar=False,
    clim=dict(kind="value", lims=[0, 0.5, 1]),
    transparent=True,
)
to_raw(fwd, info, sensor_noise_level=None)[source]#

Project the activity of all simulated sources to sensor space.

Parameters:
fwdForward

The forward model.

infoInfo

The info structure that describes the channel layout.

sensor_noise_levelfloat, optional

The desired level of sensor-space noise between 0 and 1. For example, if 0.1 is specified, 10% of total sensor-space power will stem from white noise with an identity covariance matrix, while the remaining 90% of power will be explained by source activity projected to sensor space. By default, no sensor space noise is added. See Notes for more details.

Returns:
rawRaw

The simulated sensor space data.

Notes

The adjustment of sensor space noise is performed as follows:

1. The sensor space noise is scaled to equalize the mean sensor-space variance of broadband noise and brain activity.

2. The brain activity and noise are mixed to achieve the desired level of sensor space noise (denoted by \(\gamma\) below):

\[y = \sqrt{1 - \gamma} \cdot y_{brain} + \sqrt{\gamma} \cdot y_{noise}\]

If the sensor noise is independent from projected brain activity, the following relationship will hold for the total sensor space power:

\[P_{total} = (1 - \gamma) \cdot P_{brain} + \gamma \cdot P_{noise}\]
to_stc()[source]#

Obtain an stc object that contains data from all sources in the configuration.

Returns:
stcSourceEstimate

The resulting stc object that contains data from all sources.

Examples using meegsim.configuration.SourceConfiguration#

Using functions from other packages

Using functions from other packages

Minimal example

Minimal example

Random state and reproducibility

Random state and reproducibility

Plotting the configuration

Plotting the configuration

Adjustment of global SNR

Adjustment of global SNR

Adjustment of local SNR

Adjustment of local SNR

Adding sensor space noise

Adding sensor space noise