From 726ebd85a3f7a4c71f9a3dbd0cd762f75e9dcf2f Mon Sep 17 00:00:00 2001 From: Owen Arnold Date: Sun, 7 Dec 2014 15:58:18 -0500 Subject: [PATCH] refs #10693. Remove the algorithm parts --- .../algorithms/WorkflowAlgorithms/CutMD.py | 42 ++++++++++++++----- .../test/python/mantid/api/CutMDTest.py | 29 +++++++++++++ 2 files changed, 61 insertions(+), 10 deletions(-) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py index 939d59fa0b41..db43fa742e1a 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py @@ -4,6 +4,7 @@ import numpy as np import os.path import re +import __builtin__ class Projection(object): u = "u" @@ -185,7 +186,8 @@ def __verify_input_workspace(self, to_cut): axes_check = self.getProperty("CheckAxes").value if axes_check: predicates = ["^(H.*)|(\\[H,0,0\\].*)$","^(K.*)|(\\[0,K,0\\].*)$","^(L.*)|(\\[0,0,L\\].*)$"] - for i in range(ndims): + n_crystallographic_dims = __builtin__.min(3, ndims) + for i in range(n_crystallographic_dims): dimension = to_cut.getDimension(i) p = re.compile(predicates[i]) if not p.match( dimension.getName() ): @@ -229,6 +231,9 @@ def __scale_projection(self, (u, v, w), origin_units, target_units, to_cut): def PyExec(self): + + logger.warning('You are running algorithm %s that is the beta stage of development' % (self.name())) + to_cut = self.getProperty("InputWorkspace").value self.__verify_input_workspace(to_cut) ndims = to_cut.getNumDims() @@ -241,7 +246,8 @@ def PyExec(self): p1_bins = self.getProperty("P1Bin").value p2_bins = self.getProperty("P2Bin").value p3_bins = self.getProperty("P3Bin").value - p4_bins = self.getProperty("P4Bin").value + p4_bins_property = self.getProperty("P4Bin") + p4_bins = p4_bins_property.value x_extents = self.__extents_in_current_projection(to_cut, 0); y_extents = self.__extents_in_current_projection(to_cut, 1); @@ -255,7 +261,8 @@ def PyExec(self): extents = self.__calculate_extents(v, u, w, ( x_extents, y_extents, z_extents ) ) extents, bins = self.__calculate_steps( extents, ( p1_bins, p2_bins, p3_bins ) ) - if p4_bins != None: + + if not p4_bins_property.isDefault: if (ndims == 4): n_args = len(p4_bins) min, max = self.__extents_in_current_projection(to_cut, 3); @@ -278,7 +285,7 @@ def PyExec(self): extents.append(min) extents.append(max) - bins.append(nbins) + bins.append(int(nbins)) e_units = to_cut.getDimension(3).getUnits() @@ -301,15 +308,30 @@ def PyExec(self): cut_alg.setProperty("NormalizeBasisVectors", False) cut_alg.setProperty("AxisAligned", False) # Now for the basis vectors. - for i in range(0, to_cut.getNumDims()): + + n_padding = __builtin__.max(0, ndims-3) + + for i in range(0, ndims): + + if i <= 2: + label = projection_labels[i] unit = target_units[i] - vec = projection[i] - value = "%s, %s, %s" % ( label, unit, ",".join(map(str, vec))) - cut_alg.setPropertyValue("BasisVector{0}".format(i) , value) - if i > 2: - raise RuntimeError("Not implemented yet for non-crystallographic basis vector generation.") + vec = list(projection[i]) + ( [0] * n_padding ) + + # These are always orthogonal to the rest. + else: + orthogonal_dimension = to_cut.getDimension(i) + label = orthogonal_dimension.getName() + unit = orthogonal_dimension.getUnits() + vec = [0] * ndims + vec[i] = i + + value = "%s, %s, %s" % ( label, unit, ",".join(map(str, vec))) + cut_alg.setPropertyValue("BasisVector{0}".format(i) , value) + + cut_alg.setProperty("OutputExtents", extents) cut_alg.setProperty("OutputBins", bins) 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 dc9777cb0fc7..81a375a587e8 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py @@ -202,7 +202,36 @@ def test_orthogonal_slice_with_cropping(self): self.assertTrue(isinstance(out_md, IMDHistoWorkspace), "Expect that the output was an IMDHistoWorkspace given the NoPix flag.") + def test_orthogonal_slice_4D(self): + # We create a fake 4-D workspace and check to see that using bin inputs for cropping works + to_cut = CreateMDWorkspace(Dimensions=4, Extents=[-1,1,-1,1,-1,1,-10,10], Names='H,K,L,E', Units='U,U,U,V') + # Set the UB + SetUB(Workspace=to_cut, a = 1, b = 1, c = 1, alpha =90, beta=90, gamma = 90) + SetSpecialCoordinates(InputWorkspace=to_cut, SpecialCoordinates='HKL') + + ''' + Process the 4D workspace + ''' + out_md = CutMD(to_cut, P1Bin=[-0.5,0.5], P2Bin=[-0.1,0.1], P3Bin=[-0.3,0.3], P4Bin=[1], NoPix=True) + + + self.assertAlmostEqual(-0.5, out_md.getDimension(0).getMinimum(), 6) + self.assertAlmostEqual(0.5, out_md.getDimension(0).getMaximum(), 6) + self.assertAlmostEqual(-0.1, out_md.getDimension(1).getMinimum(), 6) + self.assertAlmostEqual(0.1, out_md.getDimension(1).getMaximum(), 6) + self.assertAlmostEqual(-0.3, out_md.getDimension(2).getMinimum(), 6) + self.assertAlmostEqual(0.3, out_md.getDimension(2).getMaximum(), 6) + self.assertAlmostEqual(-10, out_md.getDimension(3).getMinimum(), 6) + self.assertAlmostEqual(10, out_md.getDimension(3).getMaximum(), 6) + self.assertEqual(20, out_md.getDimension(3).getNBins()) + self.assertEquals("['zeta', 0, 0]", out_md.getDimension(0).getName() ) + self.assertEquals("[0, 'eta', 0]", out_md.getDimension(1).getName() ) + self.assertEquals("[0, 0, 'xi']", out_md.getDimension(2).getName() ) + self.assertEquals("E", out_md.getDimension(3).getName() ) + + self.assertTrue(isinstance(out_md, IMDHistoWorkspace), "Expect that the output was an IMDHistoWorkspace given the NoPix flag.") + if __name__ == '__main__':