Skip to content

Commit

Permalink
Added unit conversion when needed
Browse files Browse the repository at this point in the history
Refs #11326
  • Loading branch information
DanNixon committed Mar 30, 2015
1 parent f67359f commit bc5c36c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
Expand Up @@ -35,7 +35,6 @@ namespace IDA
virtual void loadSettings(const QSettings & settings);

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

Ui::ApplyCorr m_uiForm;
Expand Down
Expand Up @@ -67,6 +67,8 @@ namespace IDA
/// Check the binning between two workspaces match
bool checkWorkspaceBinningMatches(Mantid::API::MatrixWorkspace_const_sptr left,
Mantid::API::MatrixWorkspace_const_sptr right);
/// Adds a conversion to wavelength step to the algorithm queue
std::string addConvertToWavelengthStep(Mantid::API::MatrixWorkspace_sptr ws);

/// DoubleEditorFactory
DoubleEditorFactory* m_dblEdFac;
Expand Down
29 changes: 2 additions & 27 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/ApplyCorr.cpp
Expand Up @@ -71,7 +71,7 @@ namespace IDA
if(sampleXUnit->caption() != "Wavelength")
{
g_log.information("Sample workspace not in wavelength, need to convert to continue.");
absCorProps["SampleWorkspace"] = addUnitConversionStep(sampleWs);
absCorProps["SampleWorkspace"] = addConvertToWavelengthStep(sampleWs);
}
else
{
Expand All @@ -89,7 +89,7 @@ namespace IDA
if(canXUnit->caption() != "Wavelength")
{
g_log.information("Container workspace not in wavelength, need to convert to continue.");
absCorProps["CanWorkspace"] = addUnitConversionStep(canWs);
absCorProps["CanWorkspace"] = addConvertToWavelengthStep(canWs);
}
else
{
Expand Down Expand Up @@ -208,31 +208,6 @@ namespace IDA
}


/**
* Adds a unit converstion step to the batch algorithm queue.
*
* @param ws Pointer to the workspace to convert
* @return Name of output workspace
*/
std::string ApplyCorr::addUnitConversionStep(MatrixWorkspace_sptr ws)
{
std::string outputName = ws->name() + "_inWavelength";

IAlgorithm_sptr convertAlg = AlgorithmManager::Instance().create("ConvertUnits");
convertAlg->initialize();

convertAlg->setProperty("InputWorkspace", ws->name());
convertAlg->setProperty("OutputWorkspace", outputName);
convertAlg->setProperty("Target", "Wavelength");
convertAlg->setProperty("EMode", getEMode(ws));
convertAlg->setProperty("EFixed", getEFixed(ws));

m_batchAlgoRunner->addAlgorithm(convertAlg);

return outputName;
}


/**
* Adds a rebin to workspace step to the calculation for when using a sample and container that
* have different binning.
Expand Down
32 changes: 27 additions & 5 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/CalcCorr.cpp
Expand Up @@ -45,19 +45,29 @@ namespace IDA

void CalcCorr::run()
{
//TODO: check sample binning matches can binning, ask if should rebin to match

// Get correct corrections algorithm
QString sampleShape = m_uiForm.cbSampleShape->currentText();
QString algorithmName = sampleShape.replace(" ", "") + "PaalmanPingsCorrection";

API::BatchAlgorithmRunner::AlgorithmRuntimeProps absCorProps;
IAlgorithm_sptr absCorAlgo = AlgorithmManager::Instance().create(algorithmName.toStdString());
absCorAlgo->initialize();

// Sample details
QString sampleWsName = m_uiForm.dsSample->getCurrentDataName();
MatrixWorkspace_sptr sampleWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(sampleWsName.toStdString());
absCorAlgo->setProperty("SampleWorkspace", sampleWsName.toStdString());

// If not in wavelength then do conversion
Mantid::Kernel::Unit_sptr sampleXUnit = sampleWs->getAxis(0)->unit();
if(sampleXUnit->caption() != "Wavelength")
{
g_log.information("Sample workspace not in wavelength, need to convert to continue.");
absCorProps["SampleWorkspace"] = addConvertToWavelengthStep(sampleWs);
}
else
{
absCorProps["SampleWorkspace"] = sampleWsName.toStdString();
}

double sampleNumberDensity = m_uiForm.spSampleNumberDensity->value();
absCorAlgo->setProperty("SampleNumberDensity", sampleNumberDensity);
Expand All @@ -72,7 +82,19 @@ namespace IDA
if(useCan)
{
QString canWsName = m_uiForm.dsContainer->getCurrentDataName();
absCorAlgo->setProperty("CanWorkspace", canWsName.toStdString());
MatrixWorkspace_sptr canWs = AnalysisDataService::Instance().retrieveWS<MatrixWorkspace>(canWsName.toStdString());

// If not in wavelength then do conversion
Mantid::Kernel::Unit_sptr canXUnit = canWs->getAxis(0)->unit();
if(canXUnit->caption() != "Wavelength")
{
g_log.information("Container workspace not in wavelength, need to convert to continue.");
absCorProps["CanWorkspace"] = addConvertToWavelengthStep(canWs);
}
else
{
absCorProps["CanWorkspace"] = canWsName.toStdString();
}

double canNumberDensity = m_uiForm.spCanNumberDensity->value();
absCorAlgo->setProperty("CanNumberDensity", canNumberDensity);
Expand Down Expand Up @@ -106,7 +128,7 @@ namespace IDA
absCorAlgo->setProperty("OutputWorkspace", outputWsName.toStdString());

// Add corrections algorithm to queue
m_batchAlgoRunner->addAlgorithm(absCorAlgo);
m_batchAlgoRunner->addAlgorithm(absCorAlgo, absCorProps);

// Add save algorithms if required
bool save = m_uiForm.ckSave->isChecked();
Expand Down
28 changes: 28 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/IDATab.cpp
Expand Up @@ -32,6 +32,7 @@ namespace IDA
m_blnEdFac = new QtCheckBoxFactory(this);
}


/**
* Loads the tab's settings.
*
Expand All @@ -44,6 +45,7 @@ namespace IDA
loadSettings(settings);
}


/**
* Slot that can be called when a user edits an input.
*/
Expand All @@ -52,6 +54,7 @@ namespace IDA
validate();
}


/**
* Check that the binning between two workspaces matches.
*
Expand All @@ -74,6 +77,31 @@ namespace IDA
}
}


/**
* Adds a unit converstion into wavelength step to the batch algorithm queue.
*
* @param ws Pointer to the workspace to convert
* @return Name of output workspace
*/
std::string IDATab::addConvertToWavelengthStep(MatrixWorkspace_sptr ws)
{
std::string outputName = ws->name() + "_inWavelength";

IAlgorithm_sptr convertAlg = AlgorithmManager::Instance().create("ConvertUnits");
convertAlg->initialize();

convertAlg->setProperty("InputWorkspace", ws->name());
convertAlg->setProperty("OutputWorkspace", outputName);
convertAlg->setProperty("Target", "Wavelength");
convertAlg->setProperty("EMode", getEMode(ws));
convertAlg->setProperty("EFixed", getEFixed(ws));

m_batchAlgoRunner->addAlgorithm(convertAlg);

return outputName;
}

} // namespace IDA
} // namespace CustomInterfaces
} // namespace MantidQt

0 comments on commit bc5c36c

Please sign in to comment.