v2.0.0
Loading...
Searching...
No Matches
fiff_cov.h
Go to the documentation of this file.
1//=============================================================================================================
27
28#ifndef FIFF_COV_H
29#define FIFF_COV_H
30
31//=============================================================================================================
32// INCLUDES
33//=============================================================================================================
34
35#include "fiff_global.h"
36#include "fiff_proj.h"
37#include "fiff_types.h"
38#include "fiff_info.h"
39
40//=============================================================================================================
41// QT INCLUDES
42//=============================================================================================================
43
44#include <QSharedDataPointer>
45#include <QSharedPointer>
46#include <QString>
47#include <QStringList>
48
49//=============================================================================================================
50// EIGEN INCLUDES
51//=============================================================================================================
52
53#include <Eigen/Core>
54#include <memory>
55
56//=============================================================================================================
57// DEFINE NAMESPACE MNELIB
58//=============================================================================================================
59
60namespace FIFFLIB
61{
62
63//=============================================================================================================
64// FORWARD DECLARATIONS
65//=============================================================================================================
66
67class FiffRawData;
68
69//=============================================================================================================
78class FIFFSHARED_EXPORT FiffCov : public QSharedData
79{
80public:
81 using SPtr = QSharedPointer<FiffCov>;
82 using ConstSPtr = QSharedPointer<const FiffCov>;
83 using UPtr = std::unique_ptr<FiffCov>;
84 using ConstUPtr = std::unique_ptr<const FiffCov>;
85 using SDPtr = QSharedDataPointer<FiffCov>;
86
87 //=========================================================================================================
91 FiffCov();
92
93 //=========================================================================================================
99 FiffCov(QIODevice &p_IODevice);
100
101 //=========================================================================================================
107 FiffCov(const FiffCov &p_FiffCov);
108
109 //=========================================================================================================
113 ~FiffCov();
114
115 //=========================================================================================================
119 void clear();
120
121 //=========================================================================================================
127 inline bool isEmpty() const;
128
129 //=========================================================================================================
140 FiffCov pick_channels(const QStringList &p_include = defaultQStringList, const QStringList &p_exclude = defaultQStringList);
141
142 //=========================================================================================================
151 FiffCov prepare_noise_cov(const FiffInfo& p_info, const QStringList& p_chNames) const;
152
153 //=========================================================================================================
169 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;
170
171 //=========================================================================================================
190 static FiffCov compute_from_epochs(const FiffRawData &raw,
191 const Eigen::MatrixXi &events,
192 const QList<int> &eventCodes,
193 float tmin,
194 float tmax,
195 float bmin = 0.0f,
196 float bmax = 0.0f,
197 bool doBaseline = false,
198 bool removeMean = true,
199 unsigned int ignoreMask = 0,
200 float delay = 0.0f);
201
202 //=========================================================================================================
209 bool save(const QString &fileName) const;
210
211 //=========================================================================================================
219 static FiffCov computeGrandAverage(const QList<FiffCov> &covs);
220
221 //=========================================================================================================
229 FiffCov& operator= (const FiffCov &rhs);
230
231 //=========================================================================================================
240 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov);
241
242public:
243 fiff_int_t kind;
244 Eigen::VectorXi chClass;
245 bool diag;
246 fiff_int_t dim;
247 QStringList names;
248 Eigen::MatrixXd data;
249 QList<FiffProj> projs;
250 QStringList bads;
251 fiff_int_t nfree;
252 Eigen::VectorXd eig;
253 Eigen::MatrixXd eigvec;
254
255};
256
257//=============================================================================================================
258// INLINE DEFINITIONS
259//=============================================================================================================
260
261inline bool FiffCov::isEmpty() const
262{
263 return this->dim <= -1;
264}
265
266//=============================================================================================================
267
268inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov &p_FiffCov)
269{
270 bool t_bIsShort = true;
271 out << "#### Fiff Covariance ####\n";
272 out << "\tKind: " << p_FiffCov.kind << std::endl;
273 out << "\tdiag: " << p_FiffCov.diag << std::endl;
274 out << "\tdim: " << p_FiffCov.dim << std::endl;
275 out << "\tnames " << p_FiffCov.names.size() << ":\n\t";
276
277 if(t_bIsShort)
278 {
279 qint32 nchan = p_FiffCov.names.size() > 6 ? 6 : p_FiffCov.names.size();
280 for(qint32 i = 0; i < nchan/2; ++i)
281 out << p_FiffCov.names[i].toUtf8().constData() << " ";
282 out << "... ";
283 for(qint32 i = p_FiffCov.names.size() - nchan/2; i < p_FiffCov.names.size(); ++i)
284 out << p_FiffCov.names[i].toUtf8().constData() << " ";
285 out << std::endl;
286 }
287
288 out << "\tdata " << p_FiffCov.data.rows() << " x " << p_FiffCov.data.cols() << ":\n\t";
289 if(t_bIsShort)
290 {
291 qint32 nrows = p_FiffCov.data.rows() > 6 ? 6 : p_FiffCov.data.rows();
292 qint32 ncols = p_FiffCov.data.cols() > 6 ? 6 : p_FiffCov.data.cols();
293 for(qint32 i = 0; i < nrows/2; ++i)
294 {
295 for(qint32 j = 0; j < ncols/2; ++j)
296 out << p_FiffCov.data(i,j) << " ";
297 out << "... ";
298 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
299 out << p_FiffCov.data(i,j) << " ";
300 out << "\n\t";
301 }
302 out << "...\n\t";
303 for(qint32 i = p_FiffCov.data.rows()-nrows/2; i < p_FiffCov.data.rows(); ++i)
304 {
305 for(qint32 j = 0; j < ncols/2; ++j)
306 out << p_FiffCov.data(i,j) << " ";
307 out << "... ";
308 for(qint32 j = p_FiffCov.data.cols() - ncols/2; j < p_FiffCov.data.cols(); ++j)
309 out << p_FiffCov.data(i,j) << " ";
310 out << "\n\t";
311 }
312 out << "\n";
313 }
314 //Projectors
315 out << "\tprojectors " << p_FiffCov.projs.size() << ":\n";
316 for(qint32 i = 0; i < p_FiffCov.projs.size(); ++i)
317 out << "\t" << p_FiffCov.projs[i];
318
319 //Bads
320 out << "\tbads " << p_FiffCov.bads.size() << ":\n\t";
321 for(qint32 i = 0; i < p_FiffCov.bads.size(); ++i)
322 out << p_FiffCov.bads[i].toUtf8().constData() << " ";
323
324 out << "\n\tfree: " << p_FiffCov.nfree << std::endl;
325
326 out << "\teig " << p_FiffCov.eig.size() << ":\n\t";
327 if(t_bIsShort)
328 {
329 qint32 nrows = p_FiffCov.eig.size() > 6 ? 6 : p_FiffCov.eig.size();
330 for(qint32 i = 0; i < nrows/2; ++i)
331 out << p_FiffCov.eig[i] << " ";
332 out << "... ";
333 for(qint32 i = p_FiffCov.eig.size() - nrows/2; i < p_FiffCov.eig.size(); ++i)
334 out << p_FiffCov.eig[i] << " ";
335 out << "\n\t";
336 }
337
338 out << "\n\teigvec " << p_FiffCov.eigvec.rows() << " x " << p_FiffCov.eigvec.cols() << ":\n\t";
339 if(t_bIsShort)
340 {
341 qint32 nrows = p_FiffCov.eigvec.rows() > 6 ? 6 : p_FiffCov.eigvec.rows();
342 qint32 ncols = p_FiffCov.eigvec.cols() > 6 ? 6 : p_FiffCov.eigvec.cols();
343 for(qint32 i = 0; i < nrows/2; ++i)
344 {
345 for(qint32 j = 0; j < ncols/2; ++j)
346 out << p_FiffCov.eigvec(i,j) << " ";
347 out << "... ";
348 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
349 out << p_FiffCov.eigvec(i,j) << " ";
350 out << "\n\t";
351 }
352 out << "...\n\t";
353 for(qint32 i = p_FiffCov.eigvec.rows() - nrows/2; i < p_FiffCov.eigvec.rows(); ++i)
354 {
355 for(qint32 j = 0; j < ncols/2; ++j)
356 out << p_FiffCov.eigvec(i,j) << " ";
357 out << "... ";
358 for(qint32 j = p_FiffCov.eigvec.cols() - ncols/2; j < p_FiffCov.eigvec.cols(); ++j)
359 out << p_FiffCov.eigvec(i,j) << " ";
360 out << "\n\t";
361 }
362 out << "\n";
363 }
364 return out;
365}
366} // NAMESPACE
367
368#ifndef metatype_fiffcovsptr
369#define metatype_fiffcovsptr
370Q_DECLARE_METATYPE(QSharedPointer<FIFFLIB::FiffCov>);
371#endif
372
373#ifndef metatype_fiffcov
374#define metatype_fiffcov
376#endif
377
378#endif // FIFF_COV_H
SSP projection item: a named projection vector set with active/desired flags, parsed from FIFFB_PROJ_...
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Q_DECLARE_METATYPE(QSharedPointer< FIFFLIB::FiffCov >)
Export/import macros and build-info accessors for the FIFFLIB shared library.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:44
Primitive scalar typedefs and forward-compatible aliases backing the FIFF type system.
FIFF file I/O, in-memory data structures and high-level readers/writers.
std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:268
FIFF noise / data covariance: matrix, channel names, kind, applied projectors, bads,...
Definition fiff_cov.h:79
QList< FiffProj > projs
Definition fiff_cov.h:249
std::unique_ptr< FiffCov > UPtr
Definition fiff_cov.h:83
fiff_int_t nfree
Definition fiff_cov.h:251
fiff_int_t dim
Definition fiff_cov.h:246
Eigen::MatrixXd eigvec
Definition fiff_cov.h:253
bool isEmpty() const
Definition fiff_cov.h:261
friend std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:268
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:311
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:85
std::unique_ptr< const FiffCov > ConstUPtr
Definition fiff_cov.h:84
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:472
FiffCov pick_channels(const QStringList &p_include=defaultQStringList, const QStringList &p_exclude=defaultQStringList)
Definition fiff_cov.cpp:136
QSharedPointer< FiffCov > SPtr
Definition fiff_cov.h:81
Eigen::VectorXi chClass
Definition fiff_cov.h:244
fiff_int_t kind
Definition fiff_cov.h:243
static FiffCov computeGrandAverage(const QList< FiffCov > &covs)
Definition fiff_cov.cpp:613
QStringList bads
Definition fiff_cov.h:250
QStringList names
Definition fiff_cov.h:247
Eigen::VectorXd eig
Definition fiff_cov.h:252
Eigen::MatrixXd data
Definition fiff_cov.h:248
FiffCov prepare_noise_cov(const FiffInfo &p_info, const QStringList &p_chNames) const
Definition fiff_cov.cpp:164
bool save(const QString &fileName) const
Definition fiff_cov.cpp:587
QSharedPointer< const FiffCov > ConstSPtr
Definition fiff_cov.h:82
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:88