Skip to content

Commit

Permalink
Added new algorithm to GUI
Browse files Browse the repository at this point in the history
Refs #10264
  • Loading branch information
DanNixon committed Sep 25, 2014
1 parent 6af5ff9 commit 6ba04bd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 61 deletions.
Expand Up @@ -2,8 +2,6 @@
from mantid.api import *
from mantid.simpleapi import *

from IndirectCommon import CheckXrange, CheckHistZero

import os


Expand Down Expand Up @@ -122,6 +120,8 @@ def validateInput(self):


def PyExec(self):
from IndirectCommon import CheckXrange

self._setup()

# CheckXrange(xRange, 'Time')
Expand Down Expand Up @@ -237,6 +237,7 @@ def _process_raw_file(self, raw_file):
@param raw_file Name of file to process
"""
from IndirectCommon import CheckHistZero

# Crop the raw file to use the desired number of spectra
# less one because CropWorkspace is zero based
Expand All @@ -263,7 +264,7 @@ def _process_raw_file(self, raw_file):
StartX=self._background_range[0], EndX=self._background_range[1],
Mode='Mean')
Integration(InputWorkspace=slice_file, OutputWorkspace=slice_file,
RangeLower=self._peak_range[0], RangeUpper=self_peak_range[1],
RangeLower=self._peak_range[0], RangeUpper=self._peak_range[1],
StartWorkspaceIndex=0, EndWorkspaceIndex=num_hist - 1)

return slice_file
Expand Down
108 changes: 50 additions & 58 deletions Code/Mantid/MantidQt/CustomInterfaces/src/IndirectDiagnostics.cpp
Expand Up @@ -6,6 +6,8 @@

#include <QFileInfo>

using namespace Mantid::API;

namespace
{
Mantid::Kernel::Logger g_log("IndirectDiagnostics");
Expand Down Expand Up @@ -101,105 +103,97 @@ namespace CustomInterfaces
// Set default UI state
sliceTwoRanges(0, false);
}

//----------------------------------------------------------------------------------------------
/** Destructor
*/
IndirectDiagnostics::~IndirectDiagnostics()
{
}

void IndirectDiagnostics::setup()
{
}

void IndirectDiagnostics::run()
{
QString pyInput =
"from IndirectEnergyConversion import slice\n"
"tofRange = [" + QString::number(m_dblManager->value(m_properties["PeakStart"])) + ","
+ QString::number(m_dblManager->value(m_properties["PeakEnd"]));
if ( m_blnManager->value(m_properties["UseTwoRanges"]) )
{
pyInput +=
"," + QString::number(m_dblManager->value(m_properties["BackgroundStart"])) + ","
+ QString::number(m_dblManager->value(m_properties["BackgroundEnd"])) + "]\n";
}
else
{
pyInput += "]\n";
}
if ( m_uiForm.slice_ckUseCalib->isChecked() )
{
pyInput +=
"calib = r'" + m_uiForm.slice_calibFile->getFirstFilename() + "'\n";
}
else
{
pyInput +=
"calib = ''\n";
}
QString suffix = "_" + m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText() + "_slice";
QString filenames = m_uiForm.slice_inputFile->getFilenames().join("', r'");
QString suffix = m_uiForm.cbAnalyser->currentText() + m_uiForm.cbReflection->currentText();
pyInput +=
"rawfile = [r'" + filenames + "']\n"
"spectra = ["+ QString::number(m_dblManager->value(m_properties["SpecMin"])) + "," + QString::number(m_dblManager->value(m_properties["SpecMax"])) +"]\n"
"suffix = '" + suffix + "'\n";

if(m_uiForm.slice_ckVerbose->isChecked())
pyInput += "verbose = True\n";
else
pyInput += "verbose = False\n";

if(m_uiForm.slice_ckPlot->isChecked())
pyInput += "plot = True\n";
else
pyInput += "plot = False\n";
std::vector<long> spectraRange;
spectraRange.push_back(static_cast<long>(m_dblManager->value(m_properties["SpecMin"])));
spectraRange.push_back(static_cast<long>(m_dblManager->value(m_properties["SpecMax"])));

if(m_uiForm.slice_ckSave->isChecked())
pyInput += "save = True\n";
else
pyInput += "save = False\n";
std::vector<double> peakRange;
peakRange.push_back(m_dblManager->value(m_properties["PeakStart"]));
peakRange.push_back(m_dblManager->value(m_properties["PeakEnd"]));

IAlgorithm_sptr sliceAlg = AlgorithmManager::Instance().create("TimeSlice");
sliceAlg->initialize();

sliceAlg->setProperty("InputFiles", filenames.toStdString());
sliceAlg->setProperty("SpectraRange", spectraRange);
sliceAlg->setProperty("PeakRange", peakRange);
sliceAlg->setProperty("Verbose", m_uiForm.slice_ckVerbose->isChecked());
sliceAlg->setProperty("Plot", m_uiForm.slice_ckPlot->isChecked());
sliceAlg->setProperty("Save", m_uiForm.slice_ckSave->isChecked());
sliceAlg->setProperty("OutputNameSuffix", suffix.toStdString());

pyInput +=
"slice(rawfile, calib, tofRange, spectra, suffix, Save=save, Verbose=verbose, Plot=plot)";
if(m_uiForm.slice_ckUseCalib->isChecked())
{
/* m_uiForm.slice_calibFile->getFirstFilename(); */
/* sliceAlg->setProperty("CalibrationWorkspace", ); */
}

if(m_blnManager->value(m_properties["UseTwoRanges"]))
{
std::vector<double> backgroundRange;
backgroundRange.push_back(m_dblManager->value(m_properties["BackgroundStart"]));
backgroundRange.push_back(m_dblManager->value(m_properties["BackgroundEnd"]));
sliceAlg->setProperty("BackgroundRange", backgroundRange);
}

QString pyOutput = m_pythonRunner.runPythonCode(pyInput).trimmed();
runAlgorithm(sliceAlg);
}

bool IndirectDiagnostics::validate()
{
UserInputValidator uiv;

// Check raw input
uiv.checkMWRunFilesIsValid("Input", m_uiForm.slice_inputFile);
if( m_uiForm.slice_ckUseCalib->isChecked() )
if(m_uiForm.slice_ckUseCalib->isChecked())
uiv.checkMWRunFilesIsValid("Calibration", m_uiForm.slice_inputFile);

// Check peak range
auto rangeOne = std::make_pair(m_dblManager->value(m_properties["PeakStart"]), m_dblManager->value(m_properties["PeakEnd"]));
uiv.checkValidRange("Range One", rangeOne);

// Check background range
bool useTwoRanges = m_blnManager->value(m_properties["UseTwoRanges"]);
if( useTwoRanges )
if(useTwoRanges)
{
auto rangeTwo = std::make_pair(m_dblManager->value(m_properties["BackgroundStart"]), m_dblManager->value(m_properties["BackgroundEnd"]));
uiv.checkValidRange("Range Two", rangeTwo);

uiv.checkRangesDontOverlap(rangeOne, rangeTwo);
}

// Check spectra range
auto specRange = std::make_pair(m_dblManager->value(m_properties["SpecMin"]), m_dblManager->value(m_properties["SpecMax"]));
uiv.checkValidRange("Spectra Range", specRange);

QString error = uiv.generateErrorMessage();
bool isError = error != "";

if(error != "")
if(isError)
g_log.warning(error.toStdString());

return (error == "");
return !isError;
}

/**
* Sets default spectra, peak and background ranges
* Sets default spectra, peak and background ranges.
*/
void IndirectDiagnostics::setDefaultInstDetails()
{
Expand All @@ -225,8 +219,6 @@ namespace CustomInterfaces
*/
void IndirectDiagnostics::slicePlotRaw()
{
using namespace Mantid::API;

setDefaultInstDetails();

if ( m_uiForm.slice_inputFile->isValid() )
Expand Down Expand Up @@ -320,10 +312,10 @@ namespace CustomInterfaces
*/
void IndirectDiagnostics::sliceUpdateRS(QtProperty* prop, double val)
{
if ( prop == m_properties["PeakStart"] ) m_rangeSelectors["SlicePeak"]->setMinimum(val);
else if ( prop == m_properties["PeakEnd"] ) m_rangeSelectors["SlicePeak"]->setMaximum(val);
else if ( prop == m_properties["BackgroundStart"] ) m_rangeSelectors["SliceBackground"]->setMinimum(val);
else if ( prop == m_properties["BackgroundEnd"] ) m_rangeSelectors["SliceBackground"]->setMaximum(val);
if(prop == m_properties["PeakStart"]) m_rangeSelectors["SlicePeak"]->setMinimum(val);
else if(prop == m_properties["PeakEnd"]) m_rangeSelectors["SlicePeak"]->setMaximum(val);
else if(prop == m_properties["BackgroundStart"]) m_rangeSelectors["SliceBackground"]->setMinimum(val);
else if(prop == m_properties["BackgroundEnd"]) m_rangeSelectors["SliceBackground"]->setMaximum(val);
}

} // namespace CustomInterfaces
Expand Down

0 comments on commit 6ba04bd

Please sign in to comment.