Skip to content

Commit

Permalink
Refs #9349 - Utility to extract masked detector IDs.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterParker committed Jul 31, 2014
1 parent 399e2d8 commit 910f8a4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Code/Mantid/scripts/SANS/SANSUtility.py
Expand Up @@ -530,6 +530,25 @@ def extract_single_spectrum(ws, ws_index):

return mtd[output_ws_name]

def get_masked_det_ids(ws):
"""
Given a workspace, will return a list of all the IDs that correspond to
detectors that have been masked.
@param ws :: the workspace to extract the det IDs from
@returns a list of IDs for masked detectors.
"""
for ws_index in range(ws.getNumberHistograms()):
try:
det = ws.getDetector(ws_index)
except RuntimeError:
# Skip the rest after finding the first spectra with no detectors,
# which is a big speed increase for SANS2D.
break
if det.isMasked():
yield det.getID()

###############################################################################
######################### Start of Deprecated Code ############################
###############################################################################
Expand Down
14 changes: 13 additions & 1 deletion Code/Mantid/scripts/test/SANSUtilityTest.py
Expand Up @@ -2,7 +2,7 @@
from mantid.simpleapi import *
import SANSUtility as su

class TestSliceStringParser(unittest.TestCase):
class SANSUtilityTest(unittest.TestCase):

def checkValues(self, list1, list2):

Expand Down Expand Up @@ -68,5 +68,17 @@ def test_extract_spectra(self):
self.assertEquals(result.getDetector(1).getID(), 102)
self.assertEquals(result.getDetector(2).getID(), 104)

def test_get_masked_det_ids(self):
ws = CreateSampleWorkspace("Histogram", "Multiple Peaks")

MaskDetectors(Workspace=ws, DetectorList=[100, 102, 104])

masked_det_ids = list(su.get_masked_det_ids(ws))

self.assertTrue(100 in masked_det_ids)
self.assertTrue(102 in masked_det_ids)
self.assertTrue(104 in masked_det_ids)
self.assertEquals(len(masked_det_ids), 3)

if __name__ == "__main__":
unittest.main()

0 comments on commit 910f8a4

Please sign in to comment.