Skip to content
Snippets Groups Projects
Commit 3c8377a3 authored by Owen Arnold's avatar Owen Arnold
Browse files

refs #24597. Convert to doctest

parent 8a0b3c71
No related merge requests found
......@@ -20,15 +20,20 @@ Examples of using ``ComponentInfo`` in python
Print indices of detectors in "bank1" that are masked
.. code-block:: python
from mantid.simpleapi import CreateSampleWorkspace
ws = CreateSampleWorkspace()
comp_info = ws.componentInfo()
det_info = ws.detectorInfo()
bank_index compinfo.indexOfAny('bank1')
for det_index in compinfo.detectorsInSubtree(bank_index):
if det_info.isMasked(int(det_index)):
print('Masked detector of bank1, ', det_index)
.. testcode:: show_masked_detectors_in_bank
from mantid.simpleapi import CreateSampleWorkspace
ws = CreateSampleWorkspace()
comp_info = ws.componentInfo()
det_info = ws.detectorInfo()
det_info.setMasked(2, True) # Mask a bank 1 detector for demo
det_info.setMasked(len(det_info)-1, True) # Mask detector not in bank 1
bank_index = comp_info.indexOfAny('bank1')
for det_index in comp_info.detectorsInSubtree(bank_index):
if det_info.isMasked(int(det_index)):
print('Masked detector index of bank1 is {}'.format(det_index))
.. testoutput:: show_masked_detectors_in_bank
Masked detector index of bank1 is 2
......@@ -16,30 +16,26 @@ Introduction
Python Interface
----------------
Examples of using ``DetectorInfo`` in python
Example of using ``DetectorInfo`` in python
Mask detectors at some distance from the source
**Mask detectors at some distance from the source**
.. code-block:: python
from mantid.simpleapi import CreateSampleWorkspace
.. testcode:: mask_detectors
# Test workspace with instrument
ws = CreateSampleWorkspace()
det_info = ws.detectorInfo();
for item in det_info:
if not item.isMonitor and item.l2 > 2.0:
item.setMasked(True)
from mantid.simpleapi import CreateSampleWorkspace
# Test workspace with instrument
ws = CreateSampleWorkspace()
det_info = ws.detectorInfo();
mask_count = 0
for item in det_info:
if not item.isMonitor and item.l2 > 2.0:
item.setMasked(True)
mask_count += 1
print('masked {} detectors'.format(mask_count))
Print detectors with scattering angle
.. code-block:: python
from mantid.simpleapi import CreateSampleWorkspace
# Test workspace with instrument
ws = CreateSampleWorkspace()
det_info = ws.detectorInfo()
for item in det_info:
if item.l2 > 0.01:
print(item.index)
.. testoutput:: mask_detectors
masked 200 detectors
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