v2.0.0
Loading...
Searching...
No Matches
fiff_cov.h
Go to the documentation of this file.
1//=============================================================================================================
36
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//=============================================================================================================
72// FORWARD DECLARATIONS
73//=============================================================================================================
74
75class FiffRawData;
76
77//=============================================================================================================
83class FIFFSHARED_EXPORT FiffCov : public QSharedData
84{
85public:
86 typedef QSharedPointer<FiffCov> SPtr;
87 typedef QSharedPointer<const FiffCov> ConstSPtr;
88 typedef QSharedDataPointer<FiffCov> SDPtr;
89
90 //=========================================================================================================
94 FiffCov();
95
96 //=========================================================================================================
102 FiffCov(QIODevice &p_IODevice);
103
104 //=========================================================================================================
110 FiffCov(const FiffCov &p_FiffCov);
111
112 //=========================================================================================================
116 ~FiffCov();
117
118 //=========================================================================================================
122 void clear();
123
124 //=========================================================================================================
130 inline bool isEmpty() const;
131
132 //=========================================================================================================
143 FiffCov pick_channels(const QStringList &p_include = defaultQStringList, const QStringList &p_exclude = defaultQStringList);
144
145 //=========================================================================================================
154 FiffCov prepare_noise_cov(const FiffInfo& p_info, const QStringList& p_chNames) const;
155
156 //=========================================================================================================
172 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;
173
174 //=========================================================================================================
193 static FiffCov compute_from_epochs(const FiffRawData &raw,
194 const Eigen::MatrixXi &events,
195 const QList<int> &eventCodes,
196 float tmin,
197 float tmax,
198 float bmin = 0.0f,
199 float bmax = 0.0f,
200 bool doBaseline = false,
201 bool removeMean = true,
202 unsigned int ignoreMask = 0,
203 float delay = 0.0f);
204
205 //=========================================================================================================
212 bool save(const QString &fileName) const;
213
214 //=========================================================================================================
222 static FiffCov computeGrandAverage(const QList<FiffCov> &covs);
223
224 //=========================================================================================================
232 FiffCov& operator= (const FiffCov &rhs);
233
234 //=========================================================================================================
243 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov);
244
245public:
247 Eigen::VectorXi chClass;
248 bool diag;
250 QStringList names;
251 Eigen::MatrixXd data;
252 QList<FiffProj> projs;
253 QStringList bads;
255 Eigen::VectorXd eig;
256 Eigen::MatrixXd eigvec;
257
258};
259
260//=============================================================================================================
261// INLINE DEFINITIONS
262//=============================================================================================================
263
264inline bool FiffCov::isEmpty() const
265{
266 return this->dim <= -1;
267}
268
269//=============================================================================================================
270
271inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov)
272{
273 bool t_bIsShort = true;
274 out << "#### Fiff Covariance ####\n";
275 out << "\tKind: " << p_FiffCov.kind << std::endl;
276 out << "\tdiag: " << p_FiffCov.diag << std::endl;
277 out << "\tdim: " << p_FiffCov.dim << std::endl;
278 out << "\tnames " << p_FiffCov.names.size() << ":\n\t";
279
280 if(t_bIsShort)
281 {
282 qint32 nchan = p_FiffCov.names.size() > 6 ? 6 : p_FiffCov.names.size();
283 for(qint32 i = 0; i < nchan/2; ++i)
284 out << p_FiffCov.names[i].toUtf8().constData() << " ";
285 out << "... ";
286 for(qint32 i = p_FiffCov.names.size() - nchan/2; i < p_FiffCov.names.size(); ++i)
287 out << p_FiffCov.names[i].toUtf8().constData() << " ";
288 out << std::endl;
289 }
290
291 out << "\tdata " << p_FiffCov.data.rows() << " x " << p_FiffCov.data.cols() << ":\n\t";
292 if(t_bIsShort)
293 {
294 qint32 nrows = p_FiffCov.data.rows() > 6 ? 6 : p_FiffCov.data.rows();
295 qint32 ncols = p_FiffCov.data.cols() > 6 ? 6 : p_FiffCov.data.cols();
296 for(qint32 i = 0; i < nrows/2; ++i)
297 {
298 for(qint32 j = 0; j < ncols/2; ++j)
299 out << p_FiffCov.data(i,j) << " ";
300 out << "... ";
301 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
302 out << p_FiffCov.data(i,j) << " ";
303 out << "\n\t";
304 }
305 out << "...\n\t";
306 for(qint32 i = p_FiffCov.data.rows()-nrows/2; i < p_FiffCov.data.rows(); ++i)
307 {
308 for(qint32 j = 0; j < ncols/2; ++j)
309 out << p_FiffCov.data(i,j) << " ";
310 out << "... ";
311 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
312 out << p_FiffCov.data(i,j) << " ";
313 out << "\n\t";
314 }
315 out << "\n";
316 }
317 //Projectors
318 out << "\tprojectors " << p_FiffCov.projs.size() << ":\n";
319 for(qint32 i = 0; i < p_FiffCov.projs.size(); ++i)
320 out << "\t" << p_FiffCov.projs[i];
321
322 //Bads
323 out << "\tbads " << p_FiffCov.bads.size() << ":\n\t";
324 for(qint32 i = 0; i < p_FiffCov.bads.size(); ++i)
325 out << p_FiffCov.bads[i].toUtf8().constData() << " ";
326
327 out << "\n\tfree: " << p_FiffCov.nfree << std::endl;
328
329 out << "\teig " << p_FiffCov.eig.size() << ":\n\t";
330 if(t_bIsShort)
331 {
332 qint32 nrows = p_FiffCov.eig.size() > 6 ? 6 : p_FiffCov.eig.size();
333 for(qint32 i = 0; i < nrows/2; ++i)
334 out << p_FiffCov.eig[i] << " ";
335 out << "... ";
336 for(qint32 i = p_FiffCov.eig.size() - nrows/2; i < p_FiffCov.eig.size(); ++i)
337 out << p_FiffCov.eig[i] << " ";
338 out << "\n\t";
339 }
340
341 out << "\n\teigvec " << p_FiffCov.eigvec.rows() << " x " << p_FiffCov.eigvec.cols() << ":\n\t";
342 if(t_bIsShort)
343 {
344 qint32 nrows = p_FiffCov.eigvec.rows() > 6 ? 6 : p_FiffCov.eigvec.rows();
345 qint32 ncols = p_FiffCov.eigvec.cols() > 6 ? 6 : p_FiffCov.eigvec.cols();
346 for(qint32 i = 0; i < nrows/2; ++i)
347 {
348 for(qint32 j = 0; j < ncols/2; ++j)
349 out << p_FiffCov.eigvec(i,j) << " ";
350 out << "... ";
351 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
352 out << p_FiffCov.eigvec(i,j) << " ";
353 out << "\n\t";
354 }
355 out << "...\n\t";
356 for(qint32 i = p_FiffCov.eigvec.rows() - nrows/2; i < p_FiffCov.eigvec.rows(); ++i)
357 {
358 for(qint32 j = 0; j < ncols/2; ++j)
359 out << p_FiffCov.eigvec(i,j) << " ";
360 out << "... ";
361 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
362 out << p_FiffCov.eigvec(i,j) << " ";
363 out << "\n\t";
364 }
365 out << "\n";
366 }
367 return out;
368}
369} // NAMESPACE
370
371#ifndef metatype_fiffcovsptr
372#define metatype_fiffcovsptr
373Q_DECLARE_METATYPE(QSharedPointer<FIFFLIB::FiffCov>);
374#endif
375
376#ifndef metatype_fiffcov
377#define metatype_fiffcov
379#endif
380
381#endif // FIFF_COV_H
FiffInfo class declaration.
Fiff library export/import macros.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:52
FiffProj class declaration.
Q_DECLARE_METATYPE(QSharedPointer< FIFFLIB::FiffCov >)
Old fiff_type declarations - replace them.
FIFF file I/O and data structures (raw, epochs, evoked, covariance, forward).
std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:271
qint32 fiff_int_t
Definition fiff_types.h:89
covariance data
Definition fiff_cov.h:84
QList< FiffProj > projs
Definition fiff_cov.h:252
fiff_int_t nfree
Definition fiff_cov.h:254
fiff_int_t dim
Definition fiff_cov.h:249
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:88
Eigen::MatrixXd eigvec
Definition fiff_cov.h:256
QSharedPointer< const FiffCov > ConstSPtr
Definition fiff_cov.h:87
bool isEmpty() const
Definition fiff_cov.h:264
friend std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:271
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
Definition fiff_cov.cpp:326
static FiffCov compute_from_epochs(const FiffRawData &raw, const Eigen::MatrixXi &events, const QList< int > &eventCodes, float tmin, float tmax, float bmin=0.0f, float bmax=0.0f, bool doBaseline=false, bool removeMean=true, unsigned int ignoreMask=0, float delay=0.0f)
Definition fiff_cov.cpp:486
QSharedPointer< FiffCov > SPtr
Definition fiff_cov.h:86
FiffCov pick_channels(const QStringList &p_include=defaultQStringList, const QStringList &p_exclude=defaultQStringList)
Definition fiff_cov.cpp:151
Eigen::VectorXi chClass
Definition fiff_cov.h:247
fiff_int_t kind
Definition fiff_cov.h:246
static FiffCov computeGrandAverage(const QList< FiffCov > &covs)
Definition fiff_cov.cpp:627
QStringList bads
Definition fiff_cov.h:253
QStringList names
Definition fiff_cov.h:250
Eigen::VectorXd eig
Definition fiff_cov.h:255
Eigen::MatrixXd data
Definition fiff_cov.h:251
FiffCov prepare_noise_cov(const FiffInfo &p_info, const QStringList &p_chNames) const
Definition fiff_cov.cpp:179
bool save(const QString &fileName) const
Definition fiff_cov.cpp:601
FIFF measurement file information.
Definition fiff_info.h:85
FIFF raw measurement data.