\(\renewcommand\AA{\unicode{x212B}}\)
ComponentInfo¶
This is a python binding to the C++ class Mantid::Geometry::ComponentInfo.
Most of the information concerning ComponentInfo
can be found in the Instrument Access Layers document.
Purpose¶
The purpose of the ComponentInfo
object is to allow the user to access geometric information about the components which are part of a beamline. A component is any physical item or group of items that is registered for the purpose of data reduction. The ComponentInfo
object can be used to access information such as the total number of components in the beamline, the absolute position of a component as well as the absolute rotation of a component. ComponentInfo
provides tree like access to the beamline including all the detectors.
Many users may need this extra information so that they can have a better understanding of the beamline they are using and the components that make up the beamline - e.g. detectors, banks, choppers. This extra information is easy and fast to access.
ComponentInfo
is one of three objects that the user can gain access to from a workspace.
The other two are:
Indexing¶
The ComponentInfo
object is accessed by an index going from 0 to N-1 where N is the number of components.
The component index for a detector is EQUAL to the detector index. In other words, a detector with a detector index of 5 when working with a DetectorInfo
object and will have a component index of 5 when working with a ComponentInfo
object.
Another way to think about this is that the first 0 to n-1 components referenced in ComponentInfo
are detectors, where n is the total number of detectors.
Usage¶
Example 1 - Creating a ComponentInfo Object:
This example shows how to obtain a ComponentInfo
object from a workspace object.
The return value is a ComponentInfo
object.
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the ComponentInfo object
info = ws.componentInfo()
from mantid.geometry import ComponentInfo
print("The type is ComponentInfo: {}".format(isinstance(info, ComponentInfo)))
Output:
The type is ComponentInfo: True
Example 2 - Calling Some Methods on the ComponentInfo Object: This example shows how to call a few different methods on the ComponentInfo object.
The relativePosition
method takes in an integer index
parameter which corresponds to a component.
The return value is a V3D
object which denotes a point in 3D space.
The setRotation()
method takes in a Quat
object which defines a rotation. The rotation is applied to the component.
Retrieving the rotation after setting it may not always give the same Quat
object back - i.e. the values could be changed.
The hasParent()
method takes an integer index
parameter which corresponds to a component.
The return value is True
if the component has a parent component or False
otherwise.
# Import Quat
from mantid.kernel import Quat
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the ComponentInfo object
info = ws.componentInfo()
# Call relativePosition
print(info.relativePosition(0))
# Create a sample Quat and call setRotation
quat = Quat(0, 0, 0, 0)
info.setRotation(0, quat)
print(info.rotation(0))
# Call hasParent
print(info.hasParent(0))
Output:
[0,0,0]
[0,0,0,0]
True
Example 3 - Retrieving a List of Child Components from a ComponentInfo Object:
The children()
method does not take in any parameters.
The method returns a list of integers representing the child components.
The returned list can then be indexed into to obtain a specific component.
# Create a workspace to use
ws = CreateSampleWorkspace()
# Get the ComponentInfo object
info = ws.componentInfo()
# Get a list of the child components
childComponents = info.children(0)
print(len(childComponents))
print(childComponents)
Output:
0
[]
bases: mantid.geometry.ComponentInfo
- class mantid.geometry.ComponentInfo¶
- children((ComponentInfo)self, (int)index) numpy.ndarray : ¶
Returns a list of child components for the component identified by ‘index’.
- componentsInSubtree((ComponentInfo)self, (int)index) numpy.ndarray : ¶
Returns a list of components in the subtree for the component identified by ‘index’.
- detectorsInSubtree((ComponentInfo)self, (int)index) numpy.ndarray : ¶
Returns a list of detectors in the subtree for the component identified by ‘index’.
- hasEquivalentSample((ComponentInfo)arg1, (ComponentInfo)self) bool : ¶
Returns True is both beamlines either lack a Sample or have a Sample at the same position.
- hasEquivalentSource((ComponentInfo)arg1, (ComponentInfo)self) bool : ¶
Returns True is both beamlines either lack a Source or have a Source at the same position.
- hasParent((ComponentInfo)self, (int)index) bool : ¶
Returns True only if the component identified by ‘index’ has a parent component.
- hasSample((ComponentInfo)self) bool : ¶
Returns True if a sample is present.
- hasSource((ComponentInfo)self) bool : ¶
Returns True if a source is present.
- hasValidShape((ComponentInfo)self, (int)index) bool : ¶
Returns True if the component identified by ‘index’ has a valid shape.
- indexOfAny((ComponentInfo)self, (str)name) int : ¶
Returns the index of any component matching name. Raises ValueError if name not found
- isDetector((ComponentInfo)self, (int)index) bool : ¶
Checks if the component is a detector.
- l1((ComponentInfo)self) float : ¶
Returns the l1 value.
- name((ComponentInfo)self, (int)index) str : ¶
Returns the name of the component identified by ‘index’.
- parent((ComponentInfo)self, (int)index) int : ¶
Returns the parent component of the component identified by ‘index’.
- position((ComponentInfo)self, (int)index) V3D : ¶
Returns the absolute position of the component identified by ‘index’.
- relativePosition((ComponentInfo)self, (int)index) V3D : ¶
Returns the absolute relative position of the component identified by ‘index’.
- relativeRotation((ComponentInfo)self, (int)index) Quat : ¶
Returns the absolute relative rotation of the component identified by ‘index’.
- root((ComponentInfo)self) int : ¶
Returns the index of the root component
- rotation((ComponentInfo)self, (int)index) Quat : ¶
Returns the absolute rotation of the component identified by ‘index’.
- sample((ComponentInfo)self) int : ¶
Returns the sample component index.
- samplePosition((ComponentInfo)self) V3D : ¶
Returns the sample position.
- scaleFactor((ComponentInfo)self, (int)index) V3D : ¶
Returns the scale factor for the component identified by ‘index’.
- setPosition((ComponentInfo)self, (int)index, (V3D)newPosition) None : ¶
Set the absolute position of the component identified by ‘index’.
- setRotation((ComponentInfo)self, (int)index, (Quat)newRotation) None : ¶
Set the absolute rotation of the component identified by ‘index’.
- setScaleFactor((ComponentInfo)self, (int)index, (V3D)scaleFactor) None : ¶
Set the scale factor of the component identifed by ‘index’.
- shape((ComponentInfo)self, (int)index) IObject : ¶
Returns the shape of the component identified by ‘index’.
- size((ComponentInfo)self) int : ¶
Returns the number of components.
- source((ComponentInfo)self) int : ¶
Returns the source component index.
- sourcePosition((ComponentInfo)self) V3D : ¶
Returns the source position.
- uniqueName((ComponentInfo)self, (str)name) bool : ¶
Returns True if the name is a unique single occurance. Zero occurances yields False.