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:
- src
SourceSpaces Source spaces object that stores all candidate source locations.
- sfreq
float Sampling frequency of the simulated data, in Hz.
- duration
float Length of the simulated data, in seconds.
- random_state
intorNone, optional Random state that was used to generate the configuration.
- src
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
stcobject 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:
- name
str Name of the source.
- name
- Returns:
- source
PointSourceorPatchSource The corresponding source.
- source
- Raises:
ValueErrorIn 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:
- subject
str The name of the subject.
- hemi
str The hemisphere to plot. The values “both” and “split” are also supported.
- colors
dictorNone, optional This dictionary can be used to override the default color palette, which is described in the Notes section below.
- scale_factors
dictorNone, 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.
- subject
- Returns:
- figure
mne.viz.Brainormatplotlib.figure.Figure The resulting figure.
- 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:
- fwd
Forward The forward model.
- info
Info The info structure that describes the channel layout.
- sensor_noise_level
float, 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.
- fwd
- Returns:
- raw
Raw The simulated sensor space data.
- raw
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
stcobject that contains data from all sources in the configuration.- Returns:
- stc
SourceEstimate The resulting stc object that contains data from all sources.
- stc