52 using namespace FIFFLIB;
53 using namespace UTILSLIB;
54 using namespace Eigen;
65 , baseline(qMakePair(-1.0f, -1.0f))
74 QPair<float,float> t_baseline,
76 fiff_int_t p_aspect_kind)
82 printf(
"\tFiff evoked data not found.\n");
90 : info(p_FiffEvoked.info)
91 , nave(p_FiffEvoked.nave)
92 , aspect_kind(p_FiffEvoked.aspect_kind)
93 , first(p_FiffEvoked.first)
94 , last(p_FiffEvoked.last)
95 , comment(p_FiffEvoked.comment)
96 , times(p_FiffEvoked.times)
97 , data(p_FiffEvoked.data)
98 , proj(p_FiffEvoked.proj)
99 , baseline(p_FiffEvoked.baseline)
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(
"%lld 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 (%lld) 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);
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() );
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);
350 printf(
"\tFound the data of interest:\n");
353 printf(
"\t\t%lld 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);
373 t_pStream->read_tag(t_pTag, pos);
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()));
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;
438 tripletList.push_back(T(
k,
k,
info.
chs[
k].cal));
440 cals.setFromTriplets(tripletList.begin(), tripletList.end());
442 all_data = cals * all_data;
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"));