MNE-CPP  0.1.9
A Framework for Electrophysiology
mne_ctf_comp_data.cpp
Go to the documentation of this file.
1 //=============================================================================================================
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 
48 #include <Eigen/Core>
49 
50 #ifndef TRUE
51 #define TRUE 1
52 #endif
53 
54 #ifndef FALSE
55 #define FALSE 0
56 #endif
57 
58 #ifndef FAIL
59 #define FAIL -1
60 #endif
61 
62 #ifndef OK
63 #define OK 0
64 #endif
65 
66 #define MALLOC_31(x,t) (t *)malloc((x)*sizeof(t))
67 
68 #define FREE_31(x) if ((char *)(x) != NULL) free((char *)(x))
69 
70 #define MNE_CTFV_COMP_UNKNOWN -1
71 #define MNE_CTFV_COMP_NONE 0
72 #define MNE_CTFV_COMP_G1BR 0x47314252
73 #define MNE_CTFV_COMP_G2BR 0x47324252
74 #define MNE_CTFV_COMP_G3BR 0x47334252
75 #define MNE_CTFV_COMP_G2OI 0x47324f49
76 #define MNE_CTFV_COMP_G3OI 0x47334f49
77 
78 //=============================================================================================================
79 // USED NAMESPACES
80 //=============================================================================================================
81 
82 using namespace Eigen;
83 using namespace FIFFLIB;
84 using namespace MNELIB;
85 
86 //=============================================================================================================
87 // DEFINE MEMBER METHODS
88 //=============================================================================================================
89 
90 MneCTFCompData::MneCTFCompData()
91 :kind(MNE_CTFV_COMP_UNKNOWN)
92 ,mne_kind(MNE_CTFV_COMP_UNKNOWN)
93 ,calibrated(FALSE)
94 ,data(NULL)
95 ,presel(NULL)
96 ,postsel(NULL)
97 ,presel_data(NULL)
98 ,comp_data(NULL)
99 ,postsel_data(NULL)
100 {
101 }
102 
103 //=============================================================================================================
104 
106 :kind(MNE_CTFV_COMP_UNKNOWN)
107 ,mne_kind(MNE_CTFV_COMP_UNKNOWN)
108 ,calibrated(FALSE)
109 ,data(NULL)
110 ,presel(NULL)
111 ,postsel(NULL)
112 ,presel_data(NULL)
113 ,comp_data(NULL)
114 ,postsel_data(NULL)
115 {
116  kind = comp.kind;
117  mne_kind = comp.mne_kind;
118  calibrated = comp.calibrated;
119  data = new MneNamedMatrix(*comp.data);
120 
121  presel = new FiffSparseMatrix(*comp.presel);
122  postsel = new FiffSparseMatrix(*comp.postsel);
123 }
124 
125 //=============================================================================================================
126 
128 {
129  if(data)
130  delete data;
131  if(presel)
132  delete presel;
133  if(postsel)
134  delete postsel;
135  FREE_31(presel_data);
136  FREE_31(postsel_data);
137  FREE_31(comp_data);
138 }
139 
140 //=============================================================================================================
141 
142 int MneCTFCompData::mne_calibrate_ctf_comp(MneCTFCompData *one, const QList<FIFFLIB::FiffChInfo>& chs, int nch, int do_it)
143 /*
144  * Calibrate or decalibrate a compensation data set
145  */
146 {
147  float *col_cals,*row_cals;
148  int j,k,p,found;
149  QString name;
150  float **data;
151 
152  if (!one)
153  return OK;
154  if (one->calibrated)
155  return OK;
156 
157  row_cals = MALLOC_31(one->data->nrow,float);
158  col_cals = MALLOC_31(one->data->ncol,float);
159 
160  for (j = 0; j < one->data->nrow; j++) {
161  name = one->data->rowlist[j];
162  found = FALSE;
163  for (p = 0; p < nch; p++)
164  if (QString::compare(name,chs[p].ch_name) == 0) {
165  row_cals[j] = chs[p].range*chs[p].cal;
166  found = TRUE;
167  break;
168  }
169  if (!found) {
170  printf("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
171  return FAIL;
172  }
173  }
174  for (k = 0; k < one->data->ncol; k++) {
175  name = one->data->collist[k];
176  found = FALSE;
177  for (p = 0; p < nch; p++)
178  if (QString::compare(name,chs[p].ch_name) == 0) {
179  col_cals[k] = chs[p].range*chs[p].cal;
180  found = TRUE;
181  break;
182  }
183  if (!found) {
184  printf("Channel %s not found. Cannot calibrate the compensation matrix.",name.toUtf8().constData());
185  return FAIL;
186  }
187  }
188  data = one->data->data;
189  if (do_it) {
190  for (j = 0; j < one->data->nrow; j++)
191  for (k = 0; k < one->data->ncol; k++)
192  data[j][k] = row_cals[j]*data[j][k]/col_cals[k];
193  }
194  else {
195  for (j = 0; j < one->data->nrow; j++)
196  for (k = 0; k < one->data->ncol; k++)
197  data[j][k] = col_cals[k]*data[j][k]/row_cals[j];
198  }
199  return OK;
200 }
One MNE CTF compensation description.
Fiff constants.
Matrix specification with a channel list.
FiffTag class declaration, which provides fiff tag I/O and processing methods.
Data associated with MNE computations for each mneMeasDataSet.
MneCTFCompData class declaration.