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;
68struct RejectionParams;
69
70//=============================================================================================================
81class FIFFSHARED_EXPORT FiffCov : public QSharedData
82{
83public:
84 using SPtr = QSharedPointer<FiffCov>;
85 using ConstSPtr = QSharedPointer<const FiffCov>;
86 using UPtr = std::unique_ptr<FiffCov>;
87 using ConstUPtr = std::unique_ptr<const FiffCov>;
88 using SDPtr = QSharedDataPointer<FiffCov>;
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 //=========================================================================================================
194 static FiffCov compute_from_epochs(const FiffRawData& raw,
195 const Eigen::MatrixXi& events,
196 const QList<int>& eventCodes,
197 float tmin,
198 float tmax,
199 float bmin = 0.0f,
200 float bmax = 0.0f,
201 bool doBaseline = false,
202 bool removeMean = true,
203 unsigned int ignoreMask = 0,
204 float delay = 0.0f,
205 const RejectionParams* rej = nullptr);
206
207 //=========================================================================================================
214 bool save(const QString& fileName) const;
215
216 //=========================================================================================================
224 static FiffCov computeGrandAverage(const QList<FiffCov>& covs);
225
226 //=========================================================================================================
234 FiffCov& operator=(const FiffCov& rhs);
235
236 //=========================================================================================================
245 friend std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov& p_FiffCov);
246
247public:
249 Eigen::VectorXi chClass;
250 bool diag;
252 QStringList names;
253 Eigen::MatrixXd data;
254 QList<FiffProj> projs;
255 QStringList bads;
257 Eigen::VectorXd eig;
258 Eigen::MatrixXd eigvec;
259};
260
261//=============================================================================================================
262// INLINE DEFINITIONS
263//=============================================================================================================
264
265inline bool FiffCov::isEmpty() const
266{
267 return this->dim <= -1;
268}
269
270//=============================================================================================================
271
272inline std::ostream& operator<<(std::ostream& out, const FIFFLIB::FiffCov& p_FiffCov)
273{
274 bool t_bIsShort = true;
275 out << "#### Fiff Covariance ####\n";
276 out << "\tKind: " << p_FiffCov.kind << std::endl;
277 out << "\tdiag: " << p_FiffCov.diag << std::endl;
278 out << "\tdim: " << p_FiffCov.dim << std::endl;
279 out << "\tnames " << p_FiffCov.names.size() << ":\n\t";
280
281 if (t_bIsShort) {
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 qint32 nrows = p_FiffCov.data.rows() > 6 ? 6 : p_FiffCov.data.rows();
294 qint32 ncols = p_FiffCov.data.cols() > 6 ? 6 : p_FiffCov.data.cols();
295 for (qint32 i = 0; i < nrows / 2; ++i) {
296 for (qint32 j = 0; j < ncols / 2; ++j)
297 out << p_FiffCov.data(i, j) << " ";
298 out << "... ";
299 for (qint32 j = p_FiffCov.data.cols() - ncols / 2; j < p_FiffCov.data.cols(); ++j)
300 out << p_FiffCov.data(i, j) << " ";
301 out << "\n\t";
302 }
303 out << "...\n\t";
304 for (qint32 i = p_FiffCov.data.rows() - nrows / 2; i < p_FiffCov.data.rows(); ++i) {
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 qint32 nrows = p_FiffCov.eig.size() > 6 ? 6 : p_FiffCov.eig.size();
329 for (qint32 i = 0; i < nrows / 2; ++i)
330 out << p_FiffCov.eig[i] << " ";
331 out << "... ";
332 for (qint32 i = p_FiffCov.eig.size() - nrows / 2; i < p_FiffCov.eig.size(); ++i)
333 out << p_FiffCov.eig[i] << " ";
334 out << "\n\t";
335 }
336
337 out << "\n\teigvec " << p_FiffCov.eigvec.rows() << " x " << p_FiffCov.eigvec.cols() << ":\n\t";
338 if (t_bIsShort) {
339 qint32 nrows = p_FiffCov.eigvec.rows() > 6 ? 6 : p_FiffCov.eigvec.rows();
340 qint32 ncols = p_FiffCov.eigvec.cols() > 6 ? 6 : p_FiffCov.eigvec.cols();
341 for (qint32 i = 0; i < nrows / 2; ++i) {
342 for (qint32 j = 0; j < ncols / 2; ++j)
343 out << p_FiffCov.eigvec(i, j) << " ";
344 out << "... ";
345 for (qint32 j = p_FiffCov.eigvec.cols() - ncols / 2; j < p_FiffCov.eigvec.cols(); ++j)
346 out << p_FiffCov.eigvec(i, j) << " ";
347 out << "\n\t";
348 }
349 out << "...\n\t";
350 for (qint32 i = p_FiffCov.eigvec.rows() - nrows / 2; i < p_FiffCov.eigvec.rows(); ++i) {
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";
359 }
360 return out;
361}
362} // NAMESPACE
363
364#ifndef metatype_fiffcovsptr
365#define metatype_fiffcovsptr
366Q_DECLARE_METATYPE(QSharedPointer<FIFFLIB::FiffCov>);
367#endif
368
369#ifndef metatype_fiffcov
370#define metatype_fiffcov
372#endif
373
374#endif // FIFF_COV_H
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
Export/import macros and build-info accessors for the FIFFLIB shared library.
#define FIFFSHARED_EXPORT
Definition fiff_global.h:44
SSP projection item: a named projection vector set with active/desired flags, parsed from FIFFB_PROJ_...
Q_DECLARE_METATYPE(QSharedPointer< FIFFLIB::FiffCov >)
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:272
qint32 fiff_int_t
Definition fiff_types.h:86
FIFF noise / data covariance: matrix, channel names, kind, applied projectors, bads,...
Definition fiff_cov.h:82
QList< FiffProj > projs
Definition fiff_cov.h:254
std::unique_ptr< FiffCov > UPtr
Definition fiff_cov.h:86
fiff_int_t nfree
Definition fiff_cov.h:256
fiff_int_t dim
Definition fiff_cov.h:251
Eigen::MatrixXd eigvec
Definition fiff_cov.h:258
bool isEmpty() const
Definition fiff_cov.h:265
friend std::ostream & operator<<(std::ostream &out, const FIFFLIB::FiffCov &p_FiffCov)
Definition fiff_cov.h:272
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:298
QSharedDataPointer< FiffCov > SDPtr
Definition fiff_cov.h:88
std::unique_ptr< const FiffCov > ConstUPtr
Definition fiff_cov.h:87
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:84
Eigen::VectorXi chClass
Definition fiff_cov.h:249
fiff_int_t kind
Definition fiff_cov.h:248
static FiffCov computeGrandAverage(const QList< FiffCov > &covs)
Definition fiff_cov.cpp:598
FiffCov & operator=(const FiffCov &rhs)
Definition fiff_cov.cpp:431
QStringList bads
Definition fiff_cov.h:255
QStringList names
Definition fiff_cov.h:252
Eigen::VectorXd eig
Definition fiff_cov.h:257
Eigen::MatrixXd data
Definition fiff_cov.h:253
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:572
QSharedPointer< const FiffCov > ConstSPtr
Definition fiff_cov.h:85
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, const RejectionParams *rej=nullptr)
Definition fiff_cov.cpp:452
Artifact-rejection thresholds for the MNE-C batch averaging pipeline (gradiometer / magnetometer / EE...
Full FIFF measurement info: per-channel descriptors, sampling and filter setup, projectors,...
Definition fiff_info.h:90
Continuous FIFF raw recording: FiffInfo plus a random-access directory of FIFF_DATA_BUFFER tags.