Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0651b06
commit be74ef8
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
Code/Mantid/Framework/PythonInterface/plugins/algorithms/MaskAngle.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,58 @@ | ||
""" | ||
Algorithm to mask detectors with scattering angles in a given interval (in degrees) | ||
By default MinAngle=0, MaxAngle=180, so if no keywords are set, all detectors are going to be masked | ||
Returns a list of detectors that were masked | ||
""" | ||
|
||
import mantid.simpleapi | ||
import mantid.kernel | ||
import mantid.api | ||
import numpy | ||
|
||
class MaskAngle(mantid.api.PythonAlgorithm): | ||
""" Class to generate grouping file | ||
""" | ||
|
||
def category(self): | ||
""" Mantid required | ||
""" | ||
return "PythonAlgorithms;Transforms\\Masking" | ||
|
||
def name(self): | ||
""" Mantid require | ||
""" | ||
return "MaskAngle" | ||
|
||
def PyInit(self): | ||
self.declareProperty(mantid.api.WorkspaceProperty("Workspace", "", direction=mantid.kernel.Direction.Input), "Input workspace") | ||
angleValidator=mantid.kernel.FloatBoundedValidator() | ||
angleValidator.setBounds(0.,180.) | ||
self.declareProperty(name="MinAngle", defaultValue=0.0, validator=angleValidator, direction=mantid.kernel.Direction.Input, doc="Angles above StartAngle are going to be masked") | ||
self.declareProperty(name="MaxAngle", defaultValue=0.0, validator=angleValidator, direction=mantid.kernel.Direction.Input, doc="Angles above StartAngle are going to be masked") | ||
self.declareProperty(mantid.kernel.IntArrayProperty(name="MaskedDetectors", direction=mantid.kernel.Direction.Output), doc="List of detector masked, with scatterin angles between MinAngle and MaxAngle") | ||
|
||
def PyExec(self): | ||
ws = self.getProperty("Workspace").value | ||
ttmin = self.getProperty("MinAngle").value | ||
ttmax = self.getProperty("MaxAngle").value | ||
if ttmin > ttmax : | ||
raise ValueError("MinAngle > MaxAngle, please check angle range for masking") | ||
|
||
detlist=[] | ||
|
||
|
||
numspec = ws.getNumberHistograms() | ||
for i in range(numspec): | ||
det=ws.getDetector(i) | ||
if not det.isMonitor(): | ||
tt=numpy.degrees(det.getTwoTheta(mantid.kernel.V3D(0,0,0),mantid.kernel.V3D(0,0,1))) | ||
if tt>= ttmin and tt<= ttmax: | ||
detlist.append(det.getID()) | ||
|
||
if len(detlist)> 0: | ||
mantid.simpleapi.MaskDetectors(Workspace=ws,DetectorList=detlist) | ||
else: | ||
self.log().information("no detectors within this range") | ||
self.setProperty("MaskedDetectors", numpy.array(detlist)) | ||
|
||
mantid.api.AlgorithmFactory.subscribe(MaskAngle) |