v2.0.0
Loading...
Searching...
No Matches
mne_ctf_comp_data.cpp
Go to the documentation of this file.
1//=============================================================================================================
36
37//=============================================================================================================
38// INCLUDES
39//=============================================================================================================
40
41#include "mne_ctf_comp_data.h"
42
43#include <fiff/fiff_constants.h>
44#include <fiff/fiff_tag.h>
45
46#include <QFile>
47#include <QDebug>
48
49#include <Eigen/Core>
50
51constexpr int FAIL = -1;
52constexpr int OK = 0;
53
54#define MNE_CTFV_COMP_UNKNOWN -1
55#define MNE_CTFV_COMP_NONE 0
56#define MNE_CTFV_COMP_G1BR 0x47314252
57#define MNE_CTFV_COMP_G2BR 0x47324252
58#define MNE_CTFV_COMP_G3BR 0x47334252
59#define MNE_CTFV_COMP_G2OI 0x47324f49
60#define MNE_CTFV_COMP_G3OI 0x47334f49
61
62//=============================================================================================================
63// USED NAMESPACES
64//=============================================================================================================
65
66using namespace Eigen;
67using namespace FIFFLIB;
68using namespace MNELIB;
69
70//=============================================================================================================
71// DEFINE MEMBER METHODS
72//=============================================================================================================
73
80
81//=============================================================================================================
82
86,calibrated(false)
87{
88 kind = comp.kind;
89 mne_kind = comp.mne_kind;
91 if (comp.data)
92 data = std::make_unique<MNENamedMatrix>(*comp.data);
93 if (comp.presel)
94 presel = std::make_unique<FiffSparseMatrix>(*comp.presel);
95 if (comp.postsel)
96 postsel = std::make_unique<FiffSparseMatrix>(*comp.postsel);
97}
98
99//=============================================================================================================
100
104
105//=============================================================================================================
106
107int MNECTFCompData::calibrate(const QList<FIFFLIB::FiffChInfo>& chs, int nch, bool do_it)
108{
109 Eigen::VectorXf col_cals(this->data->ncol);
110 Eigen::VectorXf row_cals(this->data->nrow);
111 int j,k,p,found;
112 QString name;
113
114 if (calibrated)
115 return OK;
116
117 for (j = 0; j < this->data->nrow; j++) {
118 name = this->data->rowlist[j];
119 found = false;
120 for (p = 0; p < nch; p++)
121 if (QString::compare(name,chs[p].ch_name) == 0) {
122 row_cals[j] = chs[p].range*chs[p].cal;
123 found = true;
124 break;
125 }
126 if (!found) {
127 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
128 return FAIL;
129 }
130 }
131 for (k = 0; k < this->data->ncol; k++) {
132 name = this->data->collist[k];
133 found = false;
134 for (p = 0; p < nch; p++)
135 if (QString::compare(name,chs[p].ch_name) == 0) {
136 col_cals[k] = chs[p].range*chs[p].cal;
137 found = true;
138 break;
139 }
140 if (!found) {
141 qCritical("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
142 return FAIL;
143 }
144 }
145 if (do_it) {
146 for (j = 0; j < this->data->nrow; j++)
147 for (k = 0; k < this->data->ncol; k++)
148 this->data->data(j, k) = row_cals[j]*this->data->data(j, k)/col_cals[k];
149 }
150 else {
151 for (j = 0; j < this->data->nrow; j++)
152 for (k = 0; k < this->data->ncol; k++)
153 this->data->data(j, k) = col_cals[k]*this->data->data(j, k)/row_cals[j];
154 }
155 return OK;
156}
constexpr int FAIL
constexpr int OK
FiffTag class declaration, which provides fiff tag I/O and processing methods.
Fiff constants.
MNECTFCompData class declaration.
#define MNE_CTFV_COMP_UNKNOWN
Core MNE data structures (source spaces, source estimates, hemispheres).
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
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)