Skip to content

Commit

Permalink
Added basic unit test, refactoring
Browse files Browse the repository at this point in the history
Refs #11437
  • Loading branch information
DanNixon committed Mar 27, 2015
1 parent 8c3c247 commit 9fd74ac
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 deletions.
Expand Up @@ -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')

Expand Down Expand Up @@ -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 == '':
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down
Expand Up @@ -54,6 +54,7 @@ set ( TEST_PY_FILES
UpdatePeakParameterTableValueTest.py
SANSSubtractTest.py
TimeSliceTest.py
TransformToIqtTest.py
ExportSampleLogsToCSVFileTest.py
ExportExperimentLogTest.py
PoldiMergeTest.py
Expand Down
@@ -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()
8 changes: 4 additions & 4 deletions Code/Mantid/MantidQt/CustomInterfaces/src/Indirect/Fury.cpp
Expand Up @@ -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<long>(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();
Expand All @@ -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);
Expand Down Expand Up @@ -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<long>(m_dblManager->value(m_properties["SampleBinning"])); // Default value
double numBins = m_dblManager->value(m_properties["SampleBinning"]);
if(numBins == 0)
return;

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/docs/source/algorithms/TransformToIqt-v1.rst
Expand Up @@ -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))
Expand Down

0 comments on commit 9fd74ac

Please sign in to comment.