From a7d652c67e561dcc9afcfd56272766deb2e531e8 Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Fri, 27 Mar 2015 13:55:14 +0000 Subject: [PATCH] Add interpolation options for old corrections Refs #11326 --- .../Indirect/ApplyCorr.h | 1 + .../src/Indirect/ApplyCorr.cpp | 55 ++++++++++++++++++- 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h index 2d3d79700777..c5e5efab67ae 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h +++ b/Code/Mantid/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/Indirect/ApplyCorr.h @@ -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; diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp index 95ef96f1f1e6..48b45f8dc210 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp @@ -109,15 +109,42 @@ namespace IDA QString correctionsWsName = m_uiForm.dsCorrections->getCurrentDataName(); WorkspaceGroup_sptr corrections = AnalysisDataService::Instance().retrieveWS(correctionsWsName.toStdString()); + bool interpolateAll = false; for(size_t i = 0; i < corrections->size(); i++) { MatrixWorkspace_sptr factorWs = boost::dynamic_pointer_cast(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; + } } } @@ -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. *