mne_rt.SourceModel#
- class mne_rt.SourceModel(*, src, atlas: str, subject: str = 'fsaverage', subjects_dir=None, filters=None, inverse=None, inverse_method: str = 'dSPM', info=None, lambda2: float = 0.1111111111111111, pick_ori: str | None = 'normal')[source]#
Bases:
objectSensor data → ROI time courses, via one cached linear operator.
- Parameters:
- src
instanceofSourceSpaces The source space the inverse/beamformer was built on. Needed to map atlas labels onto source-estimate rows.
- atlas
str Volumetric atlas stem (
"aparc+aseg") or surface annotation name ("aparc").- subject
str FreeSurfer subject identifier.
- subjects_dirpath-like |
None FreeSurfer subjects directory.
- filters
instanceofBeamformer|None Fitted LCMV spatial filter. Required for the fast kernel path.
- inverse
instanceofInverseOperator|None Minimum-norm inverse operator.
- inverse_method
str Minimum-norm method:
"MNE","dSPM","sLORETA"or"eLORETA".- info
instanceofInfo|None Measurement info, required to build a cached kernel for the minimum-norm path (see
source_operator()).- lambda2
float Regularisation for the minimum-norm inverse.
- pick_ori
str|None Source orientation.
"normal"on a surface source space keeps the solution linear;Noneon a volume source space yields a magnitude, which is not linear (see Notes).
- src
Notes
Both supported inverses are linear in the sensor data as long as the orientation is fixed, which is what makes the cached kernel exact:
LCMV with
pick_ori="max-power"reduces toweights @ whitener.A minimum-norm operator with
pick_ori="normal"is recovered by pushing an identity “recording” throughapply_inverse_raw()— the result is the operator matrix, using only public API.
Free-orientation solutions (LCMV with
pick_ori=None/"vector", or a minimum-norm estimate on a volume source space) combine three orientations by norm. That is non-linear and discards phase, which would make imaginary coherence meaningless, so those configurations reportsupports_kernel = Falseand refuse the kernel rather than silently returning a plausible-looking number.- __init__(*, src, atlas: str, subject: str = 'fsaverage', subjects_dir=None, filters=None, inverse=None, inverse_method: str = 'dSPM', info=None, lambda2: float = 0.1111111111111111, pick_ori: str | None = 'normal') None[source]#
Methods
__init__(*, src, atlas[, subject, ...])apply(data, *[, kernel, ch_picks, ...])Return ROI time courses
(n_roi, n_times)for one data window.channel_picks(ch_names)Row indices selecting/reordering
ch_namesinto operator order.from_stream(rt, *[, atlas, method, reg, ...])Build a
SourceModelfrom a session that has recorded a baseline.label_operator(rois, *[, mri_resolution])Sparse-average matrix mapping source points to ROIs, shape
(n_roi, n_src).roi_kernel(rois, *[, mri_resolution])The full sensor → ROI operator, shape
(n_roi, n_channels).source_estimate(data, *[, info, pick_ori])Source time courses
(n_src, n_times)via the full MNE route.Linear map from sensor data to source time courses, shape
(n_src, n_ch).Attributes
Channels the operator expects, in the order its columns are in.
"volume"or"surface", taken from the source space.Whether the fast cached-kernel path is available.
- property channel_names: list#
Channels the operator expects, in the order its columns are in.
This is not necessarily the recording’s channel list: building a forward model drops EEG channels with no digitised position, and
make_lcmv/make_inverse_operatoradditionally dropinfo["bads"].apply_lcmv_raw()handles this internally by selecting channels from the data; the cached-kernel path must do the same, or a single bad channel makes everykernel @ datafail on a shape mismatch — and a same-count reordering would silently produce wrong ROI time courses.
- channel_picks(ch_names: Sequence[str]) ndarray[source]#
Row indices selecting/reordering
ch_namesinto operator order.
- property supports_kernel: bool#
Whether the fast cached-kernel path is available.
True when the source estimate is a linear function of the sensor data: an LCMV beamformer with a fixed orientation, or a minimum-norm operator with
pick_ori="normal". Free-orientation solutions combine three orientations by norm and are excluded.
- source_operator() ndarray[source]#
Linear map from sensor data to source time courses, shape
(n_src, n_ch).For LCMV this mirrors what
apply_lcmv_raw()does internally: whiten (or project) the data, then apply the beamformer weights.For a minimum-norm operator it recovers the same matrix by pushing an identity “recording” through
apply_inverse_raw()— the columns of the result are the response to a unit signal on each channel, i.e. the operator itself. This uses only public API and is exact for"MNE"and to floating-point for the noise-normalised methods.
- label_operator(rois: Sequence[ROI], *, mri_resolution: bool = True) ndarray[source]#
Sparse-average matrix mapping source points to ROIs, shape
(n_roi, n_src).Equivalent to
extract_label_time_course()withmode="mean"(volume) or"mean_flip"(surface), but built once rather than recomputed every window.
- roi_kernel(rois: Sequence[ROI], *, mri_resolution: bool = True) ndarray[source]#
The full sensor → ROI operator, shape
(n_roi, n_channels).Apply it to a data window with
apply(), or simplykernel @ data.
- apply(data: ndarray, *, kernel=None, ch_picks=None, label_operator=None, info=None, pick_ori: str | None = None) ndarray[source]#
Return ROI time courses
(n_roi, n_times)for one data window.Uses
kernelwhen given — one matmul, and the whole point of this class. Otherwise applies the source estimate the slow way and reduces it withlabel_operator; correct, but ~two orders of magnitude slower and unsuitable for a closed loop.Note the label reduction is the same matrix either way, so the two paths agree exactly; only the source step differs.
- source_estimate(data: ndarray, *, info=None, pick_ori=None) ndarray[source]#
Source time courses
(n_src, n_times)via the full MNE route.
- classmethod from_stream(rt, *, atlas: str | None = None, method: str = 'LCMV', reg: float = 0.05, pick_ori: str = 'max-power', weight_norm: str = 'unit-noise-gain') SourceModel[source]#
Build a
SourceModelfrom a session that has recorded a baseline.- Parameters:
- rt
instanceofRTStream Session with
src/fwd/data_covset — i.e. one on whichcompute_inv_operator()has run, directly or through the first source modality that needed it.- atlas
str|None Overrides the session’s
source_atlas.- method
str "LCMV"for the beamformer, or a minimum-norm method name.- reg, pick_ori, weight_norm
Passed to
make_lcmv().
- rt