Skip to content

Commit

Permalink
Refs #5421 Hooked up ResNorm to underlying python script.
Browse files Browse the repository at this point in the history
This includes setting up the supporting code for the rest of
the Bayes interface.
  • Loading branch information
Samuel Jackson committed Sep 12, 2013
1 parent 174bbaa commit 842879d
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/IndirectBayesTab.h"

#include <QDesktopServices>
#include <QUrl>

namespace MantidQt
{
namespace CustomInterfaces
Expand Down Expand Up @@ -61,6 +64,12 @@ namespace MantidQt
static std::string name() { return "Indirect Bayes"; }
virtual void initLayout();

private slots:
/// Run the appropriate action depending based on the selected tab
void runClicked();
void helpClicked();
void manageUserDirectories();

private:
std::map<unsigned int, IndirectBayesTab*> m_bayesTabs;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_
#define MANTID_CUSTOMINTERFACES_INDIRECTBAYESTAB_H_

#include "MantidKernel/System.h"
#include "MantidAPI/MatrixWorkspace.h"

#include <QMap>
#include <QtDoublePropertyManager>
Expand Down Expand Up @@ -56,13 +56,28 @@ namespace MantidQt
IndirectBayesTab(QWidget * parent = 0);
~IndirectBayesTab();

virtual void help() = 0;
virtual void validate() = 0;
QString tabHelpURL();

virtual QString help() = 0;
virtual bool validate() = 0;
virtual void run() = 0;

signals:
/// Send signal to parent window to execute python script
void executePythonScript(const QString& pyInput, bool output);

protected:
/// Function to plot a workspace to the miniplot using a workspace name
void plotMiniPlot(const QString& workspace, size_t index);
/// Function to plot a workspace to the miniplot using a workspace pointer
void plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex);
/// Function to run a string as python code
void runPythonScript(const QString& pyInput);

/// Plot of the input
QwtPlot* m_plot;
/// Curve on the plot
QwtPlotCurve* m_curve;
/// Tree of the properties
QtTreePropertyBrowser* m_propTree;
/// Internal list of the properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace MantidQt
JumpFit(QWidget * parent = 0);

private:
virtual void help();
virtual void validate();
virtual QString help() { return "JumpFit"; };
virtual bool validate();
virtual void run();

//The ui form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace MantidQt
Quasi(QWidget * parent = 0);

private:
virtual void help();
virtual void validate();
virtual QString help() { return "Quasi"; };
virtual bool validate();
virtual void run();

//The ui form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ namespace MantidQt
public:
ResNorm(QWidget * parent = 0);

private slots:
/// Handle when the vanadium input is ready
void handleVanadiumInputReady(const QString& filename);

private:
virtual void help();
virtual void validate();
/// Inherited methods from IndirectBayesTab
virtual QString help() { return "ResNorm"; };
virtual bool validate();
virtual void run();

//The ui form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</property>
<property name="fileBrowserSuffixes" stdset="0">
<stringlist>
<string>*_res.nxs</string>
<string>*_red.nxs</string>
</stringlist>
</property>
</widget>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace MantidQt
Stretch(QWidget * parent = 0);

private:
virtual void help();
virtual void validate();
virtual QString help() { return "Stretch"; };
virtual bool validate();
virtual void run();

//The ui form
Expand Down
36 changes: 36 additions & 0 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayes.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "MantidQtAPI/ManageUserDirectories.h"
#include "MantidQtCustomInterfaces/IndirectBayes.h"
#include "MantidQtCustomInterfaces/JumpFit.h"
#include "MantidQtCustomInterfaces/Quasi.h"
Expand All @@ -24,12 +25,47 @@ IndirectBayes::IndirectBayes(QWidget *parent) : UserSubWindow(parent)
m_bayesTabs.insert(std::make_pair(QUASI, new Quasi(m_uiForm.indirectBayesTabs->widget(QUASI))));
m_bayesTabs.insert(std::make_pair(STRETCH, new Stretch(m_uiForm.indirectBayesTabs->widget(STRETCH))));
m_bayesTabs.insert(std::make_pair(JUMP_FIT, new JumpFit(m_uiForm.indirectBayesTabs->widget(JUMP_FIT))));

//Connect each tab to the python execution method
std::map<unsigned int, IndirectBayesTab*>::iterator iter;
for (iter = m_bayesTabs.begin(); iter != m_bayesTabs.end(); ++iter)
{
connect(iter->second, SIGNAL(executePythonScript(const QString&, bool)), this, SIGNAL(runAsPythonScript(const QString&, bool)));
}

connect(m_uiForm.pbRun, SIGNAL(clicked()), this, SLOT(runClicked()));
connect(m_uiForm.pbHelp, SIGNAL(clicked()), this, SLOT(helpClicked()));
connect(m_uiForm.pbManageDirs, SIGNAL(clicked()), this, SLOT(manageUserDirectories()));
}

void IndirectBayes::initLayout()
{
}

void IndirectBayes::runClicked()
{
int tabIndex = m_uiForm.indirectBayesTabs->currentIndex();

if(m_bayesTabs[tabIndex]->validate())
{
m_bayesTabs[tabIndex]->run();
}
}

void IndirectBayes::helpClicked()
{
int tabIndex = m_uiForm.indirectBayesTabs->currentIndex();
QString url = m_bayesTabs[tabIndex]->tabHelpURL();
QDesktopServices::openUrl(QUrl(url));
}

void IndirectBayes::manageUserDirectories()
{
MantidQt::API::ManageUserDirectories *ad = new MantidQt::API::ManageUserDirectories(this);
ad->show();
ad->setFocus();
}

IndirectBayes::~IndirectBayes()
{
}
46 changes: 45 additions & 1 deletion Code/Mantid/MantidQt/CustomInterfaces/src/IndirectBayesTab.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/IndirectBayesTab.h"

namespace MantidQt
Expand All @@ -9,7 +10,7 @@ namespace MantidQt
/** Constructor
*/
IndirectBayesTab::IndirectBayesTab(QWidget * parent) : QWidget(parent),
m_plot(new QwtPlot(parent)), m_propTree(new QtTreePropertyBrowser()),
m_plot(new QwtPlot(parent)), m_curve(new QwtPlotCurve()), m_propTree(new QtTreePropertyBrowser()),
m_properties(), m_dblManager(new QtDoublePropertyManager()), m_intManager(new QtIntPropertyManager())
{
}
Expand All @@ -20,5 +21,48 @@ namespace MantidQt
IndirectBayesTab::~IndirectBayesTab()
{
}

QString IndirectBayesTab::tabHelpURL()
{
return "http://www.mantidproject.org/IndirectBayes:" + help();
}

void IndirectBayesTab::runPythonScript(const QString& pyInput)
{
emit executePythonScript(pyInput, false);
}

void IndirectBayesTab::plotMiniPlot(const QString& workspace, size_t index)
{
auto ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<const Mantid::API::MatrixWorkspace>(workspace.toStdString());
plotMiniPlot(ws, index);
}

void IndirectBayesTab::plotMiniPlot(const Mantid::API::MatrixWorkspace_const_sptr & workspace, size_t wsIndex)
{
using Mantid::MantidVec;

if ( m_curve != NULL )
{
m_curve->attach(0);
delete m_curve;
m_curve = NULL;
}

size_t nhist = workspace->getNumberHistograms();
if ( wsIndex >= nhist )
{
//showInformationBox("Error: Workspace index out of range.");
}

auto dataX = workspace->readX(wsIndex);
auto dataY = workspace->readY(wsIndex);

m_curve = new QwtPlotCurve();
m_curve->setData(&dataX[0], &dataY[0], static_cast<int>(workspace->blocksize()));
m_curve->attach(m_plot);

m_plot->replot();
}
}
} // namespace MantidQt
9 changes: 2 additions & 7 deletions Code/Mantid/MantidQt/CustomInterfaces/src/JumpFit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ namespace MantidQt
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

void JumpFit::validate()
bool JumpFit::validate()
{

return true;
}

void JumpFit::run()
{

}

void JumpFit::help()
{

}
} // namespace CustomInterfaces
} // namespace MantidQt
9 changes: 2 additions & 7 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Quasi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,14 @@ namespace MantidQt
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

void Quasi::validate()
bool Quasi::validate()
{

return true;
}

void Quasi::run()
{

}

void Quasi::help()
{

}
} // namespace CustomInterfaces
} // namespace MantidQt
39 changes: 36 additions & 3 deletions Code/Mantid/MantidQt/CustomInterfaces/src/ResNorm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ namespace MantidQt
{
m_uiForm.setupUi(parent);

connect(m_uiForm.dsVanadium, SIGNAL(dataReady(const QString&)), this, SLOT(handleVanadiumInputReady(const QString&)));

//add the properties browser to the ui form
m_uiForm.treeSpace->addWidget(m_propTree);
m_properties["EMin"] = m_dblManager->addProperty("EMin");
Expand All @@ -29,19 +31,50 @@ namespace MantidQt
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

void ResNorm::validate()
bool ResNorm::validate()
{
//check we have files/workspaces available to run with
if(m_uiForm.dsResolution->getCurrentDataName().isEmpty() ||
m_uiForm.dsVanadium->getCurrentDataName().isEmpty())
{
return false;
}

return true;
}

void ResNorm::run()
{
QString verbose("False");
QString plot("False");
QString save("False");

QString pyInput =
"from IndirectBayes import ResNormRun\n";

QString VanName = m_uiForm.dsVanadium->getCurrentDataName();
QString ResName = m_uiForm.dsResolution->getCurrentDataName();

QString EMin = m_properties["EMin"]->valueText();
QString EMax = m_properties["EMax"]->valueText();

QString ERange = "[" + EMin + "," + EMax + "]";

QString nBin = m_properties["VanBinning"]->valueText();

if(m_uiForm.ckVerbose->isChecked()){ verbose = "True"; }
if(m_uiForm.ckPlot->isChecked()){ plot = "True"; }
if(m_uiForm.ckSave->isChecked()){ save ="True"; }

pyInput += "ResNormRun("+VanName+", "+ResName+", "+ERange+", "+nBin+","
" Save="+save+", Plot="+plot+", Verbose="+verbose+")\n";

runPythonScript(pyInput);
}

void ResNorm::help()
void ResNorm::handleVanadiumInputReady(const QString& filename)
{

plotMiniPlot(filename, 0);
}
} // namespace CustomInterfaces
} // namespace MantidQt
9 changes: 2 additions & 7 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Stretch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,14 @@ namespace MantidQt
m_plot->setAxisFont(QwtPlot::yLeft, parent->font());
}

void Stretch::validate()
bool Stretch::validate()
{

return true;
}

void Stretch::run()
{

}

void Stretch::help()
{

}
} // namespace CustomInterfaces
} // namespace MantidQt
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/Inelastic/IndirectBayes.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ def QuestPlot(inputWS,Plot):

# ResNorm programs

def ResNormRun(vname,rname,erange,nbins,Verbose,Plot,Save):
def ResNormRun(vname,rname,erange,nbins,Verbose=False,Plot=False,Save=False):
StartTime('ResNorm')
workdir = config['defaultsave.directory']
array_len = 4096 # length of Fortran array
Expand Down

0 comments on commit 842879d

Please sign in to comment.