Skip to content
Snippets Groups Projects
Commit 7dc05499 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #10530. Checking basis transformations.

parent 77a77b85
No related merge requests found
...@@ -86,7 +86,6 @@ class CutMD(DataProcessorAlgorithm): ...@@ -86,7 +86,6 @@ class CutMD(DataProcessorAlgorithm):
# Get the min max extents # Get the min max extents
extents = list() extents = list()
print new_coords
for i in range(0,3): for i in range(0,3):
# Vertical slice down each corner for each dimension, then determine the max, min and use as extents # Vertical slice down each corner for each dimension, then determine the max, min and use as extents
extents.append(np.amin(new_coords[:,i])) extents.append(np.amin(new_coords[:,i]))
...@@ -99,6 +98,7 @@ class CutMD(DataProcessorAlgorithm): ...@@ -99,6 +98,7 @@ class CutMD(DataProcessorAlgorithm):
extents.append(ws.getDimension(i + 3).getMinimum()) extents.append(ws.getDimension(i + 3).getMinimum())
extents.append(ws.getDimension(i + 3).getMaximum()) extents.append(ws.getDimension(i + 3).getMaximum())
print extents
return extents return extents
def __uvw_from_projection_table(self, projection_table): def __uvw_from_projection_table(self, projection_table):
...@@ -118,8 +118,15 @@ class CutMD(DataProcessorAlgorithm): ...@@ -118,8 +118,15 @@ class CutMD(DataProcessorAlgorithm):
self.__replace = replace self.__replace = replace
def replace(self, entry): def replace(self, entry):
if entry > 0: if np.absolute(entry) == 1:
return self.__replace if entry > 0:
return self.__replace
else:
return "-" + self.__replace
elif entry == 0:
return 0
else:
return "%.2f%s" % ( entry, self.__replace )
return entry return entry
crystallographic_names = ['zeta', 'eta', 'xi' ] crystallographic_names = ['zeta', 'eta', 'xi' ]
...@@ -184,14 +191,12 @@ class CutMD(DataProcessorAlgorithm): ...@@ -184,14 +191,12 @@ class CutMD(DataProcessorAlgorithm):
cut_alg.setProperty("AxisAligned", False) cut_alg.setProperty("AxisAligned", False)
# Now for the basis vectors. # Now for the basis vectors.
for i in range(0, to_cut.getNumDims()): for i in range(0, to_cut.getNumDims()):
logger.warning("WARNING....")
if i <= 2: if i <= 2:
label = projection_labels[i] label = projection_labels[i]
unit = "TODO" # Haven't figured out how to do this yet. unit = "TODO" # Haven't figured out how to do this yet.
vec = projection[i] vec = projection[i]
value = "%s, %s, %s" % ( label, unit, ",".join(map(str, vec))) value = "%s, %s, %s" % ( label, unit, ",".join(map(str, vec)))
cut_alg.setPropertyValue("BasisVector{0}".format(i) , value) cut_alg.setPropertyValue("BasisVector{0}".format(i) , value)
logger.warning("BasisVector{0}".format(i))
if i > 2: if i > 2:
raise RuntimeError("Not implmented yet for non-crystallographic basis vector generation.") raise RuntimeError("Not implmented yet for non-crystallographic basis vector generation.")
cut_alg.setProperty("OutputExtents", extents) cut_alg.setProperty("OutputExtents", extents)
......
import unittest import unittest
import testhelpers import testhelpers
import numpy as np
from mantid.simpleapi import * from mantid.simpleapi import *
from mantid.api import IMDHistoWorkspace from mantid.api import IMDHistoWorkspace
...@@ -36,9 +36,9 @@ class CutMDTest(unittest.TestCase): ...@@ -36,9 +36,9 @@ class CutMDTest(unittest.TestCase):
self.assertEquals(self.__in_md.getDimension(1).getMaximum(), out_md.getDimension(1).getMaximum()) 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).getMinimum(), out_md.getDimension(2).getMinimum())
self.assertEquals(self.__in_md.getDimension(2).getMaximum(), out_md.getDimension(2).getMaximum()) 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("['zeta', 0, 0]", out_md.getDimension(0).getName() )
self.assertEquals("[0.0, 'eta', 0.0]", out_md.getDimension(1).getName() ) self.assertEquals("[0, 'eta', 0]", out_md.getDimension(1).getName() )
self.assertEquals("[0.0, 0.0, 'xi']", out_md.getDimension(2).getName() ) self.assertEquals("[0, 0, 'xi']", out_md.getDimension(2).getName() )
def test_wrong_projection_workspace_format_wrong_column_numbers(self): def test_wrong_projection_workspace_format_wrong_column_numbers(self):
projection = CreateEmptyTableWorkspace() projection = CreateEmptyTableWorkspace()
...@@ -57,8 +57,41 @@ class CutMDTest(unittest.TestCase): ...@@ -57,8 +57,41 @@ class CutMDTest(unittest.TestCase):
# Incorrect number of rows i.e. zero in this case as none added. # 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]) 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): def test_non_orthogonal_slice_with_scaling(self):
pass # 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__': if __name__ == '__main__':
unittest.main() unittest.main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment