Skip to content

Commit

Permalink
Refs #9536 Create IdentifyBadDetectors step.
Browse files Browse the repository at this point in the history
This moves the code to identify bad detectors to a separate reduction step
that is executed on a per run basis, rather than for an entire set of runs.
  • Loading branch information
Samuel Jackson committed May 29, 2014
1 parent cfe3df8 commit f9def51
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 26 deletions.
5 changes: 4 additions & 1 deletion Code/Mantid/scripts/Inelastic/inelastic_indirect_reducer.py
Expand Up @@ -47,7 +47,10 @@ def _setup_steps(self):
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)
Expand Down
81 changes: 57 additions & 24 deletions Code/Mantid/scripts/Inelastic/inelastic_indirect_reduction_steps.py
Expand Up @@ -13,8 +13,6 @@ class LoadData(ReductionStep):
This step will use the following parameters from the Instrument's parameter
file:
* Workflow.Masking - identifies the method (if any) on which detectors that
are to be masked should be identified.
* Workflow.ChopDataIfGreaterThan - if this parameter is specified on the
instrument, then the raw data will be split into multiple frames if
the largest TOF (X) value in the workspace is greater than the provided
Expand Down Expand Up @@ -90,9 +88,6 @@ def set_detector_range(self, start, end):
def set_extra_load_opts(self, opts):
self._extra_load_opts = opts

def get_mask_list(self):
return self._masking_detectors

def set_ws_list(self, value):
self._data_files = value

Expand Down Expand Up @@ -156,13 +151,6 @@ def _load_single_file(self, filename, output_ws):
StartWorkspaceIndex=self._detector_range_start,
EndWorkspaceIndex=self._detector_range_end)

try:
msk = mtd[workspaces[0]].getInstrument().getStringParameter('Workflow.Masking')[0]
except IndexError:
msk = 'None'
if ( msk == 'IdentifyNoisyDetectors' ):
self._identify_bad_detectors(workspaces[0])

def _load_data(self, filename, output_ws):
if self._parameter_file is not None and "VESUVIO" in self._parameter_file:
loaded_ws = LoadVesuvio(Filename=filename, OutputWorkspace=output_ws, SpectrumList="1-198", **self._extra_load_opts)
Expand Down Expand Up @@ -213,17 +201,6 @@ def _sum_chopped(self, wsname):
for n in range(1, len(merge)):
DeleteWorkspace(Workspace=merge[n])

def _identify_bad_detectors(self, workspace):
IdentifyNoisyDetectors(InputWorkspace=workspace,OutputWorkspace= '__temp_tsc_noise')
ws = mtd['__temp_tsc_noise']
nhist = ws.getNumberHistograms()
self._masking_detectors = []
for i in range(0, nhist):
if ( ws.readY(i)[0] == 0.0 ):
self._masking_detectors.append(i)
DeleteWorkspace(Workspace='__temp_tsc_noise')
return self._masking_detectors

def _require_chop_data(self, ws):
try:
cdigt = mtd[ws].getInstrument().getNumberParameter(
Expand All @@ -240,6 +217,61 @@ def is_multiple_frames(self):

#--------------------------------------------------------------------------------------------------

class IdentifyBadDetectors(ReductionStep):
""" Identifies bad detectors in a workspace and creates a list of
detectors to mask. This step will set the masking detectors property on
the reducer object passed to execute. This uses the IdentifyNoisyDetectors algorithm.
The step will use the following parameters on the workspace:
* Workflow.Masking - identifies the method (if any) on which detectors that
are to be masked should be identified.
"""

_masking_detectors = []

def __init__(self, MultipleFrames=False):
super(IdentifyBadDetectors, self).__init__()
self._multiple_frames = MultipleFrames
self._background_start = None
self._background_end = None

def execute(self, reducer, file_ws):

if (self._multiple_frames):
try:
workspaces = mtd[file_ws].getNames()
except AttributeError:
workspaces = [file_ws]
else:
workspaces = [file_ws]

try:
msk = mtd[workspaces[0]].getInstrument().getStringParameter('Workflow.Masking')[0]
except IndexError:
msk = 'None'

if (msk != 'IdentifyNoisyDetectors'):
return

temp_ws_mask = '__temp_ws_mask'
IdentifyNoisyDetectors(InputWorkspace=workspaces[0], OutputWorkspace=temp_ws_mask)
ws = mtd[temp_ws_mask]
nhist = ws.getNumberHistograms()

for i in range(0, nhist):
if (ws.readY(i)[0] == 0.0):
self._masking_detectors.append(i)
DeleteWorkspace(Workspace=temp_ws_mask)

#set the detector masks on the workspace
reducer._masking_detectors = self._masking_detectors

def get_mask_list(self):
return self._masking_detectors

#--------------------------------------------------------------------------------------------------

class BackgroundOperations(ReductionStep):
"""Removes, if requested, a background from the detectors data in TOF
units. Currently only uses the CalculateFlatBackground algorithm, more options
Expand Down Expand Up @@ -927,7 +959,8 @@ def _group_fixed(self, workspace):
group_to_from = group.split("-")
group_vals = range(int(group_to_from[0]), int(group_to_from[1])+1)
group_list.append(group_vals)


#remove the detectors we're masking from the groups
for i in self._masking_detectors:
for grp in group_list:
try:
Expand Down
1 change: 0 additions & 1 deletion Code/Mantid/scripts/Inelastic/msg_reducer.py
Expand Up @@ -46,7 +46,6 @@ def pre_process(self):
loadData.execute(self, None)

self._multiple_frames = loadData.is_multiple_frames()
self._masking_detectors = loadData.get_mask_list()

if( self._info_table_props is not None ):
wsNames = loadData.get_ws_list().keys()
Expand Down

0 comments on commit f9def51

Please sign in to comment.