MNEForwardSolution
Namespace: MNELIB · Library: MNE Library
mne.Forward in MNE-Python.
#include <mne/mne_forward_solution.h>
class MNELIB::MNEForwardSolution
Forward solution: leadfield matrix mapping source-space dipoles to sensor measurements, together with the source spaces, coordinate transforms and SSP/CTF state it was computed under.
In-memory representation of an -fwd.fif forward solution.
FsLabel v1;
FsLabel::read(data + "/subjects/sample/label/lh.V1.label", v1);
QFile fwdFile(data + "/Result/ref-sample_audvis-meg-eeg-oct-6-fwd.fif");
const MNEForwardSolution fwd = MNEForwardSolution(fwdFile).pick_regions({v1}); // 70 sources x 3 orientations
QFile covFile(data + "/MEG/sample/sample_audvis-cov.fif");
const FiffCov noiseCov(covFile);
QFile aveFile(data + "/MEG/sample/sample_audvis-ave.fif");
const FiffEvoked evoked(aveFile, 0); // "Left Auditory"
const MNEInverseOperator inverse = MNEInverseOperator::make_inverse_operator(evoked.info, fwd, noiseCov, 0.2f, 0.8f);
const float lambda2 = 1.0f / 9.0f; // SNR 3
InvMinimumNorm dspm(inverse, lambda2, "dSPM");
const InvSourceEstimate stc = dspm.calculateInverse(evoked); // one row per source, combined over orientations
Public Methods
MNEForwardSolution()
Default constructor.
MNEForwardSolution(p_IODevice, force_fixed, surf_ori, include, exclude, bExcludeBads)
Constructs a forward operator, by reading from a IO device.
Parameters:
-
p_IODevice : QIODevice & IO device to read from the forward operator.
-
force_fixed : bool Force fixed source orientation mode? (optional).
-
surf_ori : bool Use surface based source coordinate system? (optional).
-
include : const QStringList & Include these channels (optional).
-
exclude : const QStringList & Exclude these channels (optional).
-
bExcludeBads : bool Drop the channels marked bad in the file; mne.read_forward_solution keeps them.
MNEForwardSolution(p_MNEForwardSolution)
Copy constructor.
Parameters:
- p_MNEForwardSolution : const MNEForwardSolution &
MNEforward solution.
operator=(other)
Copy assignment operator.
Copies public data fields only (not computation state).
Parameters:
- other : const MNEForwardSolution &
MNEforward solution to copy from.
Returns:
- MNEForwardSolution & — Reference to this.
MNEForwardSolution(other)
Move constructs an MNEForwardSolution.
Parameters:
- other : MNEForwardSolution && Forward solution to move from; left in a valid but unspecified state.
operator=(other)
Move assignment operator.
Parameters:
- other : MNEForwardSolution && Forward solution to move from; left in a valid but unspecified state.
Returns:
- MNEForwardSolution & — Reference to this object.
~MNEForwardSolution()
Destroys the MNEForwardSolution.
clear()
Initializes the MNE forward solution.
cluster_forward_solution(p_AnnotationSet, p_iClusterSize, p_D, p_pNoise_cov, p_pInfo, p_sMethod)
Cluster the forward solution and stores the result to p_fwdOut.
The clustering is done by using the provided annotations
Parameters:
-
p_AnnotationSet : const FsAnnotationSet & FsAnnotation set containing the annotation of left & right hemisphere.
-
p_iClusterSize : qint32 Maximal cluster size per roi.
-
p_D : Eigen::MatrixXd & The cluster operator.
-
p_pNoise_cov : const FiffCov & Noise covariance used to whiten the gain matrix before clustering (optional).
-
p_pInfo : const FiffInfo & Measurement info matching the noise covariance (optional).
-
p_sMethod : QString "cityblock" or "sqeuclidean".
Returns:
- MNEForwardSolution — clustered
MNEforward solution.
compute_orient_prior(loose)
Compute orientation prior.
Parameters:
- loose : float The loose orientation parameter.
Returns:
- FiffCov — Orientation priors.
isClustered()
Indicates whether fwd conatins a clustered forward solution.
Returns:
- bool — true if forward solution is clustered, false otherwise.
isEmpty()
True if FIFF measurement file information is empty.
Returns:
- bool — true if FIFF measurement file information is empty.
isFixedOrient()
Has forward operator fixed orientation?
Returns:
- bool — true if forward operator has fixed orientation, false otherwise.
pick_channels(include, exclude)
mne.fiff.pick_channels_forward
Pick channels from forward operator
Parameters:
-
include : const QStringList & List of channels to include. (if None, include all available).
-
exclude : const QStringList & Channels to exclude (if None, do not exclude any).
Returns:
- MNEForwardSolution — Forward solution restricted to selected channel types.
pick_regions(p_qListLabels)
Reduces a forward solution to selected regions.
Parameters:
- p_qListLabels : const QList< FsLabel > & ROIs.
Returns:
- MNEForwardSolution — the reduced forward solution.
pick_types(meg, eeg, include, exclude)
mne.fiff.pick_types_forward
Pick by channel type and names from a forward operator
Parameters:
-
meg : bool Include MEG channels.
-
eeg : bool Include EEG channels.
-
include : const QStringList & Additional channels to include (if empty, do not add any).
-
exclude : const QStringList & Channels to exclude (if empty, do not exclude any).
Returns:
- MNEForwardSolution — Forward solution restricted to selected channel types.
prepare_forward(p_info, p_noise_cov, p_pca, p_outFwdInfo, gain, p_outNoiseCov, p_outWhitener, p_outNumNonZero)
Prepare forward for assembling the inverse operator.
Parameters:
-
p_info : const FiffInfo & The measurement info to specify the channels to include. Bad channels in info['bads'] are not used.
-
p_noise_cov : const FiffCov & The noise covariance matrix.
-
p_pca : bool Calculate pca or not.
-
p_outFwdInfo : FiffInfo & Selected channel names.
-
gain : Eigen::MatrixXd & Gain matrix.
-
p_outNoiseCov : FiffCov & noise covariance matrix.
-
p_outWhitener : Eigen::MatrixXd & Whitener.
-
p_outNumNonZero : qint32 & the rank (non zeros).
tripletSelection(p_vecIdxSelection)
write(p_IODevice)
Write the forward solution to a FIFF file.
Formerly write_solution (SVN MNE).
Splits the combined MEG/EEG forward matrix back into separate blocks for FIFF storage, writes source spaces, coordinate transforms, and parent file provenance.
Parameters:
- p_IODevice : QIODevice & The I/O device (e.g. QFile) to write to.
Returns:
- bool — True if succeeded, false otherwise.
reduce_forward_solution(p_iNumDipoles, p_D)
reduces the forward solution and stores the result to p_fwdOut.
Parameters:
-
p_iNumDipoles : qint32 Desired number of dipoles.
-
p_D : Eigen::MatrixXd & The reduction operator.
Returns:
- MNEForwardSolution — reduced
MNEforward solution.
to_fixed_ori()
Helper to convert the forward solution to fixed ori from free.
convert_to_surf_ori()
Rotates a free-orientation solution into local surface coordinates (two tangential components, then the normal), using average patch normals when the source spaces carry them.
Equivalent of mne.convert_forward_solution(fwd, surf_ori=True). Does nothing if already surface-oriented or fixed.
getSourcePositionsByLabel(lPickedLabels, tSurfSetInflated)
Returns the positions of the specified sources based on their beloning labels.
Parameters:
-
lPickedLabels : const QList< FsLabel > & The stream to which the
MNEforward solution should be assigned to. -
tSurfSetInflated : const FsSurfaceSet & The surface used to pick the source from, based on their index specified bzy this forward solution.
Returns:
- Eigen::MatrixX3f — the source position in 3D space.
Static Methods
compute_depth_prior(Gain, gain_info, is_fixed_ori, exp, limit, patch_areas, limit_depth_chs)
Compute weighting for depth prior.
ToDo move this to FiffCov
Parameters:
-
Gain : const Eigen::MatrixXd & gain matrix.
-
gain_info : const FiffInfo & The measurement info to specify the channels to include.
-
is_fixed_ori : bool Fixed orientation?.
-
exp : double float in [0, 1]. Depth weighting coefficients. If None, no depth weighting is performed. (optional; default = 0.8).
-
limit : double (optional; default = 10.0).
-
patch_areas : const Eigen::MatrixXd & (optional) Cortical patch area of each source position (m²); the source gain is divided by it, as in mne.forward.compute_depth_prior.
-
limit_depth_chs : bool If True, use only grad channels in depth weighting (equivalent to
MNEC code). If grad chanels aren't present, only mag channels will be used (if no mag, then eeg). If False, use all channels. (optional).
Returns:
- FiffCov — the depth prior.
read(p_IODevice, fwd, force_fixed, surf_ori, include, exclude, bExcludeBads)
Parameters:
-
p_IODevice : QIODevice & A fiff IO device like a fiff QFile or QTCPSocket.
-
fwd : MNEForwardSolution & A forward solution from a fif file.
-
force_fixed : bool Force fixed source orientation mode? (optional).
-
surf_ori : bool Use surface based source coordinate system? (optional).
-
include : const QStringList & Include these channels (optional).
-
exclude : const QStringList & Exclude these channels (optional).
-
bExcludeBads : bool Drop the channels marked bad in the file; mne.read_forward_solution keeps them.
Returns:
- bool — true if succeeded, false otherwise.
restrict_gain_matrix(G, info)
Restrict gain matrix entries for optimal depth weighting.
Parameters:
-
G : Eigen::MatrixXd & Gain matrix to be restricted; result is stored in place.
-
info : const FiffInfo & Fiff information.
Example
- Full source:
src/examples/ex_inv_api/main.cpp - Build target:
ex_inv_api(runs under CTest) - Data: mne-cpp-test-data
Used in examples
ex_inv_api
Inverse library: minimum-norm estimates, resolution matrices, label time courses, sparse solvers.
FsLabel v1;
FsLabel::read(data + "/subjects/sample/label/lh.V1.label", v1);
QFile fwdFile(data + "/Result/ref-sample_audvis-meg-eeg-oct-6-fwd.fif");
const MNEForwardSolution fwd = MNEForwardSolution(fwdFile).pick_regions({v1}); // 70 sources x 3 orientations
QFile covFile(data + "/MEG/sample/sample_audvis-cov.fif");
const FiffCov noiseCov(covFile);
QFile aveFile(data + "/MEG/sample/sample_audvis-ave.fif");
const FiffEvoked evoked(aveFile, 0); // "Left Auditory"
ex_connectivity
Example of using the MNE-CPP Connectivity library.
MNEForwardSolution t_clusteredFwd;
MNEForwardSolution t_Fwd;
ex_connectivity_comparison
Example to compare connectivity methods.
MNEForwardSolution t_clusteredFwd;
MNEForwardSolution t_Fwd;
Also used in ex_fwd_api, ex_roi_clustered_inverse_pwl_rap_music, ex_clustered_inverse_mne_raw, ex_clustered_inverse_pwl_rap_music_raw, ex_clustered_inverse_rap_music_raw, ex_disp_3D, ex_histogram, ex_inverse_pwl_rap_music, ex_inverse_rap_music, ex_read_fwd, ex_st_clustered_inverse_pwl_rap_music, ex_compute_forward, ex_dsp_rt, ex_inv_beamformer, ex_inverse_mne_raw, ex_read_fwd_disp_3D.
Authors of this file
- Christoph Dinh <christoph.dinh@mne-cpp.org>