Skip to content

Commit

Permalink
refs #10530. Add Axes check.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 14, 2014
1 parent a1c00b1 commit b31bf4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Expand Up @@ -3,6 +3,7 @@
from mantid.simpleapi import *
import numpy as np
import os.path
import re


class CutMD(DataProcessorAlgorithm):
Expand Down Expand Up @@ -37,6 +38,8 @@ def PyInit(self):

self.declareProperty(name="NoPix", defaultValue=False, doc="If False creates a full MDEventWorkspaces as output. True to create an MDHistoWorkspace as output. This is DND only in Horace terminology.")

self.declareProperty(name="CheckAxes", defaultValue=True, doc="Check that the axis look to be correct, and abort if not.")


def __to_mantid_slicing_binning(self, horace_binning, to_cut, dimension_index):
dim = to_cut.getDimension(dimension_index)
Expand Down Expand Up @@ -141,17 +144,28 @@ def replace(self, entry):
labels.append( [cmapping.replace(x) for x in projection[i] ] )

return labels


def PyExec(self):
to_cut = self.getProperty("InputWorkspace").value
nopix = self.getProperty("NoPix").value


def __verify_input_workspace(self, to_cut):
coord_system = to_cut.getSpecialCoordinateSystem()
if not coord_system == SpecialCoordinateSystem.HKL:
raise ValueError("Input Workspace must be in reciprocal lattice dimensions (HKL)")


projection_table = self.getProperty("Projection").value
ndims = to_cut.getNumDims()
if ndims < 3 or ndims > 4:
raise ValueError("Input Workspace should be 3 or 4 dimensional")

# Try to sanity check the order of the dimensions. This is important.
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):
dimension = to_cut.getDimension(i)
p = re.compile(predicates[i])
if not p.match( dimension.getName() ):
raise ValueError("Dimensions must be in order H, K, L")

def __verify_projection_input(self, projection_table):
if isinstance(projection_table, ITableWorkspace):
column_names = set(projection_table.getColumnNames())
logger.warning(str(column_names))
Expand All @@ -161,6 +175,14 @@ def PyExec(self):
raise ValueError("Projection table schema is wrong! Column names received: " + str(column_names) )
if projection_table.rowCount() != 3:
raise ValueError("Projection table expects 3 rows")

def PyExec(self):
to_cut = self.getProperty("InputWorkspace").value
self.__verify_input_workspace(to_cut)
nopix = self.getProperty("NoPix").value

projection_table = self.getProperty("Projection").value
self.__verify_projection_input(projection_table)

p1_bins = self.getProperty("P1Bin").value
p2_bins = self.getProperty("P2Bin").value
Expand All @@ -179,8 +201,6 @@ def PyExec(self):

extents = self.__calculate_extents(v, u, w, to_cut)



projection_labels = self.__make_labels(projection)

cut_alg_name = "BinMD" if nopix else "SliceMD"
Expand Down
Expand Up @@ -27,7 +27,7 @@ def test_exec_throws_if_not_a_hkl_workspace(self):
self.assertRaises(RuntimeError, CutMD, InputWorkspace=test_md, OutputWorkspace="out_ws", P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1])

def test_slice_to_original(self):
out_md = CutMD(self.__in_md, P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1])
out_md = CutMD(self.__in_md, P1Bin=[0.1], P2Bin=[0.1], P3Bin=[0.1], CheckAxes=False)
self.assertTrue(isinstance(out_md, IMDEventWorkspace), "Should default to producing an IMDEventWorkspace.")
# No rotation. Basis vectors should have been left the same, so no extent changes.
self.assertEquals(self.__in_md.getDimension(0).getMinimum(), out_md.getDimension(0).getMinimum())
Expand All @@ -45,7 +45,7 @@ def test_wrong_projection_workspace_format_wrong_column_numbers(self):
projection = CreateEmptyTableWorkspace()
projection.addColumn("double", "u")
# missing other columns
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], CheckAxes=False)

def test_wrong_table_workspace_format_wrong_row_numbers(self):
projection = CreateEmptyTableWorkspace()
Expand All @@ -56,7 +56,7 @@ def test_wrong_table_workspace_format_wrong_row_numbers(self):
projection.addColumn("double", "offset")
projection.addColumn("string", "type")
# 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], CheckAxes=False)

def test_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
Expand Down

0 comments on commit b31bf4d

Please sign in to comment.