-
Notifications
You must be signed in to change notification settings - Fork 122
/
MSGDiffractionReduction.py
115 lines (86 loc) · 4.46 KB
/
MSGDiffractionReduction.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
from mantid.simpleapi import *
from mantid.api import *
from mantid.kernel import *
from mantid import config
import os.path, math
class MSGDiffractionReduction(PythonAlgorithm):
def category(self):
return 'Diffraction;PythonAlgorithms'
def summary(self):
return 'Calculates the scattering & transmission for Indirect Geometry spectrometers.'
def PyInit(self):
self.declareProperty(StringArrayProperty(name='InputFiles'),
doc='Comma separated list of input files.')
self.declareProperty(name='SumFiles', defaultValue=False,
doc='Enabled to sum spectra from each input file.')
self.declareProperty(name='Instrument', defaultValue='IRIS',
validator=StringListValidator(['IRIS', 'OSIRIS', 'TOSCA', 'VESUVIO']),
doc='Instrument used for run')
self.declareProperty(name='Mode', defaultValue='diffspec',
validator=StringListValidator(['diffspec', 'diffonly']),
doc='Diffraction mode used')
self.declareProperty(IntArrayProperty(name='DetectorRange'),
doc='Range of detectors to use.')
self.declareProperty(name='RebinParam', defaultValue='',
doc='Rebin parameters.')
self.declareProperty(WorkspaceGroupProperty('OutputWorkspaceGroup', '',
direction=Direction.Output, optional=PropertyMode.Optional),
doc='Optionally group the result workspaces.')
self.declareProperty(StringArrayProperty(name='SaveFormats'),
doc='Save formats to save output in.')
def validateInputs(self):
"""
Checks for issues with user input.
"""
issues = dict()
# Validate input files
input_files = self.getProperty('InputFiles').value
if len(input_files) == 0:
issues['InputFiles'] = 'InputFiles must contain at least one filename'
# Validate detector range
detector_range = self.getProperty('DetectorRange').value
if len(detector_range) != 2:
issues['DetectorRange'] = 'DetectorRange must be an array of 2 values only'
else:
if detector_range[0] > detector_range[1]:
issues['DetectorRange'] = 'DetectorRange must be in format [lower_index,upper_index]'
# Validate save formats
save_formats = self.getProperty('SaveFormats').value
valid_formats = ['gss', 'nxs', 'ascii']
for s_format in save_formats:
if s_format not in valid_formats:
issues['SaveFormats'] = 'Contains invalid save formats'
break
return issues
def PyExec(self):
from IndirectCommon import StartTime, EndTime
from IndirectDiffractionReduction import MSGDiffractionReducer
StartTime('MSGDiffractionReduction')
input_files = self.getProperty('InputFiles').value
sum_files = self.getProperty('SumFiles').value
instrument_name = self.getPropertyValue('Instrument')
mode = self.getPropertyValue('Mode')
detector_range = self.getProperty('DetectorRange').value
rebin_string = self.getPropertyValue('RebinParam')
output_ws_group = self.getPropertyValue('OutputWorkspaceGroup')
save_formats = self.getProperty('SaveFormats').value
ipf_filename = instrument_name + '_diffraction_' + mode + '_Parameters.xml'
reducer = MSGDiffractionReducer()
reducer.set_instrument_name(instrument_name)
reducer.set_detector_range(int(detector_range[0] - 1), int(detector_range[1] - 1))
reducer.set_parameter_file(ipf_filename)
reducer.set_sum_files(sum_files)
reducer.set_save_formats(save_formats)
for in_file in input_files:
reducer.append_data_file(in_file)
if rebin_string != '':
reducer.set_rebin_string(rebin_string)
if instrument_name == 'VESUVIO':
reducer.append_load_option('Mode', 'FoilOut')
reducer.reduce()
if output_ws_group != '':
result_ws_list = reducer.get_result_workspaces()
GroupWorkspaces(InputWorkspaces=result_ws_list, OutputWorkspace=output_ws_group)
self.setProperty('OutputWorkspaceGroup', output_ws_group)
EndTime('MSGDiffractionReduction')
AlgorithmFactory.subscribe(MSGDiffractionReduction)