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
22#include <fiff/fiff_constants.h>
23#include <fiff/fiff_tag.h>
24
25#include <QFile>
26#include <QDebug>
27
28#include <Eigen/Core>
29
30constexpr int FAIL = -1;
31constexpr int OK = 0;
32
33#define MNE_CTFV_COMP_UNKNOWN -1
34#define MNE_CTFV_COMP_NONE 0
35#define MNE_CTFV_COMP_G1BR 0x47314252
36#define MNE_CTFV_COMP_G2BR 0x47324252
37#define MNE_CTFV_COMP_G3BR 0x47334252
38#define MNE_CTFV_COMP_G2OI 0x47324f49
39#define MNE_CTFV_COMP_G3OI 0x47334f49
40
41//=============================================================================================================
42// USED NAMESPACES
43//=============================================================================================================
44
45using namespace Eigen;
46using namespace FIFFLIB;
47using namespace MNELIB;
48
49//=============================================================================================================
50// DEFINE MEMBER METHODS
51//=============================================================================================================
52
59
60//=============================================================================================================
61
65,calibrated(false)
66{
67 kind = comp.kind;
68 mne_kind = comp.mne_kind;
70 if (comp.data)
71 data = std::make_unique<MNENamedMatrix>(*comp.data);
72 if (comp.presel)
73 presel = std::make_unique<FiffSparseMatrix>(*comp.presel);
74 if (comp.postsel)
75 postsel = std::make_unique<FiffSparseMatrix>(*comp.postsel);
76}
77
78//=============================================================================================================
79
83
84//=============================================================================================================
85
86int MNECTFCompData::calibrate(const QList<FIFFLIB::FiffChInfo>& chs, int nch, bool do_it)
87{
88 Eigen::VectorXf col_cals(this->data->ncol);
89 Eigen::VectorXf row_cals(this->data->nrow);
90 int j,k,p,found;
91 QString name;
92
93 if (calibrated)
94 return OK;
95
96 for (j = 0; j < this->data->nrow; j++) {
97 name = this->data->rowlist[j];
98 found = false;
99 for (p = 0; p < nch; p++)
100 if (QString::compare(name,chs[p].ch_name) == 0) {
101 row_cals[j] = chs[p].range*chs[p].cal;
102 found = true;
103 break;
104 }
105 if (!found) {
106 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
107 return FAIL;
108 }
109 }
110 for (k = 0; k < this->data->ncol; k++) {
111 name = this->data->collist[k];
112 found = false;
113 for (p = 0; p < nch; p++)
114 if (QString::compare(name,chs[p].ch_name) == 0) {
115 col_cals[k] = chs[p].range*chs[p].cal;
116 found = true;
117 break;
118 }
119 if (!found) {
120 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
121 return FAIL;
122 }
123 }
124 if (do_it) {
125 for (j = 0; j < this->data->nrow; j++)
126 for (k = 0; k < this->data->ncol; k++)
127 this->data->data(j, k) = row_cals[j]*this->data->data(j, k)/col_cals[k];
128 }
129 else {
130 for (j = 0; j < this->data->nrow; j++)
131 for (k = 0; k < this->data->ncol; k++)
132 this->data->data(j, k) = col_cals[k]*this->data->data(j, k)/row_cals[j];
133 }
134 return OK;
135}
constexpr int FAIL
constexpr int OK
Single CTF reference-sensor compensation matrix labelled by kind.
#define MNE_CTFV_COMP_UNKNOWN
if(w.size() > 0)
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.
Core MNE data structures (source spaces, source estimates, hemispheres).
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)