MNE-CPP 0.1.9
A Framework for Electrophysiology
Loading...
Searching...
No Matches
fiff_cov.h
Go to the documentation of this file.
1//=============================================================================================================
37#ifndef FIFF_COV_H
38#define FIFF_COV_H
39
40//=============================================================================================================
41// INCLUDES
42//=============================================================================================================
43
44#include "fiff_global.h"
45#include "fiff_proj.h"
46#include "fiff_types.h"
47#include "fiff_info.h"
48
49//=============================================================================================================
50// QT INCLUDES
51//=============================================================================================================
52
53#include <QSharedDataPointer>
54#include <QSharedPointer>
55#include <QString>
56#include <QStringList>
57
58//=============================================================================================================
59// EIGEN INCLUDES
60//=============================================================================================================
61
62#include <Eigen/Core>
63
64//=============================================================================================================
65// DEFINE NAMESPACE MNELIB
66//=============================================================================================================
67
68namespace FIFFLIB
69{
70
71//=============================================================================================================
77class FIFFSHARED_EXPORT FiffCov : public QSharedData
78{
79public:
80 typedef QSharedPointer<FiffCov> SPtr;
81 typedef QSharedPointer<const FiffCov> ConstSPtr;
82 typedef QSharedDataPointer<FiffCov> SDPtr;
84 //=========================================================================================================
88 FiffCov();
89
90 //=========================================================================================================
96 FiffCov(QIODevice &p_IODevice);
97
98 //=========================================================================================================
104 FiffCov(const FiffCov &p_FiffCov);
105
106 //=========================================================================================================
110 ~FiffCov();
111
112 //=========================================================================================================
116 void clear();
117
118 //=========================================================================================================
124 inline bool isEmpty() const;
125
126 //=========================================================================================================
137 FiffCov pick_channels(const QStringList &p_include = defaultQStringList, const QStringList &p_exclude = defaultQStringList);
138
139 //=========================================================================================================
148 FiffCov prepare_noise_cov(const FiffInfo& p_info, const QStringList& p_chNames) const;
149
150 //=========================================================================================================
166 FiffCov regularize(const FiffInfo& p_info, double p_fMag = 0.1, double p_fGrad = 0.1, double p_fEeg = 0.1, bool p_bProj = true, QStringList p_exclude = defaultQStringList) const;
167
168 //=========================================================================================================
176 FiffCov& operator= (const FiffCov &rhs);
177
178 //=========================================================================================================
187 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov);
188
189public:
190 fiff_int_t kind;
191 Eigen::VectorXi chClass;
192 bool diag;
193 fiff_int_t dim;
194 QStringList names;
195 Eigen::MatrixXd data;
196 QList<FiffProj> projs;
197 QStringList bads;
198 fiff_int_t nfree;
199 Eigen::VectorXd eig;
200 Eigen::MatrixXd eigvec;
202// ### OLD STRUCT ###
203// typedef struct { /* Covariance matrix storage */
204// int kind; /* Sensor or source covariance */
205// int ncov; /* Dimension */
206// int nfree; /* Number of degrees of freedom */
207// int nproj; /* Number of dimensions projected out */
208// int nzero; /* Number of zero or small eigenvalues */
209// char **names; /* Names of the entries (optional) */
210// double *cov; /* Covariance matrix in packed representation (lower triangle) */
211// double *cov_diag; /* Diagonal covariance matrix */
212// mneSparseMatrix cov_sparse; /* A sparse covariance matrix
213// * (Note: data are floats in this which is an inconsistency) */
214// double *lambda; /* Eigenvalues of cov */
215// double *inv_lambda; /* Inverses of the square roots of the eigenvalues of cov */
216// float **eigen; /* Eigenvectors of cov */
217// double *chol; /* Cholesky decomposition */
218// mneProjOp proj; /* The projection which was active when this matrix was computed */
219// mneSssData sss; /* The SSS data present in the associated raw data file */
220// int *ch_class; /* This will allow grouping of channels for regularization (MEG [T/m], MEG [T], EEG [V] */
221// char **bads; /* Which channels were designated bad when this noise covariance matrix was computed? */
222// int nbad; /* How many of them */
223// } *mneCovMatrix,mneCovMatrixRec;
224};
225
226//=============================================================================================================
227// INLINE DEFINITIONS
228//=============================================================================================================
229
230inline bool FiffCov::isEmpty() const
231{
232 return this->dim <= -1;
233}
234
235//=============================================================================================================
236
237inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov)
238{
239 bool t_bIsShort = true;
240 out << "#### Fiff Covariance ####\n";
241 out << "\tKind: " << p_FiffCov.kind << std::endl;
242 out << "\tdiag: " << p_FiffCov.diag << std::endl;
243 out << "\tdim: " << p_FiffCov.dim << std::endl;
244 out << "\tnames " << p_FiffCov.names.size() << ":\n\t";
245
246 if(t_bIsShort)
247 {
248 qint32 nchan = p_FiffCov.names.size() > 6 ? 6 : p_FiffCov.names.size();
249 for(qint32 i = 0; i < nchan/2; ++i)
250 out << p_FiffCov.names[i].toUtf8().constData() << " ";
251 out << "... ";
252 for(qint32 i = p_FiffCov.names.size() - nchan/2; i < p_FiffCov.names.size(); ++i)
253 out << p_FiffCov.names[i].toUtf8().constData() << " ";
254 out << std::endl;
255 }
256
257 out << "\tdata " << p_FiffCov.data.rows() << " x " << p_FiffCov.data.cols() << ":\n\t";
258 if(t_bIsShort)
259 {
260 qint32 nrows = p_FiffCov.data.rows() > 6 ? 6 : p_FiffCov.data.rows();
261 qint32 ncols = p_FiffCov.data.cols() > 6 ? 6 : p_FiffCov.data.cols();
262 for(qint32 i = 0; i < nrows/2; ++i)
263 {
264 for(qint32 j = 0; j < ncols/2; ++j)
265 out << p_FiffCov.data(i,j) << " ";
266 out << "... ";
267 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
268 out << p_FiffCov.data(i,j) << " ";
269 out << "\n\t";
270 }
271 out << "...\n\t";
272 for(qint32 i = p_FiffCov.data.rows()-nrows/2; i < p_FiffCov.data.rows(); ++i)
273 {
274 for(qint32 j = 0; j < ncols/2; ++j)
275 out << p_FiffCov.data(i,j) << " ";
276 out << "... ";
277 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
278 out << p_FiffCov.data(i,j) << " ";
279 out << "\n\t";
280 }
281 out << "\n";
282 }
283 //Projectors
284 out << "\tprojectors " << p_FiffCov.projs.size() << ":\n";
285 for(qint32 i = 0; i < p_FiffCov.projs.size(); ++i)
286 out << "\t" << p_FiffCov.projs[i];
287
288 //Bads
289 out << "\tbads " << p_FiffCov.bads.size() << ":\n\t";
290 for(qint32 i = 0; i < p_FiffCov.bads.size(); ++i)
291 out << p_FiffCov.bads[i].toUtf8().constData() << " ";
292
293 out << "\n\tfree: " << p_FiffCov.nfree << std::endl;
294
295 out << "\teig " << p_FiffCov.eig.size() << ":\n\t";
296 if(t_bIsShort)
297 {
298 qint32 nrows = p_FiffCov.eig.size() > 6 ? 6 : p_FiffCov.eig.size();
299 for(qint32 i = 0; i < nrows/2; ++i)
300 out << p_FiffCov.eig[i] << " ";
301 out << "... ";
302 for(qint32 i = p_FiffCov.eig.size() - nrows/2; i < p_FiffCov.eig.size(); ++i)
303 out << p_FiffCov.eig[i] << " ";
304 out << "\n\t";
305 }
306
307 out << "\n\teigvec " << p_FiffCov.eigvec.rows() << " x " << p_FiffCov.eigvec.cols() << ":\n\t";
308 if(t_bIsShort)
309 {
310 qint32 nrows = p_FiffCov.eigvec.rows() > 6 ? 6 : p_FiffCov.eigvec.rows();
311 qint32 ncols = p_FiffCov.eigvec.cols() > 6 ? 6 : p_FiffCov.eigvec.cols();
312 for(qint32 i = 0; i < nrows/2; ++i)
313 {
314 for(qint32 j = 0; j < ncols/2; ++j)
315 out << p_FiffCov.eigvec(i,j) << " ";
316 out << "... ";
317 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
318 out << p_FiffCov.eigvec(i,j) << " ";
319 out << "\n\t";
320 }
321 out << "...\n\t";
322 for(qint32 i = p_FiffCov.eigvec.rows() - nrows/2; i < p_FiffCov.eigvec.rows(); ++i)
323 {
324 for(qint32 j = 0; j < ncols/2; ++j)
325 out << p_FiffCov.eigvec(i,j) << " ";
326 out << "... ";
327 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
328 out << p_FiffCov.eigvec(i,j) << " ";
329 out << "\n\t";
330 }
331 out << "\n";
332 }
333 return out;
334}
335} // NAMESPACE
336
337#ifndef metatype_fiffcovsptr
338#define metatype_fiffcovsptr
339Q_DECLARE_METATYPE(QSharedPointer<FIFFLIB::FiffCov>);
340#endif
341
342#ifndef metatype_fiffcov
343#define metatype_fiffcov
345#endif
346
347#endif // FIFF_COV_H
FiffInfo class declaration.
Fiff library export/import macros.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:56
FiffProj class declaration.
std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:237
Q_DECLARE_METATYPE(QSharedPointer< FIFFLIB::FiffCov >)
Definitions for describing the objects in a FIFF file.
covariance data
Definition fiff_cov.h:78
QList< FiffProj > projs
Definition fiff_cov.h:196
fiff_int_t nfree
Definition fiff_cov.h:198
fiff_int_t dim
Definition fiff_cov.h:193
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:82
Eigen::MatrixXd eigvec
Definition fiff_cov.h:200
QSharedPointer< const FiffCov > ConstSPtr
Definition fiff_cov.h:81
bool isEmpty() const
Definition fiff_cov.h:230
QSharedPointer< FiffCov > SPtr
Definition fiff_cov.h:80
fiff_int_t kind
Definition fiff_cov.h:190
QStringList bads
Definition fiff_cov.h:197
QStringList names
Definition fiff_cov.h:194
Eigen::VectorXd eig
Definition fiff_cov.h:199
Eigen::MatrixXd data
Definition fiff_cov.h:195
FIFF measurement file information.
Definition fiff_info.h:85