v2.0.0
Loading...
Searching...
No Matches
mne_cortical_map.cpp
Go to the documentation of this file.
1//=============================================================================================================
15
16//=============================================================================================================
17// INCLUDES
18//=============================================================================================================
19
20#include "mne_cortical_map.h"
23
24#include <fiff/fiff_info.h>
26
27//=============================================================================================================
28// QT INCLUDES
29//=============================================================================================================
30
31#include <QDebug>
32
33//=============================================================================================================
34// USED NAMESPACES
35//=============================================================================================================
36
37using namespace MNELIB;
38using namespace FIFFLIB;
39using namespace Eigen;
40
41//=============================================================================================================
42// DEFINE MEMBER METHODS
43//=============================================================================================================
44
46 const MNEForwardSolution& fwd,
47 const MNEInverseOperator& inv,
48 const FiffInfo& info)
49{
50 Q_UNUSED(info);
51
52 // Get the inverse kernel (nSources x nChannels)
53 const MatrixXd& kernel = const_cast<MNEInverseOperator&>(inv).getKernel();
54 if (kernel.rows() == 0 || kernel.cols() == 0) {
55 qWarning("MNECorticalMap::makeCorticalMap - Inverse kernel is empty. "
56 "Make sure the inverse operator has been prepared (assemble_kernel).");
57 return MatrixXd();
58 }
59
60 if (!fwd.sol || fwd.sol->data.rows() == 0) {
61 qWarning("MNECorticalMap::makeCorticalMap - Forward solution is empty.");
62 return MatrixXd();
63 }
64 // A loose inverse kernel is in surface coordinates; rotate a Cartesian free forward to match
65 // (mne-python _convert_forward_match_inv).
66 MNEForwardSolution matched = fwd;
67 const bool looseInverse = inv.orient_prior && inv.orient_prior->data.size() > 0 && (inv.orient_prior->data.array() < 1.0).any();
68 if (looseInverse && !matched.isFixedOrient())
69 matched.convert_to_surf_ori();
70
71 // The kernel's columns are the inverse operator's channels; pick those rows of the gain by name, as
72 // mne-python's make_inverse_resolution_matrix does.
73 MatrixXd gain = matched.sol->data;
74 const QStringList& invChannels = inv.eigen_fields ? inv.eigen_fields->col_names : QStringList();
75 if (invChannels.size() == kernel.cols() && matched.sol->row_names.size() == gain.rows()) {
76 MatrixXd picked(kernel.cols(), gain.cols());
77 for (int c = 0; c < invChannels.size(); ++c) {
78 const int row = static_cast<int>(matched.sol->row_names.indexOf(invChannels[c]));
79 if (row < 0) {
80 qWarning("MNECorticalMap::makeCorticalMap - Channel %s is not in the forward solution.",
81 invChannels[c].toUtf8().constData());
82 return MatrixXd();
83 }
84 picked.row(c) = gain.row(row);
85 }
86 gain = picked;
87 }
88
89 // Verify dimension compatibility
90 if (kernel.cols() != gain.rows()) {
91 qWarning("MNECorticalMap::makeCorticalMap - Dimension mismatch: "
92 "kernel is %lld x %lld, gain is %lld x %lld",
93 static_cast<long long>(kernel.rows()),
94 static_cast<long long>(kernel.cols()),
95 static_cast<long long>(gain.rows()),
96 static_cast<long long>(gain.cols()));
97 return MatrixXd();
98 }
99
100 return kernel * gain;
101}
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Matrix paired with row and column name lists, the on-disk form of FIFFB_PROJ_ITEM / FIFFB_MNE_NAMED_M...
Pre-computed inverse operator (whitened SVD of the forward model) for MNE/dSPM/sLORETA.
Resolution matrix K G of an inverse operator and its forward solution.
Forward solution (gain matrix mapping source dipoles to sensor measurements).
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:90
static Eigen::MatrixXd makeCorticalMap(const MNEForwardSolution &fwd, const MNEInverseOperator &inv, const FIFFLIB::FiffInfo &info)
In-memory representation of an -fwd.fif forward solution.
FIFFLIB::FiffNamedMatrix::SDPtr sol
MNE-style inverse operator.
FIFFLIB::FiffCov::SDPtr orient_prior
FIFFLIB::FiffNamedMatrix::SDPtr eigen_fields