v2.0.0
Loading...
Searching...
No Matches
fiff_ctf_comp.cpp
Go to the documentation of this file.
1//=============================================================================================================
17
18//=============================================================================================================
19// INCLUDES
20//=============================================================================================================
21
22#include "fiff_ctf_comp.h"
23
24//=============================================================================================================
25// USED NAMESPACES
26//=============================================================================================================
27
28using namespace FIFFLIB;
29using namespace Eigen;
30
31//=============================================================================================================
32// DEFINE MEMBER METHODS
33//=============================================================================================================
34
36: ctfkind(-1)
37, kind(-1)
38, save_calibrated(false)
40{
41}
42
43//=============================================================================================================
44
46: ctfkind(p_FiffCtfComp.ctfkind)
47, kind(p_FiffCtfComp.kind)
48, save_calibrated(p_FiffCtfComp.save_calibrated)
49, rowcals(p_FiffCtfComp.rowcals)
50, colcals(p_FiffCtfComp.colcals)
51, data(p_FiffCtfComp.data)
52{
53}
54
55//=============================================================================================================
56
60
61//=============================================================================================================
62
64{
65 ctfkind = -1;
66 kind = -1;
67 save_calibrated = false;
68 rowcals = MatrixXd();
69 colcals = MatrixXd();
71}
72
73//=============================================================================================================
74
75namespace
76{
77
78int uniqueChannel(const QList<FiffChInfo>& chs, const QString& name)
79{
80 int found = -1;
81 for (int i = 0; i < chs.size(); ++i) {
82 if (chs[i].ch_name == name) {
83 if (found >= 0) {
84 qWarning("Ambiguous channel %s", name.toUtf8().constData());
85 return -1;
86 }
87 found = i;
88 }
89 }
90 if (found < 0)
91 qWarning("Channel %s is not available in data", name.toUtf8().constData());
92 return found;
93}
94
95} // namespace
96
97bool FiffCtfComp::calibrate(const QList<FiffChInfo>& chs)
98{
99 rowcals = MatrixXd::Ones(data->data.rows(), 1);
100 colcals = MatrixXd::Ones(data->data.cols(), 1);
101 if (save_calibrated)
102 return true;
103 for (Index col = 0; col < data->data.cols(); ++col) {
104 const int p = uniqueChannel(chs, data->col_names.value(col));
105 if (p < 0)
106 return false;
107 colcals(col) = 1.0 / (static_cast<double>(chs[p].range) * chs[p].cal);
108 }
109 for (Index row = 0; row < data->data.rows(); ++row) {
110 const int p = uniqueChannel(chs, data->row_names.value(row));
111 if (p < 0)
112 return false;
113 rowcals(row) = static_cast<double>(chs[p].range) * chs[p].cal;
114 }
115 data->data = rowcals.asDiagonal() * data->data * colcals.asDiagonal();
116 return true;
117}
CTF / 4D Neuroimaging software gradient-compensation matrix block (FIFFB_MNE_CTF_COMP_DATA).
FIFF file I/O, in-memory data structures and high-level readers/writers.
bool calibrate(const QList< FiffChInfo > &chs)
Eigen::MatrixXd rowcals
Eigen::MatrixXd colcals
FiffNamedMatrix::SDPtr data
FIFF named matrix: dense / sparse Eigen matrix plus row-name and column-name string lists.
QSharedDataPointer< FiffNamedMatrix > SDPtr