Skip to content
Snippets Groups Projects
Commit 2d25dfca authored by Bhuvan Bezawada's avatar Bhuvan Bezawada
Browse files

Added doctests to DetectorInfo.rst

re #22885
re #23093
parent d9e92033
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,110 @@ The other two are:
* SpectrumInfo
* ComponentInfo
-------
Usage
-------
**Example 1 - Creating a DetectorInfo Object:**
This example shows how to obtain a DetectorInfo object from a workspace object.
The return value is a ``DetectorInfo`` object.
.. testcode:: CreateDetectorInfoObject
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the DetectorInfo object
info = ws.detectorInfo()
print(type(info))
**Example 2 - Calling the setMasked method on the DetectorInfo Object:**
This example shows how to call the ``setMasked`` method.
The method takes in an integer ``index`` parameter which corresponds to a component and a boolean ``masked`` parameter which allows the user to set the masking to True or False.
.. testcode:: CallSetMaskedMethod
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the DetectorInfo object
info = ws.detectorInfo()
# Call setMasked
print(info.setMasked(0, True))
print(info.isMasked(0))
print(info.setMasked(0, False))
print(info.isMasked(0))
**Example 3 - Calling the twoTheta method on the DetectorInfo Object:**
The ``twoTheta()`` method takes in an integer ``index`` parameter which represents a detector index. The return value is a float which represents the scattering angle with respect to the beam direction.
.. testcode:: CallTwoThetaMethod
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the DetectorInfo object
info = ws.detectorInfo()
# Call twoTheta
print(type(info.twoTheta(0)))
**Example 4 - Calling the position method on the DetectorInfo Object:**
The ``position()`` method takes an ``index`` parameter which represents a detector index and returns the absolute position of that detector. The returned object is of type V3D which is a essentially 3D vector.
.. testcode:: CallPositionMethod
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the DetectorInfo object
info = ws.detectorInfo()
# Call the position method
print(type(info.position(0)))
**Example 5 - Calling the size method on the DetectorInfo Object:**
The ``size()`` method does not take in any parameters and returns a number of detectors in the instrument. One can also use the built in ``__len__`` function to obtain the same result.
.. testcode:: CallSizeAndLenMethods
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the DetectorInfo object
info = ws.detectorInfo()
# Call size and __len__
print(info.size())
print(len(info))
Output:
.. testoutput:: CreateDetectorInfoObject
<class 'mantid.geometry._geometry.DetectorInfo'>
.. testoutput:: CallSetMaskedMethod
True
False
.. testoutput:: CallTwoThetaMethod
<type 'float'>
.. testoutput:: CallPositionMethod
<class 'mantid.kernel._kernel.V3D'>
.. testoutput:: CallSizeAndLenMethods
200
200
*bases:* :py:obj:`mantid.geometry.DetectorInfo`
.. module:`mantid.geometry`
......
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