Skip to content

Commit

Permalink
Re #6151 Move NormaliseByThickness to API2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Dec 3, 2012
1 parent 2830dd0 commit 176e55f
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

class HFIRSANSReduction(PythonAlgorithm):

def category(self):
return "Workflow\\SANS;PythonAlgorithms"

def name(self):
return "HFIRSANSReduction"

def PyInit(self):
#TODO: allow for multiple files to be summed
#TODO: allow for input workspace instead of file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
*WIKI*"""

from MantidFramework import *
from mantidsimple import *
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *

class NormaliseByThickness(PythonAlgorithm):
"""
Expand All @@ -19,31 +20,38 @@ def name(self):
return "NormaliseByThickness"

def PyInit(self):
# Input workspace
self.declareWorkspaceProperty("InputWorkspace", "", Direction=Direction.Input, Description="Workspace to be normalised")
self.declareWorkspaceProperty("OutputWorkspace", "", Direction=Direction.Output, Description="Name of the workspace that will contain the normalised data")
self.declareProperty("SampleThickness", 0.0, Direction=Direction.Input, Description="Optional sample thickness value. If not provided the sample-thickness run property will be used.")
self.declareProperty("OutputMessage", "", Direction=Direction.Output)
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input))
self.declareProperty(MatrixWorkspaceProperty("OutputWorkspace", "",
direction = Direction.Output),
"Name of the workspace that will contain the normalised data")
self.declareProperty("SampleThickness", 0.0,
"Optional sample thickness value. If not provided the sample-thickness run property will be used.")
self.declareProperty("OutputMessage", "",
direction=Direction.Output, doc = "Output message")

def PyExec(self):
input_ws_name = self.getPropertyValue("InputWorkspace")
if mtd[input_ws_name].getAxis(0).getUnit().name() != "Wavelength":
raise RuntimeError, "NormaliseByThickness expects an input workspace with units of Wavelength"
input_ws = self.getProperty("InputWorkspace").value

# Determine whether we should use the input thickess or try to read it from the run properties
thickness = self.getProperty("SampleThickness")
# Determine whether we should use the input thickness or try
# to read it from the run properties
thickness = self.getProperty("SampleThickness").value
if thickness <= 0:
if mtd[input_ws_name].getRun().hasProperty("sample-thickness"):
thickness = mtd[input_ws_name].getRun().getProperty("sample-thickness").value
if input_ws.getRun().hasProperty("sample-thickness"):
thickness = input_ws.getRun().getProperty("sample-thickness").value
if thickness <= 0:
raise RuntimeError, "NormaliseByThickness could not get the sample thickness"
Logger.get("NormaliseByThickness").error("NormaliseByThickness could not get the sample thickness")
return
else:
raise RuntimeError, "NormaliseByThickness could not get the sample thickness"
Logger.get("NormaliseByThickness").error("NormaliseByThickness could not get the sample thickness")
return

output_ws_name = self.getPropertyValue("OutputWorkspace")
a = self.executeSubAlg(Scale, input_ws_name, OutputWorkspace=output_ws_name, Factor=1.0/thickness, Operation="Multiply")
self._setWorkspaceProperty("OutputWorkspace", a._getWorkspaceProperty("OutputWorkspace"))
output_ws_name = self.getPropertyValue("OutputWorkspace")
api.Scale(InputWorkspace=input_ws,
OutputWorkspace=output_ws_name,
Factor=1.0/thickness, Operation="Multiply")

self.setProperty("OutputWorkspace", output_ws_name)
self.setProperty("OutputMessage", "Normalised by thickness [%g cm]" % thickness)

mtd.registerPyAlgorithm(NormaliseByThickness())
registerAlgorithm(NormaliseByThickness())
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

class SANSAzimuthalAverage1D(PythonAlgorithm):

def category(self):
return "Workflow\\SANS;PythonAlgorithms"

def name(self):
return "SANSAzimuthalAverage1D"

def PyInit(self):
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

class SANSBeamSpreaderTransmission(PythonAlgorithm):

def category(self):
return "Workflow\\SANS;PythonAlgorithms"

def name(self):
return "SANSBeamSpreaderTransmission"

def PyInit(self):
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

class SANSDirectBeamTransmission(PythonAlgorithm):

def category(self):
return "Workflow\\SANS;PythonAlgorithms"

def name(self):
return "SANSDirectBeamTransmission"

def PyInit(self):
self.declareProperty(MatrixWorkspaceProperty("InputWorkspace", "",
direction=Direction.Input))
Expand Down

0 comments on commit 176e55f

Please sign in to comment.