forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTOFTOFCropWorkspace.py
82 lines (65 loc) · 3.08 KB
/
TOFTOFCropWorkspace.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# 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 +
from mantid.api import PythonAlgorithm, AlgorithmFactory, WorkspaceProperty # , WorkspaceUnitValidator
from mantid.kernel import Direction
import mantid.simpleapi as api
class TOFTOFCropWorkspace(PythonAlgorithm):
""" Crop empty time channels
"""
def __init__(self):
PythonAlgorithm.__init__(self)
def category(self):
""" Return category
"""
return "Workflow\\MLZ\\TOFTOF;Transforms\\Splitting"
def seeAlso(self):
return [ "TOFTOFMergeRuns","CorrectTOF" ]
def name(self):
""" Return summary
"""
return "TOFTOFCropWorkspace"
def summary(self):
return "Crop empty time channels."
def PyInit(self):
""" Declare properties
"""
# better would be to use the validator, but it fails if WorkspaceGroup is given as an input
# self.declareProperty(WorkspaceProperty("InputWorkspace", "", direction=Direction.Input,
# validator=WorkspaceUnitValidator('TOF')),
# doc="Input workspace.")
self.declareProperty(WorkspaceProperty("InputWorkspace", "", direction=Direction.Input),
doc="Input workspace.")
self.declareProperty(WorkspaceProperty("OutputWorkspace", "", direction=Direction.Output),
doc="Name of the workspace that will contain the results")
return
def validateInputs(self):
issues = dict()
input_workspace = self.getProperty("InputWorkspace").value
xunit = input_workspace.getAxis(0).getUnit().unitID()
if xunit != 'TOF':
issues['InputWorkspace'] = "X axis units must be TOF. "
# check for required properties
run = input_workspace.getRun()
if not run.hasProperty('channel_width'):
issues['InputWorkspace'] = "Input workpsace must have sample log channel_width."
if not run.hasProperty('full_channels'):
issues['InputWorkspace'] = "Input workpsace must have sample log full_channels."
if not run.hasProperty('TOF1'):
issues['InputWorkspace'] = "Input workpsace must have sample log TOF1."
return issues
def PyExec(self):
""" Main execution body
"""
inputws = self.getProperty("InputWorkspace").value
run = inputws.getRun()
channel_width = float(run.getLogData('channel_width').value)
full_channels = float(run.getLogData('full_channels').value)
tof1 = float(run.getLogData('TOF1').value)
outputws = api.CropWorkspace(inputws, XMin=0., XMax=full_channels*channel_width + tof1, StoreInADS=False)
self.setProperty("OutputWorkspace", outputws)
# Register algorithm with Mantid.
AlgorithmFactory.subscribe(TOFTOFCropWorkspace)