Skip to content

Commit

Permalink
Refs #8528. Allow reducing multi slices from event workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gesnerpassos committed Nov 29, 2013
1 parent f76ec3b commit 884ff7f
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions Code/Mantid/scripts/SANS/ISISCommandInterface.py
Expand Up @@ -638,23 +638,49 @@ def _applySuffix(result, name_suffix):
RenameWorkspace(InputWorkspace=old,OutputWorkspace= result)
return result

def _common_substring(val1, val2):
l = []
for i in range(len(val1)):
if val1[i]==val2[i]: l.append(val1[i])
else:
return ''.join(l)

def _group_workspaces(list_of_values, outputname):
allnames = ','.join(list_of_values)
GroupWorkspaces(InputWorkspaces=allnames, OutputWorkspace=outputname)

def _reduceAllSlices():
if ReductionSingleton().getNumSlices() > 1:
slices = []
for index in range(ReductionSingleton().getNumSlices()):
ReductionSingleton().setSliceIndex(index)
slices.append(ReductionSingleton()._reduce())
ReductionSingleton().setSliceIndex(0)
group_name = _common_substring(slices[0], slices[1])
if group_name[-2] == "_":
group_name = group_name[:-2]
_group_workspaces(slices, group_name)
return group_name
else:
return ReductionSingleton()._reduce()



result = ""
if ReductionSingleton().get_sample().loader.periods_in_file == 1:
result = ReductionSingleton()._reduce()
result = _reduceAllSlices()
return _applySuffix(result, name_suffix)

calculated = []
try:
for period in ReductionSingleton().get_sample().loader.entries:
_setUpPeriod(period)
calculated.append(ReductionSingleton()._reduce())
calculated.append(_reduceAllSlices())

finally:
if len(calculated) > 0:
allnames = ','.join(calculated)
result = ReductionSingleton().get_out_ws_name(show_period=False)
GroupWorkspaces(OutputWorkspace=result, InputWorkspaces=allnames)
_group_workspaces(calculated, result)

return _applySuffix(result, name_suffix)

Expand Down

0 comments on commit 884ff7f

Please sign in to comment.