Skip to content

Commit

Permalink
refs #10530. Update according to Andrei's binning observations.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 17, 2014
1 parent 0b82671 commit 0056ae5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Expand Up @@ -44,31 +44,36 @@ def PyInit(self):
def __to_mantid_slicing_binning(self, horace_binning, to_cut, dimension_index):

dim = to_cut.getDimension(dimension_index)
min = dim.getMinimum()
max = dim.getMaximum()
dim_min = dim.getMinimum()
dim_max = dim.getMaximum()
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 = (max - min) / step_size
n_bins = int( (dim_max - dim_min) / 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:
min = horace_binning[0]
max = horace_binning[1]
dim_min = horace_binning[0]
dim_max = horace_binning[1]
n_bins = 1
elif n_arguments == 3:
dim_min = horace_binning[0]
dim_max = horace_binning[2]
step_size = horace_binning[1]
n_bins = (max - min) / step_size
min = horace_binning[0]
max = horace_binning[2]
pass
n_bins = int( (dim_max - dim_min) / 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.
else:
raise ValueError("Too many arguments given to the binning parameter")
if min >= max:
if dim_min >= dim_max:
raise ValueError("Dimension Min >= Max value. Min %.2f Max %.2f", min, max)
if n_bins < 1:
raise ValueError("Number of bins calculated to be < 1")
return (min, max, n_bins)
return (dim_min, dim_max, n_bins)


def __innermost_boundary(self, a, b):
if np.absolute(a) < np.absolute(b):
Expand Down Expand Up @@ -207,7 +212,7 @@ def PyExec(self):
p3_bins = self.getProperty("P3Bin").value
p4_bins = self.getProperty("P4Bin").value

# TODO. THESE ARE WRONG. Need to consider the acutal transformed extents as part of this.
# TODO. THESE ARE WRONG. Need to consider the actual transformed extents as part of this.
xbins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 0);
ybins = self.__to_mantid_slicing_binning(p2_bins, to_cut, 1);
zbins = self.__to_mantid_slicing_binning(p3_bins, to_cut, 2);
Expand Down
Expand Up @@ -52,6 +52,14 @@ def test_slice_to_original(self):
self.assertEquals("[0, 0, 'xi']", out_md.getDimension(2).getName() )
self.assertTrue(isinstance(out_md, IMDEventWorkspace), "nopix defaults to True. Should get an IMDEventWorkspace")

def test_recalculate_extents_with_3_bin_arguments(self):
out_md = CutMD(self.__in_md, P1Bin=[0, 0.3, 0.8], P2Bin=[0.1], P3Bin=[0.1], CheckAxes=False, NoPix=True)
dim = out_md.getDimension(0)
self.assertAlmostEqual(0, dim.getMinimum(), 6, "Wrong minimum")
self.assertEqual(2, dim.getNBins(), "Wrong calculated number of bins")
self.assertAlmostEqual(0.6, dim.getMaximum(), 6, "Wrong calculated maximum")


def test_wrong_projection_workspace_format_wrong_column_numbers(self):
projection = CreateEmptyTableWorkspace()
projection.addColumn("double", "u")
Expand Down

0 comments on commit 0056ae5

Please sign in to comment.