v2.0.0
Loading...
Searching...
No Matches
mne_deriv.cpp
Go to the documentation of this file.
1//=============================================================================================================
12
13//=============================================================================================================
14// INCLUDES
15//=============================================================================================================
16
17#include "mne_deriv.h"
18
19//=============================================================================================================
20// USED NAMESPACES
21//=============================================================================================================
22
23using namespace MNELIB;
24using namespace FIFFLIB;
25
26//=============================================================================================================
27// DEFINE MEMBER METHODS
28//=============================================================================================================
29
30MNEDeriv::MNEDeriv() = default;
31
32//=============================================================================================================
33
35: filename(other.filename)
36, shortname(other.shortname)
37, deriv_data(other.deriv_data ? std::make_unique<MNESparseNamedMatrix>() : nullptr)
38, in_use(other.in_use)
39, valid(other.valid)
40, chs(other.chs)
41{
42 if (deriv_data) {
43 deriv_data->nrow = other.deriv_data->nrow;
44 deriv_data->ncol = other.deriv_data->ncol;
45 deriv_data->rowlist = other.deriv_data->rowlist;
46 deriv_data->collist = other.deriv_data->collist;
47 if (other.deriv_data->data) {
48 deriv_data->data = std::make_unique<FiffSparseMatrix>(*other.deriv_data->data);
49 }
50 }
51}
52
53//=============================================================================================================
54
55MNEDeriv::~MNEDeriv() = default;
56
57//=============================================================================================================
58
59int MNEDeriv::validate(const QList<FiffChInfo>& chInfo)
60{
61 const int nrow = deriv_data ? deriv_data->nrow : 0;
62 valid = Eigen::VectorXi::Zero(nrow);
63 chs.clear();
64 for (int j = 0; j < nrow; ++j) {
65 chs.append(FiffChInfo());
66 }
67 if (chInfo.isEmpty() || nrow == 0) {
68 return 0;
69 }
70 QStringList names;
71 for (const FiffChInfo& ch : chInfo) {
72 names << ch.ch_name;
73 }
74 // Row-major view: the inputs of derived channel j are the non-zeros of row j.
75 const Eigen::SparseMatrix<float, Eigen::RowMajor> rows = deriv_data->data->eigen();
76 int nvalid = 0;
77 for (int j = 0; j < nrow; ++j) {
78 const FiffChInfo* first = nullptr;
79 bool ok = true;
80 for (Eigen::SparseMatrix<float, Eigen::RowMajor>::InnerIterator it(rows, j); it && ok; ++it) {
81 const int pick = static_cast<int>(names.indexOf(deriv_data->collist.value(static_cast<int>(it.col()))));
82 if (pick < 0) {
83 ok = false;
84 } else if (!first) {
85 first = &chInfo[pick];
86 } else {
87 const FiffChInfo& ch = chInfo[pick];
88 ok = ch.unit == first->unit && ch.unit_mul == first->unit_mul && ch.kind == first->kind;
89 }
90 }
91 if (ok && first) {
92 valid[j] = 1;
93 chs[j] = *first;
94 ++nvalid;
95 }
96 }
97 return nvalid;
98}
One channel derivation: a sparse matrix whose rows define virtual channels as weighted sums of record...
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O, in-memory data structures and high-level readers/writers.
Per-channel FIFF descriptor: identifiers, kind, calibration, coil type, channel-frame coil position a...
Eigen::VectorXi valid
Definition mne_deriv.h:106
std::unique_ptr< MNESparseNamedMatrix > deriv_data
Definition mne_deriv.h:104
QList< FIFFLIB::FiffChInfo > chs
Definition mne_deriv.h:107
Eigen::VectorXi in_use
Definition mne_deriv.h:105
QString shortname
Definition mne_deriv.h:103
int validate(const QList< FIFFLIB::FiffChInfo > &chInfo)
Definition mne_deriv.cpp:59