Skip to content

Commit

Permalink
Convert OSIRIS diffonly reduction to use batch algo runner
Browse files Browse the repository at this point in the history
Refs #10215
  • Loading branch information
DanNixon committed Sep 17, 2014
1 parent 465b98f commit 401352d
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
Expand Up @@ -5,6 +5,7 @@
// Includes
//----------------------
#include "ui_IndirectDiffractionReduction.h"
#include "MantidQtAPI/BatchAlgorithmRunner.h"
#include "MantidQtAPI/UserSubWindow.h"

namespace MantidQt
Expand Down Expand Up @@ -49,6 +50,7 @@ public slots:
QDoubleValidator * m_valDbl;
/// The settings group
QString m_settingsGroup;
MantidQt::API::BatchAlgorithmRunner *m_batchAlgoRunner;

};

Expand Down
Expand Up @@ -4,6 +4,7 @@
#include "MantidQtCustomInterfaces/IndirectDiffractionReduction.h"

#include "MantidQtAPI/ManageUserDirectories.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidKernel/Logger.h"
#include "MantidKernel/MultiFileNameParser.h"

Expand All @@ -30,14 +31,19 @@ namespace // anon

DECLARE_SUBWINDOW(IndirectDiffractionReduction);

using namespace Mantid::API;
using namespace MantidQt::CustomInterfaces;

using MantidQt::API::BatchAlgorithmRunner;

//----------------------
// Public member functions
//----------------------
///Constructor
IndirectDiffractionReduction::IndirectDiffractionReduction(QWidget *parent) :
UserSubWindow(parent), m_valInt(NULL), m_valDbl(NULL), m_settingsGroup("CustomInterfaces/DEMON")
UserSubWindow(parent), m_valInt(NULL), m_valDbl(NULL),
m_settingsGroup("CustomInterfaces/DEMON"),
m_batchAlgoRunner(new BatchAlgorithmRunner(parent))
{
}

Expand Down Expand Up @@ -127,35 +133,62 @@ void IndirectDiffractionReduction::demonRun()
return;
}

QString pyInput =
"from mantid.simpleapi import *\n"
"OSIRISDiffractionReduction("
"Sample=r'" + m_uiForm.dem_rawFiles->getFilenames().join(", ") + "', "
"Vanadium=r'" + m_uiForm.dem_vanadiumFile->getFilenames().join(", ") + "', "
"CalFile=r'" + m_uiForm.dem_calFile->getFirstFilename() + "', "
"OutputWorkspace=" + drangeWsName + ")\n";

pyInput += "ConvertUnits(InputWorkspace=" + drangeWsName + ", OutputWorkspace=" + tofWsName + ", Target='TOF')\n";
IAlgorithm_sptr osirisDiffReduction = AlgorithmManager::Instance().create("OSIRISDiffractionReduction");
osirisDiffReduction->initialize();
osirisDiffReduction->setProperty("Sample", m_uiForm.dem_rawFiles->getFilenames().join(",").toStdString());
osirisDiffReduction->setProperty("Vanadium", m_uiForm.dem_vanadiumFile->getFilenames().join(",").toStdString());
osirisDiffReduction->setProperty("CalFile", m_uiForm.dem_calFile->getFirstFilename().toStdString());
osirisDiffReduction->setProperty("OutputWorkspace", drangeWsName.toStdString());
m_batchAlgoRunner->addAlgorithm(osirisDiffReduction);

BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromReductionProps;
inputFromReductionProps["InputWorkspace"] = drangeWsName.toStdString();

IAlgorithm_sptr convertUnits = AlgorithmManager::Instance().create("ConvertUnits");
convertUnits->initialize();
convertUnits->setProperty("OutputWorkspace", tofWsName.toStdString());
convertUnits->setProperty("Target", "TOF");
m_batchAlgoRunner->addAlgorithm(convertUnits, inputFromReductionProps);

BatchAlgorithmRunner::AlgorithmRuntimeProps inputFromConvUnitsProps;
inputFromConvUnitsProps["InputWorkspace"] = tofWsName.toStdString();

if ( m_uiForm.ckGSS->isChecked() )
{
pyInput += "SaveGSS(InputWorkspace=" + tofWsName + ", Filename=" + tofWsName + " + '.gss')\n";
QString gssFilename = tofWsName + ".gss";
IAlgorithm_sptr saveGSS = AlgorithmManager::Instance().create("SaveGSS");
saveGSS->initialize();
saveGSS->setProperty("Filename", gssFilename.toStdString());
m_batchAlgoRunner->addAlgorithm(saveGSS, inputFromConvUnitsProps);
}

if ( m_uiForm.ckNexus->isChecked() )
pyInput += "SaveNexusProcessed(InputWorkspace=" + drangeWsName + ", Filename=" + drangeWsName + "+'.nxs')\n";

if ( m_uiForm.ckAscii->isChecked() )
pyInput += "SaveAscii(InputWorkspace=" + drangeWsName + ", Filename=" + drangeWsName + " +'.dat')\n";
if ( m_uiForm.ckNexus->isChecked() )
{
QString nexusFilename = drangeWsName + ".nxs";
IAlgorithm_sptr saveNexus = AlgorithmManager::Instance().create("SaveNexusProcessed");
saveNexus->initialize();
saveNexus->setProperty("Filename", nexusFilename.toStdString());
m_batchAlgoRunner->addAlgorithm(saveNexus, inputFromReductionProps);
}

if ( m_uiForm.cbPlotType->currentText() == "Spectra" )
if ( m_uiForm.ckAscii->isChecked() )
{
pyInput += "from mantidplot import *\n"
"plotSpectrum(" + drangeWsName + ", 0)\n"
"plotSpectrum(" + tofWsName + ", 0)\n";
QString asciiFilename = drangeWsName + ".dat";
IAlgorithm_sptr saveASCII = AlgorithmManager::Instance().create("SaveAscii");
saveASCII->initialize();
saveASCII->setProperty("Filename", asciiFilename.toStdString());
m_batchAlgoRunner->addAlgorithm(saveASCII, inputFromReductionProps);
}

QString pyOutput = runPythonCode(pyInput).trimmed();
m_batchAlgoRunner->executeBatchAsync();

/* if ( m_uiForm.cbPlotType->currentText() == "Spectra" ) */
/* { */
/* QString pyInput = "from mantidplot import *\n" */
/* "plotSpectrum(" + drangeWsName + ", 0)\n" */
/* "plotSpectrum(" + tofWsName + ", 0)\n"; */
/* runPythonCode(pyInput).trimmed(); */
/* } */
}
}

Expand Down

0 comments on commit 401352d

Please sign in to comment.