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#include <memory>
64
65//=============================================================================================================
66// DEFINE NAMESPACE MNELIB
67//=============================================================================================================
68
69namespace FIFFLIB
70{
71
72//=============================================================================================================
73// FORWARD DECLARATIONS
74//=============================================================================================================
75
76class FiffRawData;
77
78//=============================================================================================================
84class FIFFSHARED_EXPORT FiffCov : public QSharedData
85{
86public:
87 using SPtr = QSharedPointer<FiffCov>;
88 using ConstSPtr = QSharedPointer<const FiffCov>;
89 using UPtr = std::unique_ptr<FiffCov>;
90 using ConstUPtr = std::unique_ptr<const FiffCov>;
91 using SDPtr = QSharedDataPointer<FiffCov>;
92
93 //=========================================================================================================
97 FiffCov();
98
99 //=========================================================================================================
105 FiffCov(QIODevice &p_IODevice);
106
107 //=========================================================================================================
113 FiffCov(const FiffCov &p_FiffCov);
114
115 //=========================================================================================================
119 ~FiffCov();
120
121 //=========================================================================================================
125 void clear();
126
127 //=========================================================================================================
133 inline bool isEmpty() const;
134
135 //=========================================================================================================
146 FiffCov pick_channels(const QStringList &p_include = defaultQStringList, const QStringList &p_exclude = defaultQStringList);
147
148 //=========================================================================================================
157 FiffCov prepare_noise_cov(const FiffInfo& p_info, const QStringList& p_chNames) const;
158
159 //=========================================================================================================
175 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;
176
177 //=========================================================================================================
196 static FiffCov compute_from_epochs(const FiffRawData &raw,
197 const Eigen::MatrixXi &events,
198 const QList<int> &eventCodes,
199 float tmin,
200 float tmax,
201 float bmin = 0.0f,
202 float bmax = 0.0f,
203 bool doBaseline = false,
204 bool removeMean = true,
205 unsigned int ignoreMask = 0,
206 float delay = 0.0f);
207
208 //=========================================================================================================
215 bool save(const QString &fileName) const;
216
217 //=========================================================================================================
225 static FiffCov computeGrandAverage(const QList<FiffCov> &covs);
226
227 //=========================================================================================================
235 FiffCov& operator= (const FiffCov &rhs);
236
237 //=========================================================================================================
246 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov);
247
248public:
250 Eigen::VectorXi chClass;
251 bool diag;
253 QStringList names;
254 Eigen::MatrixXd data;
255 QList<FiffProj> projs;
256 QStringList bads;
258 Eigen::VectorXd eig;
259 Eigen::MatrixXd eigvec;
260
261};
262
263//=============================================================================================================
264// INLINE DEFINITIONS
265//=============================================================================================================
266
267inline bool FiffCov::isEmpty() const
268{
269 return this->dim <= -1;
270}
271
272//=============================================================================================================
273
274inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov)
275{
276 bool t_bIsShort = true;
277 out << "#### Fiff Covariance ####\n";
278 out << "\tKind: " << p_FiffCov.kind << std::endl;
279 out << "\tdiag: " << p_FiffCov.diag << std::endl;
280 out << "\tdim: " << p_FiffCov.dim << std::endl;
281 out << "\tnames " << p_FiffCov.names.size() << ":\n\t";
282
283 if(t_bIsShort)
284 {
285 qint32 nchan = p_FiffCov.names.size() > 6 ? 6 : p_FiffCov.names.size();
286 for(qint32 i = 0; i < nchan/2; ++i)
287 out << p_FiffCov.names[i].toUtf8().constData() << " ";
288 out << "... ";
289 for(qint32 i = p_FiffCov.names.size() - nchan/2; i < p_FiffCov.names.size(); ++i)
290 out << p_FiffCov.names[i].toUtf8().constData() << " ";
291 out << std::endl;
292 }
293
294 out << "\tdata " << p_FiffCov.data.rows() << " x " << p_FiffCov.data.cols() << ":\n\t";
295 if(t_bIsShort)
296 {
297 qint32 nrows = p_FiffCov.data.rows() > 6 ? 6 : p_FiffCov.data.rows();
298 qint32 ncols = p_FiffCov.data.cols() > 6 ? 6 : p_FiffCov.data.cols();
299 for(qint32 i = 0; i < nrows/2; ++i)
300 {
301 for(qint32 j = 0; j < ncols/2; ++j)
302 out << p_FiffCov.data(i,j) << " ";
303 out << "... ";
304 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
305 out << p_FiffCov.data(i,j) << " ";
306 out << "\n\t";
307 }
308 out << "...\n\t";
309 for(qint32 i = p_FiffCov.data.rows()-nrows/2; i < p_FiffCov.data.rows(); ++i)
310 {
311 for(qint32 j = 0; j < ncols/2; ++j)
312 out << p_FiffCov.data(i,j) << " ";
313 out << "... ";
314 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
315 out << p_FiffCov.data(i,j) << " ";
316 out << "\n\t";
317 }
318 out << "\n";
319 }
320 //Projectors
321 out << "\tprojectors " << p_FiffCov.projs.size() << ":\n";
322 for(qint32 i = 0; i < p_FiffCov.projs.size(); ++i)
323 out << "\t" << p_FiffCov.projs[i];
324
325 //Bads
326 out << "\tbads " << p_FiffCov.bads.size() << ":\n\t";
327 for(qint32 i = 0; i < p_FiffCov.bads.size(); ++i)
328 out << p_FiffCov.bads[i].toUtf8().constData() << " ";
329
330 out << "\n\tfree: " << p_FiffCov.nfree << std::endl;
331
332 out << "\teig " << p_FiffCov.eig.size() << ":\n\t";
333 if(t_bIsShort)
334 {
335 qint32 nrows = p_FiffCov.eig.size() > 6 ? 6 : p_FiffCov.eig.size();
336 for(qint32 i = 0; i < nrows/2; ++i)
337 out << p_FiffCov.eig[i] << " ";
338 out << "... ";
339 for(qint32 i = p_FiffCov.eig.size() - nrows/2; i < p_FiffCov.eig.size(); ++i)
340 out << p_FiffCov.eig[i] << " ";
341 out << "\n\t";
342 }
343
344 out << "\n\teigvec " << p_FiffCov.eigvec.rows() << " x " << p_FiffCov.eigvec.cols() << ":\n\t";
345 if(t_bIsShort)
346 {
347 qint32 nrows = p_FiffCov.eigvec.rows() > 6 ? 6 : p_FiffCov.eigvec.rows();
348 qint32 ncols = p_FiffCov.eigvec.cols() > 6 ? 6 : p_FiffCov.eigvec.cols();
349 for(qint32 i = 0; i < nrows/2; ++i)
350 {
351 for(qint32 j = 0; j < ncols/2; ++j)
352 out << p_FiffCov.eigvec(i,j) << " ";
353 out << "... ";
354 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
355 out << p_FiffCov.eigvec(i,j) << " ";
356 out << "\n\t";
357 }
358 out << "...\n\t";
359 for(qint32 i = p_FiffCov.eigvec.rows() - nrows/2; i < p_FiffCov.eigvec.rows(); ++i)
360 {
361 for(qint32 j = 0; j < ncols/2; ++j)
362 out << p_FiffCov.eigvec(i,j) << " ";
363 out << "... ";
364 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
365 out << p_FiffCov.eigvec(i,j) << " ";
366 out << "\n\t";
367 }
368 out << "\n";
369 }
370 return out;
371}
372} // NAMESPACE
373
374#ifndef metatype_fiffcovsptr
375#define metatype_fiffcovsptr
376Q_DECLARE_METATYPE(QSharedPointer<FIFFLIB::FiffCov>);
377#endif
378
379#ifndef metatype_fiffcov
380#define metatype_fiffcov
382#endif
383
384#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:274
qint32 fiff_int_t
Definition fiff_types.h:89
covariance data
Definition fiff_cov.h:85
QList< FiffProj > projs
Definition fiff_cov.h:255
std::unique_ptr< FiffCov > UPtr
Definition fiff_cov.h:89
fiff_int_t nfree
Definition fiff_cov.h:257
fiff_int_t dim
Definition fiff_cov.h:252
Eigen::MatrixXd eigvec
Definition fiff_cov.h:259
bool isEmpty() const
Definition fiff_cov.h:267
friend std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:274
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:327
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:91
std::unique_ptr< const FiffCov > ConstUPtr
Definition fiff_cov.h:90
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:487
FiffCov pick_channels(const QStringList &p_include=defaultQStringList, const QStringList &p_exclude=defaultQStringList)
Definition fiff_cov.cpp:152
QSharedPointer< FiffCov > SPtr
Definition fiff_cov.h:87
Eigen::VectorXi chClass
Definition fiff_cov.h:250
fiff_int_t kind
Definition fiff_cov.h:249
static FiffCov computeGrandAverage(const QList< FiffCov > &covs)
Definition fiff_cov.cpp:628
QStringList bads
Definition fiff_cov.h:256
QStringList names
Definition fiff_cov.h:253
Eigen::VectorXd eig
Definition fiff_cov.h:258
Eigen::MatrixXd data
Definition fiff_cov.h:254
FiffCov prepare_noise_cov(const FiffInfo &p_info, const QStringList &p_chNames) const
Definition fiff_cov.cpp:180
bool save(const QString &fileName) const
Definition fiff_cov.cpp:602
QSharedPointer< const FiffCov > ConstSPtr
Definition fiff_cov.h:88
FIFF measurement file information.
Definition fiff_info.h:86
FIFF raw measurement data.