Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP [FIX] BabyMeg HPI Fitting #800

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions applications/mne_scan/plugins/hpi/hpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,13 @@ void Hpi::update(SCMEASLIB::Measurement::SPtr pMeasurement)
// Check if data is present
if(pRTMSA->getMultiSampleArray().size() > 0) {
//If bad channels changed, recalcluate projectors
updateProjections();
if(m_iNumberBadChannels != m_pFiffInfo->bads.size()
|| m_matCompProjectors.rows() == 0
|| m_matCompProjectors.cols() == 0) {
updateProjections();
m_iNumberBadChannels = m_pFiffInfo->bads.size();
}


m_mutex.lock();
bool bDoSingleHpi = m_bDoSingleHpi;
Expand Down Expand Up @@ -282,17 +288,6 @@ void Hpi::initPluginControlWidgets()
void Hpi::updateProjections()
{
if(m_pFiffInfo) {
m_mutex.lock();
if(m_iNumberBadChannels != m_pFiffInfo->bads.size()
|| m_matCompProjectors.rows() == 0
|| m_matCompProjectors.cols() == 0) {
m_iNumberBadChannels = m_pFiffInfo->bads.size();
} else {
m_mutex.unlock();
return;
}
m_mutex.unlock();

Eigen::MatrixXd matProjectors = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size());
Eigen::MatrixXd matComp = Eigen::MatrixXd::Identity(m_pFiffInfo->chs.size(), m_pFiffInfo->chs.size());

Expand Down Expand Up @@ -324,6 +319,7 @@ void Hpi::updateProjections()
}

m_mutex.lock();
m_matProjectors = matProjectors;
m_matCompProjectors = matProjectors * matComp;
m_mutex.unlock();
}
Expand Down Expand Up @@ -360,7 +356,7 @@ void Hpi::onAllowedRotationChanged(double dAllowedRotation)

void Hpi::onDigitizersChanged(const QList<FIFFLIB::FiffDigPoint>& lDigitzers,
const QString& sFilePath)
{
{
m_mutex.lock();
if(m_pFiffInfo) {
m_pFiffInfo->dig = lDigitzers;
Expand Down Expand Up @@ -493,6 +489,7 @@ void Hpi::run()
m_mutex.unlock();

MatrixXd matDataMerged(m_pFiffInfo->chs.size(), int(m_pFiffInfo->sfreq/iNumberOfFitsPerSecond));
MatrixXd matDataProj(m_pFiffInfo->chs.size(), int(m_pFiffInfo->sfreq/iNumberOfFitsPerSecond));

while(!isInterruptionRequested()) {
m_mutex.lock();
Expand Down Expand Up @@ -522,8 +519,9 @@ void Hpi::run()
m_mutex.lock();
if(m_bDoFreqOrder) {
// find correct frequencie order if requested
HPI.findOrder(matDataMerged,
m_matCompProjectors,
matDataProj = m_matCompProjectors * matDataMerged;
HPI.findOrder(matDataProj,
m_matProjectors,
fitResult.devHeadTrans,
m_vCoilFreqs,
fitResult.errorDistances,
Expand All @@ -536,8 +534,9 @@ void Hpi::run()

// Perform actual fitting
m_mutex.lock();
HPI.fitHPI(matDataMerged,
m_matCompProjectors,
matDataProj = m_matCompProjectors * matDataMerged;
HPI.fitHPI(matDataProj,
m_matProjectors,
fitResult.devHeadTrans,
m_vCoilFreqs,
fitResult.errorDistances,
Expand Down
1 change: 1 addition & 0 deletions applications/mne_scan/plugins/hpi/hpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ class HPISHARED_EXPORT Hpi : public SCSHAREDLIB::AbstractAlgorithm

Eigen::MatrixXd m_matData; /**< The last data block.*/
Eigen::MatrixXd m_matCompProjectors; /**< Holds the matrix with the SSP and compensator projectors.*/
Eigen::MatrixXd m_matProjectors; /**< Holds the matrix with the SSP.*/

QSharedPointer<FIFFLIB::FiffInfo> m_pFiffInfo; /**< Fiff measurement info.*/
QSharedPointer<UTILSLIB::CircularBuffer_Matrix_double> m_pCircularBuffer; /**< Holds incoming raw data. */
Expand Down
2 changes: 1 addition & 1 deletion libraries/inverse/hpiFit/hpifit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void HPIFit::fitHPI(const MatrixXd& t_mat,
for (int j = 0; j < iNumCoils; j++) {
int iChIdx = 0;
VectorXd::Index indMax;
matAmp.col(j).maxCoeff(&indMax);
matAmp.col(j).cwiseAbs().maxCoeff(&indMax);
if(indMax < m_vecInnerind.size()) {
iChIdx = m_vecInnerind.at(indMax);
}
Expand Down