Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add MSGDiffractionReduction algorithm, replace Python in UI
Refs #10215
- Loading branch information
Showing
3 changed files
with
139 additions
and
46 deletions.
There are no files selected for viewing
100 changes: 100 additions & 0 deletions
100
...ramework/PythonInterface/plugins/algorithms/WorkflowAlgorithms/MSGDiffractionReduction.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
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 'Workflow\\MIDAS;PythonAlgorithms;Indirect' | ||
|
||
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.') | ||
|
||
def validateInputs(self): | ||
""" | ||
Checks for issues with user input. | ||
""" | ||
issues = dict() | ||
|
||
input_files = self.getProperty('InputFiles').value | ||
if len(input_files) == 0: | ||
issues['InputFiles'] = 'InputFiles must contain at least one filename' | ||
|
||
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]' | ||
|
||
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') | ||
|
||
ipf_filename = instrument_name + '_diffraction_' + mode + '_Parameters.xml' | ||
|
||
reducer = MSGDiffractionReducer() | ||
reducer.set_instrument_name(instrument_name) | ||
reducer.set_detector_range(detector_range[0] - 1, detector_range[1] - 1) | ||
reducer.set_parameter_file(ipf_filename) | ||
reducer.set_sum_files(sum_files) | ||
|
||
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 = recuer.get_result_workspaces() | ||
GroupWorkspaces(InputWorkspaces=result_ws_list, OutputWorkspace=output_ws_group) | ||
self.setProperty('OutputWorkspaceGroup', output_ws_group) | ||
|
||
EndTime('MSGDiffractionReduction') | ||
|
||
|
||
AlgorithmFactory.subscribe(MSGDiffractionReduction) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters