-
Notifications
You must be signed in to change notification settings - Fork 121
/
DirectILLIntegrateVanadium.py
153 lines (131 loc) · 7.09 KB
/
DirectILLIntegrateVanadium.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# -*- coding: utf-8 -*-# 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 +
import DirectILL_common as common
import ILL_utilities as utils
from mantid.api import (AlgorithmFactory, DataProcessorAlgorithm, InstrumentValidator, ITableWorkspaceProperty,
MatrixWorkspaceProperty, Progress, PropertyMode, WorkspaceProperty, WorkspaceUnitValidator)
from mantid.kernel import (CompositeValidator, Direction, EnabledWhenProperty, FloatBoundedValidator, Property,
PropertyCriterion, StringListValidator)
from mantid.simpleapi import (ComputeCalibrationCoefVan, MaskDetectorsIf)
class DirectILLIntegrateVanadium(DataProcessorAlgorithm):
"""A workflow algorithm which integrates the vanadium data."""
def __init__(self):
"""Initialize an instance of the algorithm."""
DataProcessorAlgorithm.__init__(self)
def category(self):
"""Return the algorithm's category."""
return common.CATEGORIES
def seeAlso(self):
return [ "DirectILLReduction" ]
def name(self):
"""Return the algorithm's name."""
return 'DirectILLIntegrateVanadium'
def summary(self):
"""Return a summary of the algorithm."""
return 'Integrate vanadium workspace. Part of the TOF workflow at ILL.'
def version(self):
"""Return the algorithm's version."""
return 1
def PyExec(self):
"""Executes the data reduction workflow."""
progress = Progress(self, 0.0, 1.0, 4)
self._subalgLogging = self.getProperty(common.PROP_SUBALG_LOGGING).value == common.SUBALG_LOGGING_ON
cleanupMode = self.getProperty(common.PROP_CLEANUP_MODE).value
self._cleanup = utils.Cleanup(cleanupMode, self._subalgLogging)
progress.report('Loading inputs')
mainWS = self._inputWS()
progress.report('Integrating')
mainWS = self._integrate(mainWS)
progress.report('Masking zeros')
mainWS = self._maskZeros(mainWS)
self._finalize(mainWS)
progress.report('Done')
def PyInit(self):
inputWorkspaceValidator = CompositeValidator()
inputWorkspaceValidator.add(InstrumentValidator())
inputWorkspaceValidator.add(WorkspaceUnitValidator('TOF'))
positiveFloat = FloatBoundedValidator(lower=0)
self.declareProperty(MatrixWorkspaceProperty(
name=common.PROP_INPUT_WS,
defaultValue='',
validator=inputWorkspaceValidator,
optional=PropertyMode.Mandatory,
direction=Direction.Input),
doc='A workspace to be integrated.')
self.declareProperty(WorkspaceProperty(name=common.PROP_OUTPUT_WS,
defaultValue='',
direction=Direction.Output),
doc='The integrated workspace.')
self.declareProperty(name=common.PROP_CLEANUP_MODE,
defaultValue=utils.Cleanup.ON,
validator=StringListValidator([
utils.Cleanup.ON,
utils.Cleanup.OFF]),
direction=Direction.Input,
doc='What to do with intermediate workspaces.')
self.declareProperty(name=common.PROP_SUBALG_LOGGING,
defaultValue=common.SUBALG_LOGGING_OFF,
validator=StringListValidator([
common.SUBALG_LOGGING_OFF,
common.SUBALG_LOGGING_ON]),
direction=Direction.Input,
doc='Enable or disable subalgorithms to ' + 'print in the logs.')
self.declareProperty(ITableWorkspaceProperty(
name=common.PROP_EPP_WS,
defaultValue='',
direction=Direction.Input,
optional=PropertyMode.Mandatory),
doc='Table workspace containing results from the FindEPP algorithm.')
self.declareProperty(name=common.PROP_DWF_CORRECTION,
defaultValue=common.DWF_ON,
validator=StringListValidator([
common.DWF_ON,
common.DWF_OFF]),
direction=Direction.Input,
doc='Enable or disable the correction for the Debye-Waller factor for ' + common.PROP_OUTPUT_WS + '.')
self.declareProperty(name=common.PROP_TEMPERATURE,
defaultValue=Property.EMPTY_DBL,
validator=positiveFloat,
direction=Direction.Input,
doc='Vanadium temperature in Kelvin for Debye-Waller correction, '
+ 'overrides the default value from the sample logs.')
self.setPropertySettings(common.PROP_TEMPERATURE, EnabledWhenProperty(common.PROP_DWF_CORRECTION,
PropertyCriterion.IsDefault))
def _inputWS(self):
"""Return the raw input workspace."""
mainWS = self.getProperty(common.PROP_INPUT_WS).value
self._cleanup.protect(mainWS)
return mainWS
def _finalize(self, outWS):
"""Do final cleanup and set the output property."""
self.setProperty(common.PROP_OUTPUT_WS, outWS)
self._cleanup.cleanup(outWS)
self._cleanup.finalCleanup()
def _integrate(self, mainWS):
"""Integrate mainWS applying Debye-Waller correction, if requested."""
eppWS = self.getProperty(common.PROP_EPP_WS).value
calibrationWS = self.getProperty(common.PROP_OUTPUT_WS).value
dwfEnabled = self.getProperty(common.PROP_DWF_CORRECTION).value == common.DWF_ON
temperature = self.getProperty(common.PROP_TEMPERATURE).value
calibrationWS = ComputeCalibrationCoefVan(VanadiumWorkspace=mainWS,
EPPTable=eppWS,
OutputWorkspace=calibrationWS,
Temperature=temperature,
EnableDWF=dwfEnabled,
EnableLogging=self._subalgLogging)
self._cleanup.cleanup(mainWS)
return calibrationWS
def _maskZeros(self, mainWS):
"""Mask zero integrals in mainWS."""
mainWS = MaskDetectorsIf(InputWorkspace=mainWS,
OutputWorkspace=mainWS,
Mode='SelectIf',
Operator='Equal',
Value=0.,
EnableLogging=self._subalgLogging)
return mainWS
AlgorithmFactory.subscribe(DirectILLIntegrateVanadium)