diff --git a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py index feaeb730d7dc..1f1beaf79832 100644 --- a/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py +++ b/Code/Mantid/Framework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/CutMD.py @@ -86,7 +86,6 @@ def __calculate_extents(self, v, u, w, ws): # Get the min max extents extents = list() - print new_coords for i in range(0,3): # Vertical slice down each corner for each dimension, then determine the max, min and use as extents extents.append(np.amin(new_coords[:,i])) @@ -99,6 +98,7 @@ def __calculate_extents(self, v, u, w, ws): extents.append(ws.getDimension(i + 3).getMinimum()) extents.append(ws.getDimension(i + 3).getMaximum()) + print extents return extents def __uvw_from_projection_table(self, projection_table): @@ -118,8 +118,15 @@ def __init__(self, replace): self.__replace = replace def replace(self, entry): - if entry > 0: - return self.__replace + if np.absolute(entry) == 1: + if entry > 0: + return self.__replace + else: + return "-" + self.__replace + elif entry == 0: + return 0 + else: + return "%.2f%s" % ( entry, self.__replace ) return entry crystallographic_names = ['zeta', 'eta', 'xi' ] @@ -184,14 +191,12 @@ def PyExec(self): cut_alg.setProperty("AxisAligned", False) # Now for the basis vectors. for i in range(0, to_cut.getNumDims()): - logger.warning("WARNING....") if i <= 2: label = projection_labels[i] unit = "TODO" # Haven't figured out how to do this yet. vec = projection[i] value = "%s, %s, %s" % ( label, unit, ",".join(map(str, vec))) cut_alg.setPropertyValue("BasisVector{0}".format(i) , value) - logger.warning("BasisVector{0}".format(i)) if i > 2: raise RuntimeError("Not implmented yet for non-crystallographic basis vector generation.") cut_alg.setProperty("OutputExtents", extents) 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 97c6e62d43d2..3a13fddddc08 100644 --- a/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py +++ b/Code/Mantid/Framework/PythonInterface/test/python/mantid/api/CutMDTest.py @@ -1,6 +1,6 @@ import unittest import testhelpers - +import numpy as np from mantid.simpleapi import * from mantid.api import IMDHistoWorkspace @@ -36,9 +36,9 @@ def test_slice_to_original(self): self.assertEquals(self.__in_md.getDimension(1).getMaximum(), out_md.getDimension(1).getMaximum()) self.assertEquals(self.__in_md.getDimension(2).getMinimum(), out_md.getDimension(2).getMinimum()) self.assertEquals(self.__in_md.getDimension(2).getMaximum(), out_md.getDimension(2).getMaximum()) - self.assertEquals("['zeta', 0.0, 0.0]", out_md.getDimension(0).getName() ) - self.assertEquals("[0.0, 'eta', 0.0]", out_md.getDimension(1).getName() ) - self.assertEquals("[0.0, 0.0, 'xi']", out_md.getDimension(2).getName() ) + 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() ) def test_wrong_projection_workspace_format_wrong_column_numbers(self): projection = CreateEmptyTableWorkspace() @@ -57,8 +57,41 @@ def test_wrong_table_workspace_format_wrong_row_numbers(self): # Incorrect number of rows i.e. zero in this case as none added. self.assertRaises(RuntimeError, CutMD, InputWorkspace=self.__in_md, Projection=projection, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1]) - def test_run_it(self): - pass + def test_non_orthogonal_slice_with_scaling(self): + # We create a fake workspace around and check to see that the extents get scaled with the new coordinate system when sliced + to_cut = CreateMDWorkspace(Dimensions=3, Extents=[-1,1,-1,1,-1,1], Names='H,K,L', Units='U,U,U') + + SetSpecialCoordinates(InputWorkspace=to_cut, SpecialCoordinates='HKL') + + scale_x = 2.0 + scale_y = 2.0 + + projection = CreateEmptyTableWorkspace() + # Correct number of columns, and names + projection.addColumn("double", "u") + projection.addColumn("double", "v") + projection.addColumn("str", "type") + projection.addRow([scale_x,0,"aaa"]) + projection.addRow([0,scale_y,"aaa"]) + projection.addRow([0,0,"aaa"]) + + out_md = CutMD(to_cut, Projection=projection, P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1]) + + scale_z = np.cross(projection.column(1), projection.column(0))[-1] + ''' + Here we check that the corners in HKL end up in the expected positions when transformed into the new scaled basis + provided by the W transform (projection table) + ''' + self.assertEquals(-(1/scale_x), out_md.getDimension(0).getMinimum()) + self.assertEquals((1/scale_x), out_md.getDimension(0).getMaximum()) + self.assertEquals(-(1/scale_y), out_md.getDimension(1).getMinimum()) + self.assertEquals((1/scale_y), out_md.getDimension(1).getMaximum()) + self.assertEquals((1/scale_z), out_md.getDimension(2).getMinimum()) + self.assertEquals(-(1/scale_z), out_md.getDimension(2).getMaximum()) + self.assertEquals("['2.00zeta', 0, 0]", out_md.getDimension(0).getName() ) + self.assertEquals("[0, '2.00eta', 0]", out_md.getDimension(1).getName() ) + self.assertEquals("[0, 0, '-4.00xi']", out_md.getDimension(2).getName() ) + if __name__ == '__main__': unittest.main() \ No newline at end of file