Skip to content
Snippets Groups Projects
Commit 822579fc authored by Doucet, Mathieu's avatar Doucet, Mathieu
Browse files

Improvement Mask reduction step. Re #2119

parent aab136dc
No related branches found
No related tags found
No related merge requests found
......@@ -72,7 +72,7 @@ def BeamSpreaderTransmission(sample_spreader, direct_spreader,
spreader_transmission_err=spreader_transmission_err))
def Mask(nx_low=0, nx_high=0, ny_low=0, ny_high=0):
ReductionSingleton().set_mask(sans_reduction_steps.Mask(nx_low=nx_low, nx_high=nx_high, ny_low=ny_low, ny_high=ny_high))
ReductionSingleton().get_mask().mask_edges(nx_low=nx_low, nx_high=nx_high, ny_low=ny_low, ny_high=ny_high)
def Background(datafile):
ReductionSingleton().set_background(datafile)
......
......@@ -61,13 +61,11 @@ class HFIRSANS(Instrument):
return masked_pts
def get_masked_detectors(self, masked_pixels):
def get_detector_from_pixel(self, pixel_list):
"""
Returns a list of masked detector channels from the list of pixels.
This is very instrument-dependent, because it depends on the actual
mapping of the detector pxiels to Mantid detector IDs.
TODO: think about a way to clean this up
Returns a list of detector IDs from a list of [x,y] pixels,
where the pixel coordinates are in pixel units.
"""
return [ 1000000 + p[0]*1000 + p[1] for p in masked_pixels ]
return [ 1000000 + p[0]*1000 + p[1] for p in pixel_list ]
......@@ -70,6 +70,9 @@ class SANSReducer(Reducer):
# Default data loader
self._data_loader = sans_reduction_steps.LoadRun()
# Default mask object
self._mask = sans_reduction_steps.Mask()
def set_normalizer(self, option):
"""
......
......@@ -596,27 +596,37 @@ class SensitivityCorrection(ReductionStep):
class Mask(ReductionStep):
"""
Marks some spectra so that they are not included in the analysis
TODO: Maintain HFIR-ISIS compatibility
"""
def __init__(self, nx_low=0, nx_high=0, ny_low=0, ny_high=0):
def __init__(self):
"""
Initalize masking
"""
Initalize masking and optionally define a "picture frame" outside of
which the spectra from all detectors are to be masked.
super(Mask, self).__init__()
self._nx_low = 0
self._nx_high = 0
self._ny_low = 0
self._ny_high = 0
self._xml = []
#these spectra will be masked by the algorithm MaskDetectors
self.spec_list = []
# List of pixels to mask
self.masked_pixels = []
def mask_edges(self, nx_low=0, nx_high=0, ny_low=0, ny_high=0):
"""
Define a "picture frame" outside of which the spectra from all detectors are to be masked.
@param nx_low: number of pixels to mask on the lower-x side of the detector
@param nx_high: number of pixels to mask on the higher-x side of the detector
@param ny_low: number of pixels to mask on the lower-y side of the detector
@param ny_high: number of pixels to mask on the higher-y side of the detector
@param ny_high: number of pixels to mask on the higher-y side of the detector
"""
super(Mask, self).__init__()
self._nx_low = nx_low
self._nx_high = nx_high
self._ny_low = ny_low
self._ny_high = ny_high
self._xml = []
#these spectra will be masked by the algorithm MaskDetectors
self.spec_list = ''
self._ny_high = ny_high
def add_xml_shape(self, complete_xml_element):
if not complete_xml_element.startswith('<') :
......@@ -657,6 +667,18 @@ class Mask(ReductionStep):
self._infinite_cylinder([xcentre, ycentre, 0.0], radius, [0,0,1],
complement=True, id=ID))
def add_pixel_rectangle(self, x_min, x_max, y_min, y_max):
"""
Mask out a rectangle area defined in pixel coordinates.
@param x_min: Minimum x to mask
@param x_max: Maximum x to mask
@param y_min: Minimum y to mask
@param y_max: Maximum y to mask
"""
for ix in range(x_min, x_max+1):
for iy in rangE(y_min, y_max+1):
self.masked_pixels.append([ix, iy])
def execute(self, reducer, workspace, instrument=None):
for shape in self._xml:
MaskDetectorsInShape(workspace, shape)
......@@ -670,14 +692,19 @@ class Mask(ReductionStep):
self._ny_low,
self._ny_high)
# Transform the list of pixels into a list of Mantid detector IDs
masked_detectors = instrument.get_masked_detectors(masked_pixels)
masked_detectors = instrument.get_detector_from_pixel(masked_pixels)
# Mask the pixels by passing the list of IDs
MaskDetectors(workspace, None, masked_detectors)
MaskDetectors(workspace, DetectorList = masked_detectors)
if self.spec_list != '':
MaskDetectors(workspace, SpectraList = self.spec_list)
# Mask out internal list of pixels
if len(self.masked_pixels)>0:
masked_detectors = instrument.get_detector_from_pixel(self.masked_pixels)
MaskDetectors(workspace, DetectorList = masked_detectors)
return "Mask applied"
def view_mask(self):
......
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