-
Notifications
You must be signed in to change notification settings - Fork 122
/
NormaliseByThickness.py
63 lines (51 loc) · 2.63 KB
/
NormaliseByThickness.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#pylint: disable=no-init
import mantid.simpleapi as api
from mantid.api import *
from mantid.kernel import *
class NormaliseByThickness(PythonAlgorithm):
"""
Normalise detector counts by the sample thickness
"""
def category(self):
return "Workflow\\SANS"
def name(self):
return "NormaliseByThickness"
def summary(self):
return "Normalise detector counts by the sample thickness."
def PyInit(self):
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 = self.getProperty("InputWorkspace").value
# 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 input_ws.getRun().hasProperty("sample-thickness"):
thickness = input_ws.getRun().getProperty("sample-thickness").value
if thickness <= 0:
Logger("NormaliseByThickness").error("NormaliseByThickness could not get the sample thickness")
return
else:
Logger("NormaliseByThickness").error("NormaliseByThickness could not get the sample thickness")
return
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)
AlgorithmFactory.subscribe(NormaliseByThickness())