forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SetDetScale.py
85 lines (67 loc) · 3.02 KB
/
SetDetScale.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
# 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, InstrumentValidator, FileProperty, FileAction
from mantid.kernel import Direction, StringArrayProperty
import mantid.simpleapi as api
class SetDetScale(PythonAlgorithm):
"""
Class to set instrument detScale for SaveHKL and AnvredCorrection
"""
def category(self):
"""
Mantid required
"""
return "DataHandling\\Instrument"
def name(self):
"""
Mantid required
"""
return "SetDetScale"
def summary(self):
"""
Mantid required
"""
return "Set/change the detScale parameters for a MatrixWorkspace or PeaksWorkspace instrument"
def PyInit(self):
self.declareProperty(WorkspaceProperty("Workspace", "",
validator=InstrumentValidator(),
direction=Direction.InOut),
doc="MatrixWorkspace or PeaksWorkspace with instrument.")
# List of parameters
self.declareProperty(StringArrayProperty("DetScaleList",
direction=Direction.Input),
doc="Comma separated list detectorNumbers:detScales eg. 13:1.046504,14:1.259293")
self.declareProperty(FileProperty(name="DetScaleFile", defaultValue="",
action=FileAction.OptionalLoad,
extensions=["txt"]),
"Optional text file with detector number and its scale on each line separated by spaces")
def PyExec(self):
ws = self.getProperty("Workspace").value
# Now input all the components
components = self.getProperty("DetScaleList").value
listParse = []
scaleDict = {}
#Read scales from file
sc_filename = self.getProperty("DetScaleFile").value
if sc_filename:
scfile = open(sc_filename, "r")
lines = scfile.readlines()
for line in lines:
columns = line.split() # splits on whitespace characters
key = columns[0]
scaleDict[key] = columns[1]
#Overwrite any scales given in file
for component in components:
comp, value = component.split(":")
key = comp
scaleDict[key] = value
for key in scaleDict.keys():
listParse.append({"ParameterName":"detScale"+key, "Value":scaleDict[key]})
for dList in listParse:
api.SetInstrumentParameter(Workspace=ws,ParameterType="Number",**dList)
# Register algorithm with Mantid.
AlgorithmFactory.subscribe(SetDetScale)