Newer
Older
from __future__ import (absolute_import, division, print_function)
from six import iteritems
import mantid.simpleapi as mantid
class MaxEntWrapper(object):
"""
A class to wrap the different parts
of the MaxEnt and its preprocessing.
This keeps the main MaxEnt class simple.
"""
def __init__(self,maxent):
self.name = "MaxEnt"
self.model = maxent
def loadData(self,inputs):
"""
store the data in the wrapper for later
"""
if "phaseTable" in inputs:
self.phaseTable = inputs["phaseTable"]
else:
self.phaseTable = None
if "maxent" in inputs:
self.maxent = inputs["maxent"]
else:
self.maxent = None
self.model.setRun(inputs["Run"])
"""
runs the relevant parts of the MaxEnt and the preprocessing
"""
try:
if self.phaseTable is not None:
self.model.makePhaseTable(self.phaseTable)
if self.maxent is not None:
self.model.MaxEntAlg(self.maxent)
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
return
class MaxEntModel(object):
"""
A simple class which executes
the relevant algorithms for
the analysis.
"""
def __init__(self):
self.name = "MaxEnt"
def setRun(self,run):
self.run=run
def MaxEntAlg(self,inputs):
"""
Use the MaxEnt alg
"""
alg = mantid.AlgorithmManager.create("MuonMaxent")
alg.initialize()
alg.setChild(True)
for name,value in iteritems(inputs):
alg.setProperty(name,value)
alg.execute()
print(inputs)
self.addOutput(inputs,alg,"OutputWorkspace")
self.addOutput(inputs,alg,"OutputPhaseTable")
self.addOutput(inputs,alg,"OutputDeadTimeTable")
self.addOutput(inputs,alg,"ReconstructedSpectra")
self.addOutput(inputs,alg,"PhaseConvergenceTable")
def makePhaseTable(self,inputs):
"""
generates a phase table from CalMuonDetectorPhases
"""
calcAlg=mantid.AlgorithmManager.create("CalMuonDetectorPhases")
calcAlg.initialize()
calcAlg.setChild(True)
for name,value in iteritems(inputs):
calcAlg.setProperty(name,value)
calcAlg.execute()
name="DetectorTable"
mantid.AnalysisDataService.addOrReplace( inputs[name],calcAlg.getProperty(name).value)
def addOutput(self,inputs,alg,name):
if name in inputs:
mantid.AnalysisDataService.addOrReplace(inputs[name],alg.getProperty(name).value)
if mantid.AnalysisDataService.doesExist(self.run):
group=mantid.AnalysisDataService.retrieve(self.run)
mantid.GroupWorkspaces(OutputWorkspace=self.run)
group.add(inputs[name])
def getName(self):
return self.name