Skip to content

Commit

Permalink
refs #10530. More checks and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenArnold committed Nov 14, 2014
1 parent b31bf4d commit fe90ba7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Expand Up @@ -179,6 +179,8 @@ def __verify_projection_input(self, projection_table):
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
Expand All @@ -187,15 +189,20 @@ 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 # 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

Expand All @@ -222,7 +229,6 @@ def PyExec(self):
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()
Expand Down
Expand Up @@ -24,7 +24,18 @@ def test_exec_throws_if_not_a_hkl_workspace(self):
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)
Expand Down

0 comments on commit fe90ba7

Please sign in to comment.