From 9fd74aca649960905909c44b1d1f1f2e45151c9e Mon Sep 17 00:00:00 2001 From: Dan Nixon Date: Fri, 27 Mar 2015 09:56:54 +0000 Subject: [PATCH] Added basic unit test, refactoring Refs #11437 --- .../WorkflowAlgorithms/TransformToIqt.py | 8 ++--- .../python/plugins/algorithms/CMakeLists.txt | 1 + .../plugins/algorithms/TransformToIqtTest.py | 34 +++++++++++++++++++ .../CustomInterfaces/src/Indirect/Fury.cpp | 8 ++--- .../source/algorithms/TransformToIqt-v1.rst | 2 +- 5 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/TransformToIqtTest.py diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TransformToIqt.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TransformToIqt.py index 87084b0eb231..ab2d4a4c5129 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TransformToIqt.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/TransformToIqt.py @@ -43,7 +43,7 @@ def PyInit(self): doc='Minimum energy for fit. Default=-0.5') self.declareProperty(name='EnergyMax', defaultValue=0.5, doc='Maximum energy for fit. Default=0.5') - self.declareProperty(name='NumBins', defaultValue=1, + self.declareProperty(name='BinReductionFactor', defaultValue=10.0, doc='Decrease total number of spectrum points by this ratio through merging of ' 'intensities from neighbouring bins. Default=1') @@ -99,7 +99,7 @@ def _setup(self): self._e_min = self.getProperty('EnergyMin').value self._e_max = self.getProperty('EnergyMax').value - self._number_points_per_bin = self.getProperty('NumBins').value + self._number_points_per_bin = self.getProperty('BinReductionFactor').value self._parameter_table = self.getPropertyValue('ParameterWorkspace') if self._parameter_table == '': @@ -140,7 +140,7 @@ def _calculate_parameters(self): Xmin=self._e_min, Xmax=self._e_max) x_data = mtd['__TransformToIqt_sample_cropped'].readX(0) number_input_points = len(x_data) - 1 - num_bins = number_input_points / self._number_points_per_bin + num_bins = int(number_input_points / self._number_points_per_bin) self._e_width = (abs(self._e_min) + abs(self._e_max)) / num_bins try: @@ -173,7 +173,7 @@ def _calculate_parameters(self): param_table = CreateEmptyTableWorkspace(OutputWorkspace=self._parameter_table) param_table.addColumn('int', 'SampleInputBins') - param_table.addColumn('int', 'NumberBins') + param_table.addColumn('float', 'BinReductionFactor') param_table.addColumn('int', 'SampleOutputBins') param_table.addColumn('float', 'EnergyMin') param_table.addColumn('float', 'EnergyMax') diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt index 7efb5e765f89..2fd9d12af787 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/CMakeLists.txt @@ -54,6 +54,7 @@ set ( TEST_PY_FILES UpdatePeakParameterTableValueTest.py SANSSubtractTest.py TimeSliceTest.py + TransformToIqtTest.py ExportSampleLogsToCSVFileTest.py ExportExperimentLogTest.py PoldiMergeTest.py diff --git a/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/TransformToIqtTest.py b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/TransformToIqtTest.py new file mode 100644 index 000000000000..3358369b0b7f --- /dev/null +++ b/Code/Mantid/Framework/PythonInterface/test/python/plugins/algorithms/TransformToIqtTest.py @@ -0,0 +1,34 @@ +import unittest +from mantid.simpleapi import * +from mantid.api import * + +class TransformToIqtTest(unittest.TestCase): + + def test_with_can_reduction(self): + """ + Tests running using the container reduction as a resolution. + """ + + sample = Load('irs26176_graphite002_red') + can = Load('irs26173_graphite002_red') + + params, iqt = TransformToIqt(SampleWorkspace=sample, + ResolutionWorkspace=can, + BinReductionFactor=10) + + + def test_with_resolution_reduction(self): + """ + Tests running using the instrument resolution workspace. + """ + + sample = Load('irs26176_graphite002_red') + resolution = Load('irs26173_graphite002_res') + + params, iqt = TransformToIqt(SampleWorkspace=sample, + ResolutionWorkspace=resolution, + BinReductionFactor=10) + + +if __name__ == '__main__': + unittest.main() diff --git a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Fury.cpp b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Fury.cpp index bd9d07474e3f..d1f64dc1bcc2 100644 --- a/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Fury.cpp +++ b/Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Fury.cpp @@ -89,7 +89,7 @@ namespace IDA double energyMin = m_dblManager->value(m_properties["ELow"]); double energyMax = m_dblManager->value(m_properties["EHigh"]); - long numBins = static_cast(m_dblManager->value(m_properties["SampleBinning"])); + double numBins = m_dblManager->value(m_properties["SampleBinning"]); bool plot = m_uiForm.ckPlot->isChecked(); bool save = m_uiForm.ckSave->isChecked(); @@ -102,7 +102,7 @@ namespace IDA furyAlg->setProperty("EnergyMin", energyMin); furyAlg->setProperty("EnergyMax", energyMax); - furyAlg->setProperty("NumBins", numBins); + furyAlg->setProperty("BinReductionFactor", numBins); furyAlg->setProperty("Plot", plot); furyAlg->setProperty("Save", save); @@ -188,7 +188,7 @@ namespace IDA double energyMin = m_dblManager->value(m_properties["ELow"]); double energyMax = m_dblManager->value(m_properties["EHigh"]); - long numBins = static_cast(m_dblManager->value(m_properties["SampleBinning"])); // Default value + double numBins = m_dblManager->value(m_properties["SampleBinning"]); if(numBins == 0) return; @@ -201,7 +201,7 @@ namespace IDA furyAlg->setProperty("EnergyMin", energyMin); furyAlg->setProperty("EnergyMax", energyMax); - furyAlg->setProperty("NumBins", numBins); + furyAlg->setProperty("BinReductionFactor", numBins); furyAlg->setProperty("Plot", false); furyAlg->setProperty("Save", false); diff --git a/Code/Mantid/docs/source/algorithms/TransformToIqt-v1.rst b/Code/Mantid/docs/source/algorithms/TransformToIqt-v1.rst index eb3fc542b844..83480d11785c 100644 --- a/Code/Mantid/docs/source/algorithms/TransformToIqt-v1.rst +++ b/Code/Mantid/docs/source/algorithms/TransformToIqt-v1.rst @@ -97,7 +97,7 @@ Usage ResolutionWorkspace=can, EnergyMin=-0.5, EnergyMax=0.5, - NumBins=10) + BinReductionFactor=10) print 'Number of output bins: %d' % (params.cell('SampleOutputBins', 0)) print 'Resolution bins: %d' % (params.cell('ResolutionBins', 0))