54 using namespace Eigen;
65 , baseline(qMakePair(-1.0f, -1.0f))
74 QPair<float,float> t_baseline,
76 fiff_int_t p_aspect_kind)
78 if(!
FiffEvoked::read(p_IODevice, *
this, setno, t_baseline, proj, p_aspect_kind))
82 printf(
"\tFiff evoked data not found.\n");
121 times = RowVectorXf();
129 const QStringList& exclude)
const 131 if(include.size() == 0 && exclude.size() == 0)
137 qWarning(
"Warning : No channels match the selection.\n");
149 MatrixXd selBlock(1,1);
151 if(selBlock.rows() != sel.cols() || selBlock.cols() != res.
data.cols())
152 selBlock.resize(sel.cols(), res.
data.cols());
153 for(qint32 l = 0; l < sel.cols(); ++l)
155 if(sel(0,l) <= res.
data.rows()) {
156 selBlock.block(l,0,1,selBlock.cols()) = res.
data.block(sel(0,l),0,1,selBlock.cols());
158 qWarning(
"FiffEvoked::pick_channels - Warning : Selected channel index out of bound.\n");
161 res.
data.resize(sel.cols(), res.
data.cols());
172 QPair<float,float> t_baseline,
174 fiff_int_t p_aspect_kind)
176 p_FiffEvoked.
clear();
182 QString t_sFileName = t_pStream->streamName();
184 printf(
"Reading %s ...\n",t_sFileName.toUtf8().constData());
186 if(!t_pStream->open())
193 if(!t_pStream->read_meas_info(t_pStream->dirtree(),
info, meas))
199 QList<FiffDirNode::SPtr> processed = meas->dir_tree_find(FIFFB_PROCESSED_DATA);
200 if (processed.size() == 0)
202 qWarning(
"Could not find processed data");
206 QList<FiffDirNode::SPtr> evoked_node = meas->dir_tree_find(FIFFB_EVOKED);
207 if (evoked_node.size() == 0)
209 qWarning(
"Could not find evoked data");
216 if (evoked_node.size() > 1)
218 QStringList comments;
219 QList<fiff_int_t> aspect_kinds;
221 if(!t_pStream->get_evoked_entries(evoked_node, comments, aspect_kinds, t))
222 t = QString(
"None found, must use integer");
223 qWarning(
"%d datasets present, setno parameter must be set. Candidate setno names:\n%s", evoked_node.size(), t.toUtf8().constData());
232 bool t_bIsInteger =
true;
233 setno.toInt(&t_bIsInteger);
238 qWarning(
"kindStat must be \"FIFFV_ASPECT_AVERAGE\" or \"FIFFV_ASPECT_STD_ERR\"");
242 QStringList comments;
243 QList<fiff_int_t> aspect_kinds;
245 t_pStream->get_evoked_entries(evoked_node, comments, aspect_kinds, t);
248 for(qint32 i = 0; i < comments.size(); ++i)
250 if(comments[i].compare(setno.toString()) == 0 && p_aspect_kind == aspect_kinds[i])
259 qWarning() <<
"setno " << setno <<
" (" << p_aspect_kind <<
") not found, out of found datasets:\n " << t;
265 if (setno.toInt() >= evoked_node.size() || setno.toInt() < 0)
267 qWarning(
"Data set selector out of range");
276 QList<FiffDirNode::SPtr> aspects = my_evoked->dir_tree_find(FIFFB_ASPECT);
278 if(aspects.size() > 1)
279 printf(
"\tMultiple (%d) aspects found. Taking first one.\n", aspects.size());
286 fiff_int_t nchan = 0;
288 QList<FiffChInfo> chs;
293 for (k = 0; k < my_evoked->nent(); ++k)
295 kind = my_evoked->dir[k]->kind;
296 pos = my_evoked->dir[k]->pos;
300 t_pStream->read_tag(t_pTag,pos);
301 comment = t_pTag->toString();
304 t_pStream->read_tag(t_pTag,pos);
305 first = *t_pTag->toInt();
308 t_pStream->read_tag(t_pTag,pos);
309 last = *t_pTag->toInt();
312 t_pStream->read_tag(t_pTag,pos);
313 nchan = *t_pTag->toInt();
316 t_pStream->read_tag(t_pTag,pos);
317 sfreq = *t_pTag->toFloat();
320 t_pStream->read_tag(t_pTag, pos);
321 chs.append( t_pTag->toChInfo() );
325 if (comment.isEmpty())
326 comment = QString(
"No comment");
335 qWarning(
"Local channel information was not found when it was expected.");
338 if (chs.size() != nchan)
340 qWarning(
"Number of channels and number of channel definitions are different.");
345 printf(
"\tFound channel information in evoked data. nchan = %d\n",nchan);
349 qint32 nsamp =
last-first+1;
350 printf(
"\tFound the data of interest:\n");
351 printf(
"\t\tt = %10.2f ... %10.2f ms (%s)\n", 1000*(
float)first/info.
sfreq, 1000*(
float)
last/info.
sfreq,comment.toUtf8().constData());
352 if (info.
comps.size() > 0)
353 printf(
"\t\t%d CTF compensation matrices available\n", info.
comps.size());
359 fiff_int_t
nave = -1;
360 QList<FiffTag> epoch;
361 for (k = 0; k < my_aspect->nent(); ++k)
363 kind = my_aspect->dir[k]->kind;
364 pos = my_aspect->dir[k]->pos;
369 t_pStream->read_tag(t_pTag, pos);
370 comment = t_pTag->toString();
373 t_pStream->read_tag(t_pTag, pos);
374 aspect_kind = *t_pTag->toInt();
377 t_pStream->read_tag(t_pTag, pos);
378 nave = *t_pTag->toInt();
381 t_pStream->read_tag(t_pTag, pos);
382 epoch.append(
FiffTag(t_pTag.data()));
388 printf(
"\t\tnave = %d - aspect type = %d\n", nave, aspect_kind);
390 qint32 nepoch = epoch.size();
397 all_data = epoch[0].toFloatMatrix().cast<
double>();
398 all_data.transposeInPlace();
402 if (all_data.cols() == 1 && info.
nchan == 1)
403 all_data.transposeInPlace();
410 all_data = epoch[0].toFloatMatrix().cast<
double>();
411 all_data.transposeInPlace();
413 for (k = 1; k < nepoch; ++k)
415 oldsize = all_data.rows();
416 MatrixXd tmp = epoch[k].toFloatMatrix().cast<
double>();
417 tmp.transposeInPlace();
418 all_data.conservativeResize(oldsize+tmp.rows(), all_data.cols());
419 all_data.block(oldsize, 0, tmp.rows(), tmp.cols()) = tmp;
422 if (all_data.cols() != nsamp)
424 qWarning(
"Incorrect number of samples (%d instead of %d)", (
int) all_data.cols(), nsamp);
431 printf(
"\n\tPreprocessing...\n");
432 printf(
"\t%d channels remain after picking\n",info.
nchan);
434 typedef Eigen::Triplet<double> T;
435 std::vector<T> tripletList;
436 tripletList.reserve(info.
nchan);
437 for(k = 0; k < info.
nchan; ++k)
438 tripletList.push_back(T(k, k, info.
chs[k].cal));
439 SparseMatrix<double> cals(info.
nchan, info.
nchan);
440 cals.setFromTriplets(tripletList.begin(), tripletList.end());
442 all_data = cals * all_data;
444 RowVectorXf
times = RowVectorXf(
last-first+1);
445 for (k = 0; k < times.size(); ++k)
446 times[k] = ((
float)(first+k)) / info.
sfreq;
453 printf(
"\tNo projector specified for these data.\n");
454 p_FiffEvoked.
proj = MatrixXd();
463 printf(
"\tThe projection vectors do not apply to these channels\n");
464 p_FiffEvoked.
proj = MatrixXd();
468 printf(
"\tCreated an SSP operator (subspace dimension = %d)\n", nproj);
469 p_FiffEvoked.
proj = projection;
476 if(p_FiffEvoked.
proj.rows() > 0)
478 all_data = p_FiffEvoked.
proj * all_data;
479 printf(
"\tSSP projectors applied to the evoked data\n");
490 p_FiffEvoked.
data = all_data;
509 printf(
"\tNo projector specified for these data.\n");
510 this->proj = MatrixXd();
519 printf(
"\tThe projection vectors do not apply to these channels\n");
520 this->proj = MatrixXd();
524 printf(
"\tCreated an SSP operator (subspace dimension = %d)\n", nproj);
525 this->proj = projection;
539 data = MatrixXd::Zero(newData.rows(),newData.cols());
542 if(
data.cols() == newData.cols() &&
data.rows() == newData.rows()) {
565 printf(
"Applying baseline correction ... (mode: mean)\n");
566 this->
data = MNEMath::rescale(this->
data, this->
times, p_baseline, QString(
"mean"));
FiffTag class declaration, which provides fiff tag I/O and processing methods.
void applyBaselineCorrection(QPair< float, float > &p_baseline)
#define FIFFV_ASPECT_STD_ERR
FiffEvoked pick_channels(const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList) const
void setInfo(const FiffInfo &p_info, bool proj=true)
FiffStream class declaration.
qint32 make_projector(Eigen::MatrixXd &proj) const
MNEMath class declaration.
QSharedPointer< FiffTag > SPtr
QPair< float, float > baseline
static void activate_projs(QList< FiffProj > &p_qListFiffProj)
FiffEvoked class declaration.
QList< FiffCtfComp > comps
static Eigen::RowVectorXi pick_channels(const QStringList &ch_names, const QStringList &include=defaultQStringList, const QStringList &exclude=defaultQStringList)
#define FIFFV_ASPECT_AVERAGE
#define FIFF_FIRST_SAMPLE
FiffDirNode class declaration, which provides fiff dir tree processing methods.
FiffInfo pick_info(const Eigen::RowVectorXi &sel=defaultVectorXi) const
static bool read(QIODevice &p_IODevice, FiffEvoked &p_FiffEvoked, QVariant setno=0, QPair< float, float > t_baseline=defaultFloatPair, bool proj=true, fiff_int_t p_aspect_kind=FIFFV_ASPECT_AVERAGE)
FiffEvoked & operator+=(const Eigen::MatrixXd &newData)
FIFF measurement file information.
QSharedPointer< FiffDirNode > SPtr
QSharedPointer< FiffStream > SPtr