v2.0.0
Loading...
Searching...
No Matches
mne_ctf_comp_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
15
16//=============================================================================================================
17// INCLUDES
18//=============================================================================================================
19
20#include "mne_ctf_comp_data.h"
21#include "mne_types.h"
22
23#include <fiff/fiff_constants.h>
24#include <fiff/fiff_tag.h>
25
26#include <QFile>
27#include <QDebug>
28
29#include <Eigen/Core>
30
31constexpr int FAIL = -1;
32constexpr int OK = 0;
33
34//=============================================================================================================
35// USED NAMESPACES
36//=============================================================================================================
37
38using namespace Eigen;
39using namespace FIFFLIB;
40using namespace MNELIB;
41
42//=============================================================================================================
43// DEFINE MEMBER METHODS
44//=============================================================================================================
45
52
53//=============================================================================================================
54
58, calibrated(false)
59{
60 kind = comp.kind;
61 mne_kind = comp.mne_kind;
63 if (comp.data)
64 data = std::make_unique<MNENamedMatrix>(*comp.data);
65 if (comp.presel)
66 presel = std::make_unique<FiffSparseMatrix>(*comp.presel);
67 if (comp.postsel)
68 postsel = std::make_unique<FiffSparseMatrix>(*comp.postsel);
69}
70
71//=============================================================================================================
72
76
77//=============================================================================================================
78
79int MNECTFCompData::calibrate(const QList<FIFFLIB::FiffChInfo>& chs, int nch, bool do_it)
80{
81 Eigen::VectorXf col_cals(this->data->ncol);
82 Eigen::VectorXf row_cals(this->data->nrow);
83 int j, k, p, found;
84 QString name;
85
86 if (calibrated)
87 return OK;
88
89 for (j = 0; j < this->data->nrow; j++) {
90 name = this->data->rowlist[j];
91 found = false;
92 for (p = 0; p < nch; p++)
93 if (QString::compare(name, chs[p].ch_name) == 0) {
94 row_cals[j] = chs[p].range * chs[p].cal;
95 found = true;
96 break;
97 }
98 if (!found) {
99 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.", name.toUtf8().constData());
100 return FAIL;
101 }
102 }
103 for (k = 0; k < this->data->ncol; k++) {
104 name = this->data->collist[k];
105 found = false;
106 for (p = 0; p < nch; p++)
107 if (QString::compare(name, chs[p].ch_name) == 0) {
108 col_cals[k] = chs[p].range * chs[p].cal;
109 found = true;
110 break;
111 }
112 if (!found) {
113 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.", name.toUtf8().constData());
114 return FAIL;
115 }
116 }
117 if (do_it) {
118 for (j = 0; j < this->data->nrow; j++)
119 for (k = 0; k < this->data->ncol; k++)
120 this->data->data(j, k) = row_cals[j] * this->data->data(j, k) / col_cals[k];
121 } else {
122 for (j = 0; j < this->data->nrow; j++)
123 for (k = 0; k < this->data->ncol; k++)
124 this->data->data(j, k) = col_cals[k] * this->data->data(j, k) / row_cals[j];
125 }
126 return OK;
127}
Symbolic FIFF tag, block, value, unit and channel-type constants shared across FIFFLIB.
FIFF tag: the 16-byte tag header (kind, type, size, next) plus its decoded payload.
if(w.size() > 0)
constexpr int FAIL
constexpr int OK
Legacy MNE-C constants and shared typedefs used across MNELIB structures.
Single CTF reference-sensor compensation matrix labelled by kind.
Core MNE data structures (source spaces, source estimates, hemispheres).
constexpr auto MNE_CTFV_COMP_UNKNOWN
Definition mne_types.h:119
FIFF file I/O, in-memory data structures and high-level readers/writers.
std::unique_ptr< FIFFLIB::FiffSparseMatrix > postsel
std::unique_ptr< MNENamedMatrix > data
std::unique_ptr< FIFFLIB::FiffSparseMatrix > presel
int calibrate(const QList< FIFFLIB::FiffChInfo > &chs, int nch, bool do_it)