From 058e8115c2cdad16b4084bfb8d87d770dc10a2b5 Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Mon, 17 Nov 2014 12:01:03 +0000 Subject: [PATCH] refs #10530. Truncate extents. Andrei's suggestion. --- .../plugins/algorithms/WorkflowAlgorithms/CutMD.py | 10 ++++++++-- .../test/python/mantid/api/CutMDTest.py | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py index 94ea424c27a4..0051c9913ae5 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py @@ -46,12 +46,15 @@ def __to_mantid_slicing_binning(self, horace_binning, to_cut, dimension_index): dim = to_cut.getDimension(dimension_index) dim_min = dim.getMinimum() dim_max = dim.getMaximum() + dim_range = dim_max - dim_min n_arguments = len(horace_binning) if n_arguments == 0: raise ValueError("binning parameter cannot be empty") elif n_arguments == 1: step_size = horace_binning[0] - n_bins = int( (dim_max - dim_min) / step_size) + if step_size > dim_range: + step_size = dim_range + n_bins = int( dim_range / step_size) # Calculate the maximum based on step size and number of bins dim_max = dim_min + ( n_bins * step_size ) elif n_arguments == 2: @@ -62,7 +65,10 @@ def __to_mantid_slicing_binning(self, horace_binning, to_cut, dimension_index): dim_min = horace_binning[0] dim_max = horace_binning[2] step_size = horace_binning[1] - n_bins = int( (dim_max - dim_min) / step_size) + dim_range = dim_max - dim_min + if step_size > dim_range: + step_size = dim_range + n_bins = int( dim_range / step_size) dim_max = dim_min + ( n_bins * step_size ) #if dim_max != horace_binning[2]: # pass # TODO, we should generate a warning at this point. diff --git a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py index 6637fedb62d0..48e2d790658e 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py @@ -59,6 +59,12 @@ def test_recalculate_extents_with_3_bin_arguments(self): self.assertEqual(2, dim.getNBins(), "Wrong calculated number of bins") self.assertAlmostEqual(0.6, dim.getMaximum(), 6, "Wrong calculated maximum") + def test_truncate_extents(self): + out_md = CutMD(self.__in_md, P1Bin=[0, 1.1, 1], P2Bin=[21], P3Bin=[0.1], CheckAxes=False, NoPix=True) + + self.assertEqual(1, out_md.getDimension(0).getNBins(), "Step is beyond range. Should just be integrated") + self.assertEqual(1, out_md.getDimension(1).getNBins(), "Step is beyond range. Should just be integrated") + def test_wrong_projection_workspace_format_wrong_column_numbers(self): projection = CreateEmptyTableWorkspace()