Skip to content

Commit

Permalink
Add interpolation options for old corrections
Browse files Browse the repository at this point in the history
Refs #11326
  • Loading branch information
DanNixon committed Mar 27, 2015
1 parent 7319e7b commit a7d652c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
Expand Up @@ -35,6 +35,7 @@ namespace IDA
virtual void loadSettings(const QSettings & settings);

std::string addUnitConversionStep(Mantid::API::MatrixWorkspace_sptr ws);
void addInterpolationStep(Mantid::API::MatrixWorkspace_sptr toInterpolate, std::string toMatch);

Ui::ApplyCorr m_uiForm;

Expand Down
55 changes: 52 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp
Expand Up @@ -109,15 +109,42 @@ namespace IDA
QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName();

WorkspaceGroup_sptr corrections = AnalysisDataService::Instance().retrieveWS<WorkspaceGroup>(correctionsWsName.toStdString());
bool interpolateAll = false;
for(size_t i = 0; i < corrections->size(); i++)
{
MatrixWorkspace_sptr factorWs = boost::dynamic_pointer_cast<MatrixWorkspace>(corrections->getItem(i));

// Check for matching binning
if(sampleWs && !checkWorkspaceBinningMatches(sampleWs, factorWs))
if(sampleWs && (sampleWs->blocksize() != factorWs->blocksize()))
{
//TODO
throw std::runtime_error("Binning");
int result;
if(interpolateAll)
{
result = QMessageBox::Yes;
}
else
{
QString text = "Number of bins on sample and "
+ QString::fromStdString(factorWs->name())
+ " workspace does not match.\n"
+ "Would you like to interpolate this workspace to match the sample?";

result = QMessageBox::question(NULL, tr("Interpolate corrections?"), tr(text),
QMessageBox::YesToAll, QMessageBox::Yes, QMessageBox::No);
}

switch(result)
{
case QMessageBox::YesToAll:
interpolateAll = true;
case QMessageBox::Yes:
addInterpolationStep(factorWs, absCorProps["SampleWorkspace"]);
break;
default:
m_batchAlgoRunner->clearQueue();
g_log.error("ApplyCorr cannot run with corrections that do not match sample binning.");
return;
}
}
}

Expand Down Expand Up @@ -177,6 +204,28 @@ namespace IDA
}


/**
* Adds a spline interpolation as a step in the calculation for using legacy correction factor
* workspaces.
*
* @param toInterpolate Pointer to the workspace to interpolate
* @param toMatch Name of the workspace to match
*/
void ApplyCorr::addInterpolationStep(MatrixWorkspace_sptr toInterpolate, std::string toMatch)
{
API::BatchAlgorithmRunner::AlgorithmRuntimeProps interpolationProps;
interpolationProps["WorkspaceToMatch"] = toMatch;

IAlgorithm_sptr interpolationAlg = AlgorithmManager::Instance().create("SplineInterpolation");
interpolationAlg->initialize();

interpolationAlg->setProperty("WorkspaceToInterpolate", toInterpolate->name());
interpolationAlg->setProperty("OutputWorkspace", toInterpolate->name());

m_batchAlgoRunner->addAlgorithm(interpolationAlg, interpolationProps);
}


/**
* Handles completion of the algorithm.
*
Expand Down

0 comments on commit a7d652c

Please sign in to comment.