Skip to content

Commit

Permalink
refs #10530. Truncate extents. Andrei's suggestion.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 17, 2014
1 parent 3a32821 commit 058e811
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Expand Up @@ -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:
Expand All @@ -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.
Expand Down
Expand Up @@ -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()
Expand Down

0 comments on commit 058e811

Please sign in to comment.