Skip to content
Snippets Groups Projects
Commit be885078 authored by Samuel Jackson's avatar Samuel Jackson
Browse files

Refs #9960 Use monitor index parameter from IDF.

parent f8b9004b
No related branches found
No related tags found
No related merge requests found
......@@ -58,8 +58,7 @@ def resolution(files, iconOpt, rebinParam, bground,
reducer.set_detector_range(iconOpt['first']-1,iconOpt['last']-1)
for file in files:
reducer.append_data_file(file)
parfile = config['instrumentDefinition.directory']
parfile += instrument +"_"+ analyser +"_"+ reflection +"_Parameters.xml"
parfile = instrument +"_"+ analyser +"_"+ reflection +"_Parameters.xml"
reducer.set_parameter_file(parfile)
reducer.set_grouping_policy('All')
reducer.set_sum_files(True)
......
......@@ -47,6 +47,7 @@ class LoadData(ReductionStep):
def execute(self, reducer, file_ws):
"""Loads the data.
"""
self._reducer = reducer
wsname = ''
for output_ws, filename in self._data_files.iteritems():
......@@ -78,9 +79,6 @@ class LoadData(ReductionStep):
def set_parameter_file(self, value):
self._parameter_file = value
def set_monitor_index(self, index):
self._monitor_index = index
def set_detector_range(self, start, end):
self._detector_range_start = start
self._detector_range_end = end
......@@ -119,6 +117,7 @@ class LoadData(ReductionStep):
if self._parameter_file != None:
LoadParameterFile(Workspace=output_ws,Filename= self._parameter_file)
self._monitor_index = self._reducer._get_monitor_index(mtd[output_ws])
if self._require_chop_data(output_ws):
ChopData(InputWorkspace=output_ws,OutputWorkspace= output_ws,Step= 20000.0,NChops= 5, IntegrationRangeLower=5000.0,
......@@ -482,9 +481,9 @@ class HandleMonitor(ReductionStep):
"""Handles the montior for the reduction of inelastic indirect data.
This uses the following parameters from the instrument:
* Workflow.MonitorArea
* Workflow.MonitorThickness
* Workflow.MonitorScalingFactor
* Workflow.Monitor1-Area
* Workflow.Monitor1-Thickness
* Workflow.Monitor1-ScalingFactor
* Workflow.UnwrapMonitor
"""
_multiple_frames = False
......
......@@ -17,7 +17,6 @@ class MSGReducer(reducer.Reducer):
_instrument_name = None #: Name of the instrument used in experiment.
_sum = False #: Whether to sum input files or treat them sequentially.
_load_logs = False #: Whether to load the log file(s) associated with the raw file.
_monitor_index = None #: Index of Monitor specturm.
_multiple_frames = False
_detector_range = [-1, -1]
_masking_detectors = {}
......@@ -38,7 +37,6 @@ class MSGReducer(reducer.Reducer):
loadData.set_ws_list(self._data_files)
loadData.set_sum(self._sum)
loadData.set_load_logs(self._load_logs)
loadData.set_monitor_index(self._monitor_index)
loadData.set_detector_range(self._detector_range[0],
self._detector_range[1])
loadData.set_parameter_file(self._parameter_file)
......@@ -98,24 +96,16 @@ class MSGReducer(reducer.Reducer):
if not isinstance(instrument, str):
raise ValueError("Instrument name must be given.")
self._instrument_name = instrument
self._load_empty_instrument()
self._get_monitor_index()
if ( self._monitor_index is None ):
raise RuntimeError("Could not find Monitor in Instrument.")
def set_parameter_file(self, file):
def set_parameter_file(self, file_name):
"""Sets the parameter file to be used in the reduction. The parameter
file will contain some settings that are used throughout the reduction
process.
Note: This is *not* the base parameter file, ie "IRIS_Parameters.xml"
but, rather, the additional parameter file.
"""
if self._instrument_name is None:
raise ValueError("Instrument name not set.")
self._parameter_file = \
os.path.join(config["parameterDefinition.directory"], file)
LoadParameterFile(Workspace=self._workspace_instrument,Filename=
self._parameter_file)
os.path.join(config["parameterDefinition.directory"], file_name)
def set_rebin_string(self, rebin):
"""Sets the rebin string to be used with the Rebin algorithm.
......@@ -185,33 +175,13 @@ class MSGReducer(reducer.Reducer):
raise RuntimeError("None of the reduction steps implement "
"the get_result_workspaces() method.")
def _load_empty_instrument(self):
"""Returns an empty workspace for the instrument.
Raises:
* ValueError if no instrument is selected.
* RuntimeError if there is a problem with the IDF.
"""
if self._instrument_name is None:
raise ValueError('No instrument selected.')
self._workspace_instrument = '__empty_' + self._instrument_name
if not mtd.doesExist(self._workspace_instrument):
idf_dir = config.getString('instrumentDefinition.directory')
idf = idf_dir + self._instrument_name + '_Definition.xml'
try:
LoadEmptyInstrument(Filename=idf,OutputWorkspace= self._workspace_instrument)
except RuntimeError:
raise ValueError('Invalid IDF')
return mtd[self._workspace_instrument]
def _get_monitor_index(self):
def _get_monitor_index(self, workspace):
"""Determine the workspace index of the first monitor spectrum.
"""
workspace = self._load_empty_instrument()
for counter in range(0, workspace.getNumberHistograms()):
try:
detector = workspace.getDetector(counter)
except RuntimeError:
pass
if detector.isMonitor():
self._monitor_index = counter
return
inst = workspace.getInstrument()
try:
monitor_index = inst.getNumberParameter('Workflow.Monitor1-SpectrumNumber')[0]
return int(monitor_index)
except IndexError:
raise ValueError('Unable to retrieve spectrum number of monitor.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment