108 const QStringList& exclude)
const
110 if (include.size() == 0 && exclude.size() == 0)
114 if (sel.cols() == 0) {
115 qWarning(
"Warning : No channels match the selection.\n");
127 MatrixXd selBlock(1, 1);
129 if (selBlock.rows() != sel.cols() || selBlock.cols() != res.
data.cols())
130 selBlock.resize(sel.cols(), res.
data.cols());
131 for (qint32 l = 0; l < sel.cols(); ++l) {
132 if (sel(0, l) <= res.
data.rows()) {
133 selBlock.block(l, 0, 1, selBlock.cols()) = res.
data.block(sel(0, l), 0, 1, selBlock.cols());
135 qWarning(
"FiffEvoked::pick_channels - Warning : Selected channel index out of bound.\n");
138 res.
data.resize(sel.cols(), res.
data.cols());
149 QPair<float, float> t_baseline,
153 p_FiffEvoked.
clear();
159 QString t_sFileName = t_pStream->streamName();
161 qInfo(
"Reading %s ...\n", t_sFileName.toUtf8().constData());
163 if (!t_pStream->open())
170 if (!t_pStream->read_meas_info(t_pStream->dirtree(),
info, meas))
172 info.filename = t_sFileName;
177 if (processed.size() == 0) {
178 qWarning(
"Could not find processed data");
182 QList<FiffDirNode::SPtr> evoked_node = meas->dir_tree_find(
FIFFB_EVOKED);
183 if (evoked_node.size() == 0) {
184 qWarning(
"Could not find evoked data");
189 if (!setno.isValid()) {
190 if (evoked_node.size() > 1) {
191 QStringList comments;
192 QList<fiff_int_t> aspect_kinds;
194 if (!t_pStream->get_evoked_entries(evoked_node, comments, aspect_kinds, t))
195 t = QString(
"None found, must use integer");
196 qWarning(
"%lld datasets present, setno parameter must be set. Candidate setno names:\n%s",
static_cast<long long>(evoked_node.size()), t.toUtf8().constData());
202 bool t_bIsInteger =
true;
203 setno.toInt(&t_bIsInteger);
206 qWarning(
"kindStat must be \"FIFFV_ASPECT_AVERAGE\" or \"FIFFV_ASPECT_STD_ERR\"");
210 QStringList comments;
211 QList<fiff_int_t> aspect_kinds;
213 t_pStream->get_evoked_entries(evoked_node, comments, aspect_kinds, t);
216 for (qint32 i = 0; i < comments.size(); ++i) {
217 if (comments[i].compare(setno.toString()) == 0 && p_aspect_kind == aspect_kinds[i]) {
224 qWarning() <<
"setno " << setno <<
" (" << p_aspect_kind <<
") not found, out of found datasets:\n " << t;
230 if (setno.toInt() >= evoked_node.size() || setno.toInt() < 0) {
231 qWarning(
"Data set selector out of range");
240 QList<FiffDirNode::SPtr> aspects = my_evoked->dir_tree_find(
FIFFB_ASPECT);
242 if (aspects.size() > 1)
243 qInfo(
"\tMultiple (%lld) aspects found. Taking first one.\n",
static_cast<long long>(aspects.size()));
252 QList<FiffChInfo> chs;
257 for (k = 0; k < my_evoked->nent(); ++k) {
258 kind = my_evoked->dir[k]->kind;
259 pos = my_evoked->dir[k]->pos;
262 t_pStream->read_tag(t_pTag, pos);
266 t_pStream->read_tag(t_pTag, pos);
267 first = *t_pTag->toInt();
270 t_pStream->read_tag(t_pTag, pos);
271 last = *t_pTag->toInt();
274 t_pStream->read_tag(t_pTag, pos);
275 nchan = *t_pTag->toInt();
278 t_pStream->read_tag(t_pTag, pos);
279 sfreq = *t_pTag->toFloat();
282 t_pStream->read_tag(t_pTag, pos);
283 chs.append(t_pTag->toChInfo());
288 comment = QString(
"No comment");
294 if (chs.size() == 0) {
295 qWarning(
"Local channel information was not found when it was expected.");
298 if (chs.size() != nchan) {
299 qWarning(
"Number of channels and number of channel definitions are different.");
304 qInfo(
"\tFound channel information in evoked data. nchan = %d\n", nchan);
309 qInfo(
"\tFound the data of interest:\n");
310 qInfo(
"\t\tt = %10.2f ... %10.2f ms (%s)\n", 1000 *
static_cast<float>(
first) /
info.sfreq, 1000 *
static_cast<float>(
last) /
info.sfreq,
comment.toUtf8().constData());
311 if (
info.comps.size() > 0)
312 qInfo(
"\t\t%lld CTF compensation matrices available\n",
static_cast<long long>(
info.comps.size()));
319 QList<FiffTag> epoch;
320 for (k = 0; k < my_aspect->nent(); ++k) {
321 kind = my_aspect->dir[k]->kind;
322 pos = my_aspect->dir[k]->pos;
326 t_pStream->read_tag(t_pTag, pos);
330 t_pStream->read_tag(t_pTag, pos);
334 t_pStream->read_tag(t_pTag, pos);
335 nave = *t_pTag->toInt();
338 t_pStream->read_tag(t_pTag, pos);
339 epoch.append(
FiffTag(*t_pTag));
347 qint32 nepoch = epoch.size();
348 if (nepoch != 1 && nepoch !=
info.nchan) {
349 qWarning(
"Number of epoch tags is unreasonable (nepoch = %d nchan = %d)", nepoch,
info.nchan);
357 all_data = epoch[0].toFloatMatrix().cast<
double>();
358 all_data.transposeInPlace();
362 if (all_data.cols() == 1 &&
info.nchan == 1)
363 all_data.transposeInPlace();
368 all_data.resize(nepoch, epoch[0].size() /
static_cast<int>(
sizeof(
float)));
369 for (k = 0; k < nepoch; ++k) {
370 const int n = epoch[k].size() /
static_cast<int>(
sizeof(float));
371 if (n != all_data.cols()) {
372 qWarning(
"Old style epochs have different lengths (%d and %d)", n, (
int)all_data.cols());
375 all_data.row(k) = Map<const RowVectorXf>(epoch[k].toFloat(), n).cast<
double>();
378 if (all_data.cols() != nsamp) {
379 qWarning(
"Incorrect number of samples (%d instead of %d)", (
int)all_data.cols(), nsamp);
386 qInfo(
"\n\tPreprocessing...\n");
387 qInfo(
"\t%d channels remain after picking\n",
info.nchan);
389 using T = Eigen::Triplet<double>;
390 std::vector<T> tripletList;
391 tripletList.reserve(
info.nchan);
392 for (k = 0; k <
info.nchan; ++k)
393 tripletList.push_back(T(k, k,
info.chs[k].cal));
394 SparseMatrix<double> cals(
info.nchan,
info.nchan);
395 cals.setFromTriplets(tripletList.begin(), tripletList.end());
397 all_data = cals * all_data;
400 for (k = 0; k <
times.size(); ++k)
406 if (
info.projs.size() == 0 || !
proj) {
407 qInfo(
"\tNo projector specified for these data.\n");
408 p_FiffEvoked.
proj = MatrixXd();
412 qint32 nproj =
info.make_projector(projection);
414 qWarning(
"\tThe projection vectors do not apply to these channels\n");
415 p_FiffEvoked.
proj = MatrixXd();
417 qInfo(
"\tCreated an SSP operator (subspace dimension = %d)\n", nproj);
418 p_FiffEvoked.
proj = projection;
425 if (p_FiffEvoked.
proj.rows() > 0) {
426 all_data = p_FiffEvoked.
proj * all_data;
427 qInfo(
"\tSSP projectors applied to the evoked data\n");
438 p_FiffEvoked.
data = all_data;
443 if (t_baseline.first != t_baseline.second) {
447 qInfo(
"\tNo baseline correction applied\n");