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

refs #11304. Add the ability to merge md workspaces

parent f0b9e427
No related branches found
No related tags found
No related merge requests found
......@@ -11,9 +11,9 @@ class CreateMD(DataProcessorAlgorithm):
def __possible_emodes(self):
return ['Elastic', 'Direct', 'Indirect']
def __single_gen_sqw(self, input_workspace, emode, alatt=[], angdeg=[], u=[], v=[], psi=None, gl=None, gs=None):
def __single_run(self, input_workspace, emode, alatt=[], angdeg=[], u=[], v=[], psi=None, gl=None, gs=None):
import numpy as np
ub_params = [any(alatt), any(angdeg), any(u), any(v)]
ub_params = map(any, [alatt, angdeg, u, v])
goniometer_params = [psi, gl, gs]
if any(ub_params) and not all(ub_params):
raise ValueError("Either specify all of alatt, angledeg, u, v or none of them")
......@@ -36,8 +36,8 @@ class CreateMD(DataProcessorAlgorithm):
SetGoniometer(Workspace=input_workspace, Axis0=axis0, Axis1=axis1, Axis2=axis2)
min_extents, max_extents = ConvertToMDMinMaxLocal(InputWorkspace=input_workspace,QDimensions='Q3D',dEAnalysisMode=emode)
output_workspace = ConvertToMD(InputWorkspace=input_workspace, QDimensions='Q3D', QConversionScales='HKL',dEAnalysisMode=emode, MinValues=min_extents, MaxValues=max_extents)
return output_workspace
output_run = ConvertToMD(InputWorkspace=input_workspace, QDimensions='Q3D', QConversionScales='HKL',dEAnalysisMode=emode, MinValues=min_extents, MaxValues=max_extents)
return output_run
def category(self):
return 'MDAlgorithms'
......@@ -84,23 +84,23 @@ class CreateMD(DataProcessorAlgorithm):
if len(input_workspaces) < 1:
raise ValueError("Need one or more input workspace")
if not emode in self.__possible_emodes():
raise ValueError("Unknown emode %s Allowed values are %s" % (emode, self.__possible_emodes()))
output_workspaces = list()
output_workspace = None
run_md = None
for ws in input_workspaces:
out_ws = self.__single_gen_sqw(input_workspace=ws, emode=emode, alatt=alatt, angdeg=angdeg, u=u, v=v, psi=psi, gl=gl, gs=gs)
output_workspaces.append(out_ws)
# TODO. Need to merge runs.
if len(input_workspaces) > 1:
raise RuntimeError("Merging not implmented yet")
# TODO We will need to merge everything
# TODO We should offer to merge file-backed
self.setProperty("OutputWorkspace", output_workspaces[0])
run_md = self.__single_run(input_workspace=ws, emode=emode, alatt=alatt, angdeg=angdeg, u=u, v=v, psi=psi, gl=gl, gs=gs)
if not output_workspace:
output_workspace = run_md.rename()
else:
print output_workspace.name()
print run_md.name()
output_workspace += run_md # Accumulate results via PlusMD. TODO, will need to find the best performance method for doing this.
self.setProperty("OutputWorkspace", output_workspace)
......
......@@ -6,14 +6,6 @@ from mantid.api import AlgorithmManager, IMDHistoWorkspace, IMDEventWorkspace
class CreateMDTest(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
#DeleteWorkspace(self.__in_md )
def test_init(self):
alg = AlgorithmManager.create("CreateMD")
......@@ -39,7 +31,8 @@ class CreateMDTest(unittest.TestCase):
alg.setProperty("v", [1,0,0])
def test_execute_single_workspace(self):
input_workspace = CreateSampleWorkspace()
input_workspace = CreateSampleWorkspace(NumBanks=1, BinWidth=2000)
AddSampleLog(input_workspace, LogName='Ei', LogText='12.0', LogType='Number')
alg = AlgorithmManager.create("CreateMD")
......@@ -56,6 +49,34 @@ class CreateMDTest(unittest.TestCase):
out_ws = alg.getProperty("OutputWorkspace").value
self.assertTrue(isinstance(out_ws, IMDEventWorkspace), "Expected an MDEventWorkspace back")
DeleteWorkspace(input_workspace)
def test_execute_multiple_runs(self):
input_workspace1 = CreateSampleWorkspace(NumBanks=1, BinWidth=2000)
AddSampleLog(input_workspace1, LogName='Ei', LogText='12.0', LogType='Number')
input_workspace2 = CreateSampleWorkspace(NumBanks=1, BinWidth=2000)
AddSampleLog(input_workspace2, LogName='Ei', LogText='12.0', LogType='Number')
alg = AlgorithmManager.create("CreateMD")
alg.setRethrows(True)
alg.setChild(True)
alg.initialize()
alg.setPropertyValue("OutputWorkspace", "mdworkspace")
alg.setProperty("InputWorkspaces", [input_workspace1.name(), input_workspace2.name()]) # Two input workspaces
alg.setProperty("Alatt", [1,1,1])
alg.setProperty("Angdeg", [90,90,90])
alg.setProperty("u", [0,0,1])
alg.setProperty("v", [1,0,0])
alg.execute()
out_ws = alg.getProperty("OutputWorkspace").value
lastAlg = out_ws.getHistory().lastAlgorithm()
self.assertEqual("PlusMD", lastAlg.name(), "Last operation should have been to merge individually converted runs together.")
self.assertTrue(isinstance(out_ws, IMDEventWorkspace), "Expected an MDEventWorkspace back")
DeleteWorkspace(input_workspace1)
DeleteWorkspace(input_workspace2)
......
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