Table of Contents
An algorithm to mask a detector, or set of detectors, as not to be used. The workspace spectra associated with those detectors are zeroed.
Name | Direction | Type | Default | Description |
---|---|---|---|---|
Workspace | InOut | Workspace | Mandatory | The name of the input and output workspace on which to perform the algorithm. |
SpectraList | Input | int list | An ArrayProperty containing a list of spectra to mask | |
DetectorList | Input | int list | An ArrayProperty containing a list of detector ID’s to mask | |
WorkspaceIndexList | Input | unsigned int list | An ArrayProperty containing the workspace indices to mask | |
MaskedWorkspace | Input | MatrixWorkspace | If given but not as a SpecialWorkspace2D, the masking from this workspace will be copied. If given as a SpecialWorkspace2D, the masking is read from its Y values. | |
StartWorkspaceIndex | Input | number | 0 | The index of the first workspace index of input MaskedWorkspace to be included in the calculation. Default is 0. |
EndWorkspaceIndex | Input | number | Optional | The index number of the last workspace index of input MaskedWorkspace to be included in the calculation. Default is the last histogram. |
This algorithm will flag the detectors listed as masked(IDetector::isMasked() method) and will zero the data in the spectra for MatrixWorkspaces related to those detectors. For PeaksWorkspaces, only the detectors listed are masked and the mask must be specified by a DetectorList or MaskedWorkspace.
All but the first property are optional and at least one of them must be set. If several are set, the first will be used.
The set of detectors to be masked can be given as a list of either spectrum numbers, detector IDs or workspace indices. The list should be set against the appropriate property.
If the input MaskedWorkspace is not a SpecialWorkspace2D object, this algorithm will check every detectors in input MaskedWorkspace’s Instrument. If the detector is masked, then the corresponding detector will be masked in Workspace.
If the input MaskedWorkspace is a MaskWorkspace object, i.e., masking workspace, then the algorithm will mask Workspace’s detector according to the histogram data of the SpecialWorkspace2D object.
MaskDetectors v1 supports various format of input to mask detectors, including
Here are the rules for input information for masking
There are 2 operations to mask a detector and thus spectrum related
In the plan, the workflow to mask detectors should be
import numpy as np
# Create a workspace containing some data.
ws = CreateSampleWorkspace()
# Mask two detectors by specifying numbers 1 and 3
MaskDetectors(ws,SpectraList=[1,3])
# Check that spectra with spectrum numbers 1 and 3 are masked
# Get the 1st spectrum in the workspace
spec = ws.getSpectrum(0)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
y = ws.readY(0)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
# Get the 2nd spectrum in the workspace
spec = ws.getSpectrum(1)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
y = ws.readY(1)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
# Get the 3rd spectrum in the workspace
spec = ws.getSpectrum(2)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
y = ws.readY(2)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
# Get the 4th spectrum in the workspace
spec = ws.getSpectrum(3)
detid = spec.getDetectorIDs()[0]
print 'Spectrum number is',spec.getSpectrumNo()
print 'Detector of this spectrum is masked:',ws.getInstrument().getDetector(detid).isMasked()
y = ws.readY(3)
print 'All counts in the spectrum are 0: ',np.all( y == 0.0 )
Spectrum number is 1
Detector of this spectrum is masked: True
All counts in the spectrum are 0: True
Spectrum number is 2
Detector of this spectrum is masked: False
All counts in the spectrum are 0: False
Spectrum number is 3
Detector of this spectrum is masked: True
All counts in the spectrum are 0: True
Spectrum number is 4
Detector of this spectrum is masked: False
All counts in the spectrum are 0: False
# Create a workspace containing some data.
ws = CreateSampleWorkspace()
# Mask two detectors by specifying detector IDs 101 and 103
MaskDetectors(ws,DetectorList=[101,103])
# Check that spectra with spectrum numbers 1 and 3 are masked
# Check the 1st detector
det = ws.getInstrument().getDetector(101)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
# Check the 2nd detector
det = ws.getInstrument().getDetector(103)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
# Check some other detectors
det = ws.getInstrument().getDetector(100)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
det = ws.getInstrument().getDetector(102)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
det = ws.getInstrument().getDetector(105)
print 'Detector ',det.getID(),' is masked:',det.isMasked()
# Create a workspace containing some data.
ws = CreateSampleWorkspace()
# Mask two detectors by specifying workspace indices 0 and 2
MaskDetectors(ws,WorkspaceIndexList=[0,2])
# Check that spectra with workspace indices 0 and 2 are masked
# Check the 1st spectrum
workspaceIndex = 0
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
# Check the 2nd spectrum
workspaceIndex = 2
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
# Check some other spectra
workspaceIndex = 1
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
workspaceIndex = 3
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
workspaceIndex = 4
det = ws.getDetector( workspaceIndex )
print 'Detector in spectrum with workspace index ',workspaceIndex,' is masked:',det.isMasked()
Detector in spectrum with workspace index 0 is masked: True
Detector in spectrum with workspace index 2 is masked: True
Detector in spectrum with workspace index 1 is masked: False
Detector in spectrum with workspace index 3 is masked: False
Detector in spectrum with workspace index 4 is masked: False
# Create a masking workspace
# Create a intermediate workspace to help create the masking workspace
tmp = CreateSampleWorkspace()
# Mask two detectors
MaskDetectors(tmp,WorkspaceIndexList=[1,3])
# Extract created mask into specialised masking workspace
masking_ws,dummy = ExtractMask( tmp )
print 'A masking workspace has',masking_ws.blocksize(),'spectrum'
print 'Unmasked spectrum, value=',masking_ws.readY(0)[0]
print 'Masked spectrum, value=',masking_ws.readY(1)[0]
print 'Unmasked spectrum, value=',masking_ws.readY(2)[0]
print 'Masked spectrum, value=',masking_ws.readY(3)[0]
print 'Unmasked spectrum, value=',masking_ws.readY(4)[0]
print
# Create a data workspace
ws = CreateSampleWorkspace()
# Mask it using the mask in masking_ws
MaskDetectors(ws, MaskedWorkspace=masking_ws)
# Check masking of first 5 detectors
det = ws.getDetector(0)
print 'Detector',det.getID(),'is masked:',det.isMasked()
det = ws.getDetector(1)
print 'Detector',det.getID(),'is masked:',det.isMasked()
det = ws.getDetector(2)
print 'Detector',det.getID(),'is masked:',det.isMasked()
det = ws.getDetector(3)
print 'Detector',det.getID(),'is masked:',det.isMasked()
det = ws.getDetector(4)
print 'Detector',det.getID(),'is masked:',det.isMasked()
A masking workspace has 1 spectrum
Unmasked spectrum, value= 0.0
Masked spectrum, value= 1.0
Unmasked spectrum, value= 0.0
Masked spectrum, value= 1.0
Unmasked spectrum, value= 0.0
Detector 100 is masked: False
Detector 101 is masked: True
Detector 102 is masked: False
Detector 103 is masked: True
Detector 104 is masked: False
Categories: Algorithms | Transforms\Masking