-
Notifications
You must be signed in to change notification settings - Fork 122
/
inelastic_indirect_reducer.py
146 lines (119 loc) · 5.36 KB
/
inelastic_indirect_reducer.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
## IndirectEnergyConversionReducer class
from mantid.simpleapi import *
from msg_reducer import MSGReducer
import inelastic_indirect_reduction_steps as steps
class IndirectReducer(MSGReducer):
"""Reducer class for Inelastic Indirect Spectroscopy.
Example for use:
>> import inelastic_indirect_reducer as iir
>> reducer = iir.IndirectReducer()
>> reducer.set_instrument_name('IRIS')
>> reducer.set_parameter_file('IRIS_graphite_002_Parameters.xml')
>> reducer.set_detector_range(2,52)
>> reducer.append_data_file('IRS21360.raw')
>> reducer.reduce()
Will perform the same steps as the ConvertToEnergy interface does on the
default settings.
"""
_grouping_policy = None
_calibration_workspace = None
_background_start = None
_background_end = None
_detailed_balance_temp = None
_rename_result = True
_save_to_cm_1 = False
_scale_factor = None
def __init__(self):
"""
"""
super(IndirectReducer, self).__init__()
self._grouping_policy = None
self._calibration_workspace = None
self._background_start = None
self._background_end = None
self._detailed_balance_temp = None
self._rename_result = True
self._scale_factor = None
def _setup_steps(self):
"""**NB: This function is run automatically by the base reducer class
and so does not require user interaction.**
Setup the steps for the reduction. Please refer to the individual
steps for details on their operation.
"""
step = steps.IdentifyBadDetectors(MultipleFrames=self._multiple_frames)
self.append_step(step)
# "HandleMonitor" converts the monitor to Wavelength, possibly Unwraps
step = steps.HandleMonitor(MultipleFrames=self._multiple_frames)
self.append_step(step)
# "BackgroundOperations" just does a CalculateFlatBackground at the moment,
# will be extended for SNS stuff
if (self._background_start is not None and
self._background_end is not None):
step = steps.BackgroundOperations(
MultipleFrames=self._multiple_frames)
step.set_range(self._background_start, self._background_end)
self.append_step(step)
# "ApplyCalibration" divides the workspace by the calibration workspace
if self._calibration_workspace is not None:
step = steps.ApplyCalibration()
step.set_is_multiple_frames(self._multiple_frames)
step.set_calib_workspace(self._calibration_workspace)
self.append_step(step)
# "CorrectByMonitor" converts the data into Wavelength, then divides by
# the monitor workspace.
step = steps.CorrectByMonitor(MultipleFrames=self._multiple_frames)
self.append_step(step)
# "ConvertToEnergy" runs ConvertUnits to DeltaE, CorrectKiKf, and also
# Rebin if a rebin string has been specified.
step = steps.ConvertToEnergy(MultipleFrames=self._multiple_frames)
step.set_rebin_string(self._rebin_string)
self.append_step(step)
if self._detailed_balance_temp is not None:
step = steps.DetailedBalance(MultipleFrames=self._multiple_frames)
step.set_temperature(self._detailed_balance_temp)
self.append_step(step)
# Multiplies the scale by the factor specified.
if self._scale_factor is not None:
step = steps.Scaling(MultipleFrames=self._multiple_frames)
step.set_scale_factor(self._scale_factor)
self.append_step(step)
step = steps.Grouping(MultipleFrames=self._multiple_frames)
step.set_grouping_policy(self._grouping_policy)
self.append_step(step)
# "FoldData" puts workspaces that have been chopped back together.
if self._multiple_frames:
if self._fold_multiple_frames:
self.append_step(steps.FoldData())
else:
return
step = steps.ConvertToCm1(MultipleFrames=self._multiple_frames)
step.set_save_to_cm_1(self._save_to_cm_1)
self.append_step(step)
# The "SaveItem" step saves the files in the requested formats.
if len(self._save_formats) > 0:
step = steps.SaveItem()
step.set_formats(self._save_formats)
step.set_save_to_cm_1(self._save_to_cm_1)
self.append_step(step)
if self._rename_result:
step = steps.Naming()
self.append_step(step)
def set_grouping_policy(self, policy):
self._grouping_policy = policy
def set_save_to_cm_1(self, save_to_cm_1):
self._save_to_cm_1 = save_to_cm_1
def set_calibration_workspace(self, workspace):
if not mtd.doesExist(workspace):
raise ValueError("Selected calibration workspace not found.")
self._calibration_workspace = workspace
def set_background(self, start, end):
self._background_start = float(start)
self._background_end = float(end)
def set_detailed_balance(self, temp):
self._detailed_balance_temp = float(temp)
def set_scale_factor(self, scaleFactor):
self._scale_factor = float(scaleFactor)
def set_rename(self, value):
if not isinstance(value, bool):
raise TypeError("value must be either True or False (boolean)")
self._rename_result = value