Skip to content

Commit

Permalink
Added use of algorithm to UI
Browse files Browse the repository at this point in the history
Refs #9345
  • Loading branch information
DanNixon committed Aug 22, 2014
1 parent 62602d9 commit 097bb3d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 43 deletions.
Expand Up @@ -24,7 +24,7 @@ def PyInit(self):
doc='Input workspace')

valid_functions = ['ChudleyElliot', 'HallRoss', 'FickDiffusion', 'TeixeiraWater']
self.declareProperty(name='JumpFunction', defaultValue=valid_functions[0],
self.declareProperty(name='Function', defaultValue=valid_functions[0],
validator=StringListValidator(valid_functions),
doc='') ##TODO

Expand All @@ -44,7 +44,7 @@ def PyExec(self):
in_ws = self.getPropertyValue('InputWorkspace')
out_name = self.getPropertyValue('Output')

jump_function = self.getProperty('JumpFunction').value
jump_function = self.getProperty('Function').value
width = self.getProperty('Width').value
q_min = self.getProperty('QMin').value
q_max = self.getProperty('QMax').value
Expand Down
Expand Up @@ -3,6 +3,7 @@

#include "MantidAPI/MatrixWorkspace.h"
#include "MantidQtMantidWidgets/RangeSelector.h"
#include "MantidQtAPI/AlgorithmRunner.h"
#include "MantidQtAPI/QwtWorkspaceSpectrumData.h"

#include <QMap>
Expand Down Expand Up @@ -42,7 +43,7 @@ namespace MantidQt
This class defines a abstract base class for the different tabs of the Indirect Bayes interface.
Any joint functionality shared between each of the tabs should be implemented here as well as defining
shared member functions.
@author Samuel Jackson, STFC
Copyright &copy; 2013 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
Expand Down Expand Up @@ -112,17 +113,19 @@ namespace MantidQt
/// Function to run a string as python code
void runPythonScript(const QString& pyInput);
/// Function to read an instrument's resolution from the IPF using a string
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
bool getInstrumentResolution(const QString& filename, std::pair<double,double>& res);
/// Function to read an instrument's resolution from the IPF using a workspace pointer
bool getInstrumentResolution(Mantid::API::MatrixWorkspace_const_sptr ws, std::pair<double,double>& res);
/// Function to set the range limits of the plot
void setPlotRange(QtProperty* min, QtProperty* max, const std::pair<double, double>& bounds);
/// Function to set the position of the lower guide on the plot
void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value);
void updateLowerGuide(QtProperty* lower, QtProperty* upper, double value);
/// Function to set the position of the upper guide on the plot
void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value);
void updateUpperGuide(QtProperty* lower, QtProperty* upper, double value);
/// Function to get the range of the curve displayed on the mini plot
std::pair<double,double> getCurveRange();
/// Run an algorithm async
void runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm);

/// Plot of the input
QwtPlot* m_plot;
Expand All @@ -138,9 +141,11 @@ namespace MantidQt
QtDoublePropertyManager* m_dblManager;
/// Double editor facotry for the properties browser
DoubleEditorFactory* m_dblEdFac;
/// Algorithm runner object to execute algorithms on a seperate thread from the gui
MantidQt::API::AlgorithmRunner* m_algRunner;

};
} // namespace CustomInterfaces
} // namespace Mantid

#endif
#endif
Expand Up @@ -37,10 +37,10 @@ namespace MantidQt
void findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws);

private:
//The ui form
// The UI form
Ui::JumpFit m_uiForm;
// map of axis labels to spectrum number
std::map<std::string,int> spectraList;
// Map of axis labels to spectrum number
std::map<std::string, int> m_spectraList;

};
} // namespace CustomInterfaces
Expand Down
14 changes: 13 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Expand Up @@ -15,7 +15,8 @@ namespace MantidQt
IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent),
m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_rangeSelector(new MantidWidgets::RangeSelector(m_plot)),
m_propTree(new QtTreePropertyBrowser()), m_properties(), m_dblManager(new QtDoublePropertyManager()),
m_dblEdFac(new DoubleEditorFactory())
m_dblEdFac(new DoubleEditorFactory()),
m_algRunner(new MantidQt::API::AlgorithmRunner(parent))
{
m_propTree->setFactoryForManager(m_dblManager, m_dblEdFac);
m_rangeSelector->setInfoOnly(false);
Expand Down Expand Up @@ -58,6 +59,17 @@ namespace MantidQt
emit executePythonScript(pyInput, true);
}

/**
* Runs an algorithm async
*
* @param algorithm :: The algorithm to be run
*/
void IndirectBayesTab::runAlgorithm(const Mantid::API::IAlgorithm_sptr algorithm)
{
algorithm->setRethrows(true);
m_algRunner->startAlgorithm(algorithm);
}

/**
* Plot a workspace to the miniplot given a workspace name and
* a specturm index.
Expand Down
65 changes: 33 additions & 32 deletions Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp
@@ -1,3 +1,4 @@
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/Run.h"
#include "MantidAPI/TextAxis.h"
#include "MantidQtCustomInterfaces/JumpFit.h"
Expand Down Expand Up @@ -48,7 +49,7 @@ namespace MantidQt
uiv.checkDataSelectorIsValid("Sample", m_uiForm.dsSample);

//this workspace doesn't have any valid widths
if(spectraList.size() == 0)
if(m_spectraList.size() == 0)
{
uiv.addErrorMessage("Input workspace doesn't appear to contain any width data.");
}
Expand All @@ -69,50 +70,51 @@ namespace MantidQt
*/
void JumpFit::run()
{
QString verbose("False");
QString plot("False");
QString save("False");

QString sample = m_uiForm.dsSample->getCurrentDataName();
using namespace Mantid::API;

//fit function to use
QString fitFunction("CE");
// Fit function to use
QString fitFunction("ChudleyElliot");
switch(m_uiForm.cbFunction->currentIndex())
{
case 0:
fitFunction = "CE"; // Use Chudley-Elliott
fitFunction = "ChudleyElliot";
break;
case 1:
fitFunction = "HallRoss";
break;
case 2:
fitFunction = "Fick";
fitFunction = "FickDiffusion";
break;
case 3:
fitFunction = "Teixeira";
fitFunction = "TeixeiraWater";
break;
}

// Loaded workspace name
QString sample = m_uiForm.dsSample->getCurrentDataName();
auto ws = Mantid::API::AnalysisDataService::Instance().retrieve(sample.toStdString());

std::string widthText = m_uiForm.cbWidth->currentText().toStdString();
int width = spectraList[widthText];
QString widthTxt = boost::lexical_cast<std::string>(width).c_str();
long width = m_spectraList[widthText];

// Cropping values
QString QMin = m_properties["QMin"]->valueText();
QString QMax = m_properties["QMax"]->valueText();
IAlgorithm_sptr fitAlg = AlgorithmManager::Instance().create("JumpFit");
fitAlg->initialize();

//output options
if(m_uiForm.chkVerbose->isChecked()) { verbose = "True"; }
if(m_uiForm.chkSave->isChecked()) { save = "True"; }
if(m_uiForm.chkPlot->isChecked()) { plot = "True"; }
fitAlg->setProperty("InputWorkspace", ws);
fitAlg->setProperty("Function", fitFunction.toStdString());

QString pyInput =
"from IndirectJumpFit import JumpRun\n";
fitAlg->setProperty("Width", width);
fitAlg->setProperty("QMin", m_dblManager->value(m_properties["QMin"]));
fitAlg->setProperty("QMax", m_dblManager->value(m_properties["QMax"]));

pyInput += "JumpRun('"+sample+"','"+fitFunction+"',"+widthTxt+","+QMin+","+QMax+","
"Save="+save+", Plot="+plot+", Verbose="+verbose+")\n";
bool verbose = m_uiForm.chkVerbose->isChecked();
bool save = m_uiForm.chkSave->isChecked();
bool plot = m_uiForm.chkPlot->isChecked();
fitAlg->setProperty("Plot", plot);
fitAlg->setProperty("Verbose", verbose);
fitAlg->setProperty("Save", save);

runPythonScript(pyInput);
runAlgorithm(fitAlg);
}

/**
Expand All @@ -134,18 +136,17 @@ namespace MantidQt
*/
void JumpFit::handleSampleInputReady(const QString& filename)
{

auto ws = Mantid::API::AnalysisDataService::Instance().retrieve(filename.toStdString());
auto mws = boost::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(ws);

findAllWidths(mws);

if(spectraList.size() > 0)
if(m_spectraList.size() > 0)
{
m_uiForm.cbWidth->setEnabled(true);

std::string currentWidth = m_uiForm.cbWidth->currentText().toStdString();
plotMiniPlot(filename, spectraList[currentWidth]);
plotMiniPlot(filename, m_spectraList[currentWidth]);
std::pair<double,double> res;
std::pair<double,double> range = getCurveRange();

Expand Down Expand Up @@ -176,7 +177,7 @@ namespace MantidQt
void JumpFit::findAllWidths(Mantid::API::MatrixWorkspace_const_sptr ws)
{
m_uiForm.cbWidth->clear();
spectraList.clear();
m_spectraList.clear();

for (size_t i = 0; i < ws->getNumberHistograms(); ++i)
{
Expand Down Expand Up @@ -206,7 +207,7 @@ namespace MantidQt
}

cbItemName = title.substr(0, substrIndex);
spectraList[cbItemName] = static_cast<int>(i);
m_spectraList[cbItemName] = static_cast<int>(i);
m_uiForm.cbWidth->addItem(QString(cbItemName.c_str()));

//display widths f1.f1, f2.f1 and f2.f2
Expand All @@ -228,11 +229,11 @@ namespace MantidQt
QString sampleName = m_uiForm.dsSample->getCurrentDataName();
QString samplePath = m_uiForm.dsSample->getFullFilePath();

if(!sampleName.isEmpty() && spectraList.size() > 0)
if(!sampleName.isEmpty() && m_spectraList.size() > 0)
{
if(validate())
{
plotMiniPlot(sampleName, spectraList[text.toStdString()]);
plotMiniPlot(sampleName, m_spectraList[text.toStdString()]);
}
}
}
Expand Down

0 comments on commit 097bb3d

Please sign in to comment.