From fe90ba7f90bba513d513b89724eb00d4850683b9 Mon Sep 17 00:00:00 2001 From: Owen Arnold <owen.arnold@stfc.ac.uk> Date: Fri, 14 Nov 2014 13:54:47 +0000 Subject: [PATCH] refs #10530. More checks and tests. --- .../algorithms/WorkflowAlgorithms/CutMD.py | 16 +++++++++++----- .../test/python/mantid/api/CutMDTest.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py index 64bcbfc6803..179704cdd7b 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py @@ -179,6 +179,8 @@ class CutMD(DataProcessorAlgorithm): def PyExec(self): to_cut = self.getProperty("InputWorkspace").value self.__verify_input_workspace(to_cut) + ndims = to_cut.getNumDims() + nopix = self.getProperty("NoPix").value projection_table = self.getProperty("Projection").value @@ -187,15 +189,20 @@ class CutMD(DataProcessorAlgorithm): p1_bins = self.getProperty("P1Bin").value p2_bins = self.getProperty("P2Bin").value p3_bins = self.getProperty("P3Bin").value - p4_bins = self.getProperty("P4Bin").value # TODO handle 3D only slicing. + p4_bins = self.getProperty("P4Bin").value # TODO. THESE ARE WRONG. Need to consider the acutal transformed extents as part of this. xbins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 0); ybins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 1); - zbins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 2); - #ebins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 3); # TODO. cannot guarantee this one is here + zbins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 2); + bins = [ int(xbins[2]), int(ybins[2]), int(zbins[2]) ] + if p4_bins: + if (ndims == 4): + ebins = self.__to_mantid_slicing_binning(p1_bins, to_cut, 3); + bins.append(int(ebins[2])) + else: + raise ValueError("Cannot specify P4Bins unless the workspace is of sufficient dimensions") - # TODO. check that workspace is x=H, y=K, z=L before using the projections and slicing. projection = self.__uvw_from_projection_table(projection_table) u,v,w = projection @@ -222,7 +229,6 @@ class CutMD(DataProcessorAlgorithm): if i > 2: raise RuntimeError("Not implmented yet for non-crystallographic basis vector generation.") cut_alg.setProperty("OutputExtents", extents) - bins = [ int(xbins[2]), int(ybins[2]), int(zbins[2]) ] # Again this is a hack for 3 dimensional data only. cut_alg.setProperty("OutputBins", bins) cut_alg.execute() 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 9ade8e999a8..a7c84c6af25 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py @@ -24,7 +24,18 @@ class CutMDTest(unittest.TestCase): test_md = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names="A,B,C", Units="U,U,U") # Explicitly set the coordinate system to lab Q. SetSpecialCoordinates(InputWorkspace=test_md, SpecialCoordinates='Q (lab frame)') - self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1]) + self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1], CheckAxes=False) + + def test_exec_throws_if_set_to_be_a_hkl_workspace_but_with_missaligned_dimension_names(self): + test_md = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names="K,H,L", Units="U,U,U") # K,H,L are the dimension names + SetSpecialCoordinates(InputWorkspace=test_md, SpecialCoordinates='HKL') + self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1], CheckAxes=True) + + def test_exec_throws_if_giving_4th_binning_parameter_when_workspace_is_3D(self): + test_md = CreateMDWorkspace(Dimensions=3, Extents=[-10,10,-10,10,-10,10], Names="H,K,L", Units="U,U,U") + # Explicitly set the coordinate system to lab Q. + SetSpecialCoordinates(InputWorkspace=test_md, SpecialCoordinates='HKL') + self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1], P4Bin=[0.1]) def test_slice_to_original(self): out_md = CutMD(self.__in_md, P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1], CheckAxes=False) -- GitLab