125 qint32 first_comp = -1;
128 for (k = 0; k < this->
nchan; ++k)
132 comp = this->
chs[k].chpos.coil_type >> 16;
135 else if (comp != first_comp)
136 qWarning(
"Compensation is not set equally on all MEG channels");
146 MatrixXd C1, C2, comp_tmp;
164 qWarning(
"Cannot create compensator C1\n");
165 qWarning(
"Desired compensation matrix (kind = %d) not found\n",from);
176 qWarning(
"Cannot create compensator C2\n");
177 qWarning(
"Desired compensation matrix (kind = %d) not found\n",to);
186 comp_tmp = MatrixXd::Identity(this->
nchan,this->
nchan) + C1 - C2 - C2*C1;
189 if (exclude_comp_chs)
191 VectorXi pick = MatrixXi::Zero(1,this->
nchan);
193 for (k = 0; k < this->
nchan; ++k)
203 qWarning(
"Nothing remains after excluding the compensation channels\n");
207 ctf_comp.data->data.resize(npick,this->nchan);
208 for (k = 0; k < npick; ++k)
209 ctf_comp.data->data.row(k) = comp_tmp.block(pick(k), 0, 1, this->nchan);
222 MatrixXd presel, postsel;
223 qint32 k, col, c, ch=0, row, row_ch=0, channelAvailable;
225 for (k = 0; k < this->comps.size(); ++k)
227 if (this->comps[k].kind == kind)
229 this_data = this->comps[k].data;
234 presel = MatrixXd::Zero(this_data->ncol,this->nchan);
236 for(col = 0; col < this_data->ncol; ++col)
238 channelAvailable = 0;
239 for (c = 0; c < this->ch_names.size(); ++c)
241 if (QString::compare(this_data->col_names.at(col),this->ch_names.at(c)) == 0)
247 if (channelAvailable == 0)
249 qWarning(
"Channel %s is not available in data\n",this_data->col_names.at(col).toUtf8().constData());
252 else if (channelAvailable > 1)
254 qWarning(
"Ambiguous channel %s",this_data->col_names.at(col).toUtf8().constData());
257 presel(col,ch) = 1.0;
262 postsel = MatrixXd::Zero(this->nchan,this_data->nrow);
264 for (c = 0; c < this->nchan; ++c)
266 channelAvailable = 0;
267 for (row = 0; row < this_data->row_names.size(); ++row)
269 if (QString::compare(this->ch_names.at(c),this_data->row_names.at(row)) == 0)
275 if (channelAvailable > 1)
277 qWarning(
"Ambiguous channel %s", this->ch_names.at(c).toUtf8().constData());
280 else if (channelAvailable == 1)
282 postsel(c,row_ch) = 1.0;
285 this_comp = postsel*this_data->data*presel;
289 this_comp = defaultMatrixXd;
306 for(qint32 i = 0; i < sel.size(); ++i)
309 res.
chs.append(this->
chs[idx]);
312 res.
nchan =
static_cast<int>(sel.size());
321 QList<FiffChInfo> newList;
323 fiff_int_t coil_type;
325 for(k = 0; k < listFiffChInfo.size(); ++k)
326 newList.append(listFiffChInfo[k]);
328 qint32 lower_half = 65535;
329 for (k = 0; k < listFiffChInfo.size(); ++k)
333 coil_type = listFiffChInfo[k].chpos.coil_type & lower_half;
334 newList[k].chpos.coil_type = (coil_type | (value << 16));
345 const QStringList&
bads,
346 QList<FiffChInfo>& chsp,
358 if (!stream->read_meas_info(stream->dirtree(), info, infoNode)) {
359 qCritical(
"%s : could not read measurement info", name.toUtf8().data());
365 QList<FiffChInfo> meg;
366 QList<FiffChInfo> eeg;
368 for (
int k = 0; k < info.
chs.size(); k++) {
369 if (
bads.contains(info.
chs[k].ch_name))
372 meg.append(info.
chs[k]);
373 else if (do_eeg && info.
chs[k].isValidEeg())
374 eeg.append(info.
chs[k]);
378 chsp.reserve(meg.size() + eeg.size());
394 fiff_int_t data_type = 4;
396 QList<FiffChInfo>
chs;
398 for(k = 0; k < this->nchan; ++k)
408 if(this->
meas_id.version != -1)
422 bool have_hpi_result =
false;
423 bool have_isotrak =
false;
427 if (!this->
acq_pars.isEmpty() || !this->acq_stim.isEmpty())
441 if (!have_hpi_result)
452 if (this->
dig.size() > 0 && !have_isotrak)
455 for (qint32 k = 0; k < this->
dig.size(); ++k)
471 if (this->
bads.size() > 0)
497 MatrixXd cals(1,
nchan);
499 for(k = 0; k <
nchan; ++k)
506 cals(0,k) =
static_cast<double>(
chs[k].cal);
518 std::cout <<
"Sample frequency: " <<
sfreq <<
"\n";
520 std::cout <<
"Number of digitizer points: " <<
dig.size() <<
"\n";
521 for (
auto& point :
dig){
523 std::cout <<
"HPI Point " << point.ident <<
" - " << point.r[0] <<
", " << point.r[1] <<
", " << point.r[2] <<
"\n";
Header-only Eigen matrix text I/O — round-trips dense matrices to whitespace-separated ASCII for cros...
#define FIFF_MNE_CH_NAME_LIST
#define FIFFB_MNE_BAD_CHANNELS
Full FIFF measurement metadata: everything from FIFFB_MEAS / FIFFB_MEAS_INFO needed to interpret a re...
FIFF tag-kind, block-kind and type-code numerical definitions, authoritative for FIFFLIB.
#define FIFF_GANTRY_ANGLE
#define FIFF_PARENT_BLOCK_ID
#define FIFF_EXPERIMENTER
FIFF binary tag-stream layer: wraps a QIODevice to read and write FIFF tags, directories,...
FIFF file I/O, in-memory data structures and high-level readers/writers.
Shared utilities (I/O helpers, spectral analysis, layout management, warp algorithms).
One CTF software-gradient compensation matrix: grade kind, calibration flag and the gradiometer × ref...
QSharedPointer< FiffDirNode > SPtr
128-bit FIFF identifier: hardware machine ID plus creation time, stamped on every file and block.
FiffInfo pick_info(const Eigen::RowVectorXi &sel=defaultVectorXi) const
void set_current_comp(fiff_int_t value)
static bool readMegEegChannels(const QString &name, bool do_meg, bool do_eeg, const QStringList &bads, QList< FiffChInfo > &chsp, int &nmegp, int &neegp)
void writeToStream(FiffStream *p_pStream) const
QList< FiffCtfComp > comps
qint32 get_current_comp()
bool make_compensator(fiff_int_t from, fiff_int_t to, FiffCtfComp &ctf_comp, bool exclude_comp_chs=false) const
QList< FiffDigPoint > dig
FiffCoordTrans ctf_head_t
FiffCoordTrans dev_head_t
QSharedDataPointer< FiffNamedMatrix > SDPtr
FIFF tag-stream reader/writer: wraps a QIODevice and exposes typed read_* / write_* methods for every...
fiff_long_t start_block(fiff_int_t kind)
fiff_long_t write_proj(const QList< FiffProj > &projs)
QSharedPointer< FiffStream > SPtr
fiff_long_t write_dig_point(const FiffDigPoint &dig)
fiff_long_t write_int(fiff_int_t kind, const fiff_int_t *data, fiff_int_t nel=1, fiff_int_t next=FIFFV_NEXT_SEQ)
fiff_long_t write_float(fiff_int_t kind, const float *data, fiff_int_t nel=1)
fiff_long_t write_id(fiff_int_t kind, const FiffId &id=FiffId::getDefault())
fiff_long_t write_coord_trans(const FiffCoordTrans &trans)
fiff_long_t write_name_list(fiff_int_t kind, const QStringList &data)
fiff_long_t write_string(fiff_int_t kind, const QString &data)
fiff_long_t end_block(fiff_int_t kind, fiff_int_t next=FIFFV_NEXT_SEQ)
fiff_long_t write_ch_info(const FiffChInfo &ch)
fiff_long_t write_ctf_comp(const QList< FiffCtfComp > &comps)