Skip to content

Commit

Permalink
refs #8951. Refactoring, more tests, and stricter input checking.
Browse files Browse the repository at this point in the history
Check workspace groups to ensure they have the same number of workspaces. Group workspace processing is independent on whether we are scaling RHS or LHS.
  • Loading branch information
OwenArnold committed Feb 10, 2014
1 parent 78098d6 commit fb31e74
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 40 deletions.
Expand Up @@ -73,7 +73,13 @@ def __check_workspaces_are_common(self, input_workspace_names):
test_ws = workspaces[i]
if type(exemplar) != type(test_ws):
raise RuntimeError("Input Workspaces must all be of the same type.")
if isinstance(test_ws, WorkspaceGroup):
if test_ws.size() != exemplar.size():
raise RuntimeError("Group Workspaces as InputWorkspaces must have the same number of sub-workspaces.")

def __are_processing_groups(self, input_workspace_names):
test_ws = self.__workspace_from_split_name(input_workspace_names, 0)
return isinstance(test_ws, WorkspaceGroup)

def PyExec(self):

Expand Down Expand Up @@ -103,58 +109,60 @@ def PyExec(self):
comma_separator = ","
no_separator = str()

# Iterate forward through the workspaces
if scaleRHSWorkspace:
lhsWS = self.__workspace_from_split_name(inputWorkspaces, 0)

if isinstance(lhsWS, WorkspaceGroup):
# Identify and process as group workspaces
if self.__are_processing_groups(inputWorkspaces):
workspace_groups = self.__workspaces_from_split_name(inputWorkspaces)

workspace_groups = self.__workspaces_from_split_name(inputWorkspaces)
out_group_separator = no_separator
out_group_workspaces = str()

out_group_separator = no_separator
out_group_workspaces = str()
# TODO. VERIFY THAT ALL INPUT WORKSPACES ARE GROUP WORKSPACES

for i in range(lhsWS.size()):

to_process = str()
out_name = str()
separator = no_separator

for j in range(0, numberOfWorkspaces, 1):
n_sub_workspaces = workspace_groups[0].size()
for i in range(n_sub_workspaces):

to_process = str()
out_name = str()
separator = no_separator

for j in range(0, numberOfWorkspaces, 1):

to_process += separator + workspace_groups[j][i].name()
out_name += workspace_groups[j][i].name()
separator=comma_separator
out_name += ("_" + str(i+1))
to_process += separator + workspace_groups[j][i].name()
out_name += workspace_groups[j][i].name()
separator=comma_separator

out_name += ("_" + str(i+1))

startOverlaps = self.getProperty("StartOverlaps").value
endOverlaps = self.getProperty("EndOverlaps").value
stitched, scaleFactor = Stitch1DMany(InputWorkspaces=to_process, OutputWorkspace=out_name, StartOverlaps=startOverlaps, EndOverlaps=endOverlaps,
startOverlaps = self.getProperty("StartOverlaps").value
endOverlaps = self.getProperty("EndOverlaps").value
stitched, scaleFactor = Stitch1DMany(InputWorkspaces=to_process, OutputWorkspace=out_name, StartOverlaps=startOverlaps, EndOverlaps=endOverlaps,
Params=params, ScaleRHSWorkspace=scaleRHSWorkspace, UseManualScaleFactor=useManualScaleFactor,
ManualScaleFactor=manualScaleFactor)

out_group_workspaces += out_group_separator + out_name
out_group_separator = comma_separator
out_group_workspaces += out_group_separator + out_name
out_group_separator = comma_separator

out_group = GroupWorkspaces(InputWorkspaces=out_group_workspaces)
self.setProperty('OutputWorkspace', out_group)
else:
# TODO. VERIFY THAT ALL INPUT WORKSPACES ARE NOT GROUP WORKSPACES
out_group = GroupWorkspaces(InputWorkspaces=out_group_workspaces)
self.setProperty('OutputWorkspace', out_group)

else:

# Iterate forward through the workspaces
if scaleRHSWorkspace:
lhsWS = self.__workspace_from_split_name(inputWorkspaces, 0)

for i in range(1, numberOfWorkspaces, 1):
rhsWS = self.__workspace_from_split_name(inputWorkspaces, i)
lhsWS, scaleFactor = self.__do_stitch_workspace(lhsWS, rhsWS, startOverlaps[i-1], endOverlaps[i-1], params, scaleRHSWorkspace, useManualScaleFactor, manualScaleFactor)
self.setProperty('OutputWorkspace', lhsWS)
DeleteWorkspace(lhsWS)

# Iterate backwards through the workspaces.
else:
rhsWS = self.__workspace_from_split_name(inputWorkspaces, -1)
for i in range(0, numberOfWorkspaces-1, 1):
lhsWS = self.__workspace_from_split_name(inputWorkspaces, i)
rhsWS, scaleFactor = Stitch1D(LHSWorkspace=lhsWS, RHSWorkspace=rhsWS, StartOverlap=startOverlaps[i-1], EndOverlap=endOverlaps[i-1], Params=params, ScaleRHSWorkspace=scaleRHSWorkspace, UseManualScaleFactor=useManualScaleFactor, ManualScaleFactor=manualScaleFactor)
self.setProperty('OutputWorkspace', rhsWS)
DeleteWorkspace(rhsWS)
# Iterate backwards through the workspaces.
else:
rhsWS = self.__workspace_from_split_name(inputWorkspaces, -1)
for i in range(0, numberOfWorkspaces-1, 1):
lhsWS = self.__workspace_from_split_name(inputWorkspaces, i)
rhsWS, scaleFactor = Stitch1D(LHSWorkspace=lhsWS, RHSWorkspace=rhsWS, StartOverlap=startOverlaps[i-1], EndOverlap=endOverlaps[i-1], Params=params, ScaleRHSWorkspace=scaleRHSWorkspace, UseManualScaleFactor=useManualScaleFactor, ManualScaleFactor=manualScaleFactor)
self.setProperty('OutputWorkspace', rhsWS)
DeleteWorkspace(rhsWS)

self.setProperty('OutScaleFactor', scaleFactor)
return None
Expand Down
Expand Up @@ -76,6 +76,21 @@ def test_workspace_types_differ_throws(self):
pass
finally:
DeleteWorkspace(tbl)

def test_workspace_group_size_differ_throws(self):
ws1 = CreateWorkspace(UnitX="1/q", DataX=self.x, DataY=[3.0, 3.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], NSpec=1, DataE=self.e)
ws2 = CreateWorkspace(UnitX="1/q", DataX=self.x, DataY=[0.0, 0.0, 0.0, 2.0, 2.0, 2.0, 2.0, 0.0, 0.0, 0.0], NSpec=1, DataE=self.e)
ws3 = CreateWorkspace(UnitX="1/q", DataX=self.x, DataY=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0], NSpec=1, DataE=self.e)
input_group_1 = GroupWorkspaces(InputWorkspaces="%s,%s, %s" % (ws1.name(), ws2.name(), ws3.name()))
input_group_2 = GroupWorkspaces(InputWorkspaces="%s,%s" % (ws1.name(), ws2.name()))
try:
stitched, sf = Stitch1DMany(InputWorkspaces='%s,%s' % (input_group_1.name(), input_group_2.name()), Params=0.2)
self.fail("Differing number of sub-workspaces in workspace group. Should have thrown.")
except RuntimeError:
pass
finally:
DeleteWorkspace(input_group_1)

#Cross-check that the result of using Stitch1DMany with two workspaces is the same as using Stitch1D.

def test_stitches_two(self):
Expand Down Expand Up @@ -132,7 +147,7 @@ def test_process_group_workspaces(self):
self.assertTrue(isinstance(stitched, WorkspaceGroup), "Output should be a group workspace")
self.assertEqual(stitched.size(), 3, "Output should contain 3 workspaces")
self.assertEqual(stitched.name(), "stitched", "Output not named correctly")

DeleteWorkspace(input_group_1)



Expand Down

0 comments on commit fb31e74

Please sign in to comment.