ComponentInfo#

This is a python binding to the C++ class Mantid::Geometry::ComponentInfo.

bases: mantid.geometry.ComponentInfo

ComponentInfo provides faster and simpler access to instrument/beamline geometry as required by Mantid algorithm than was possible using Instrument. ComponentInfo and DetectorInfo are designed as full replacements to Instrument.

Most of the information concerning ComponentInfo can be found in the Instrument Access Layers document, which provides details on how DetectorInfo interacts with other geometry access layers.

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
[]

Example 4 - Print indices of detectors in “bank1” that are masked

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))

Output:

Masked detector index of bank1 is 2

Reference#

class mantid.geometry.ComponentInfo#
addBool((ComponentInfo)self, (str)name, (bool)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds or replaces a named boolean parameter on the component identified by ‘index’ (the root component by default).

addDouble((ComponentInfo)self, (str)name, (float)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds or replaces a named double parameter on the component identified by ‘index’ (the root component by default).

addFittingParameter((ComponentInfo)self, (str)name, (str)fittingFunction, (str)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds a named fitting parameter, given its value as a string, on the component identified by ‘index’ (the root component by default).

addInt((ComponentInfo)self, (str)name, (int)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds or replaces a named integer parameter on the component identified by ‘index’ (the root component by default).

addParameter((ComponentInfo)self, (str)type, (str)name, (str)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds or replaces the named parameter of this type, given its value as a string, on the component identified by ‘index’ (the root component by default).

addQuat((ComponentInfo)self, (str)name, (mantid.kernel._kernel.Quat)value[, (object)index=None[, (str)description='']]) → None :#

Adds or replaces a named Quat parameter on the component identified by ‘index’ (the root component by default).

addString((ComponentInfo)self, (str)name, (str)value[, (object)index=None[, (str)description=''[, (str)visible='true']]]) → None :#

Adds or replaces a named string parameter on the component identified by ‘index’ (the root component by default).

addV3D((ComponentInfo)self, (str)name, (mantid.kernel._kernel.V3D)value[, (object)index=None[, (str)description='']]) → None :#

Adds or replaces a named V3D parameter on the component identified by ‘index’ (the root component by default).

children((ComponentInfo)self, (int)index) → numpy.ndarray :#

Returns a list of child components for the component identified by ‘index’.

clearParameter((ComponentInfo)self, (str)name[, (object)index=None]) → None :#

Removes every parameter of this name from the component identified by ‘index’ (the root component by default).

componentType((ComponentInfo)self, (int)index) → ComponentType :#

Returns the ComponentType of 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’.

detectorIndexAtXYZ((ComponentInfo)self, (int)index, (int)x, (int)y, (int)z) → int :#

Returns the detector index of the pixel at (x, y, z) within the Rectangular/Grid bank identified by ‘index’.

detectorsInSubtree((ComponentInfo)self, (int)index) → numpy.ndarray :#

Returns a list of detectors in the subtree for the component identified by ‘index’.

fullName((ComponentInfo)self, (int)index) → str :#

Returns the fully-qualified name of the component identified by ‘index’, e.g. ‘instrument/bank1/pixel3’.

getBoolParameter((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → mantid.kernel._kernel.std_vector_bool :#

Returns the named boolean parameter of the component identified by ‘index’ (the root component by default), or an empty sequence if it is unset.

getFittingParameter((ComponentInfo)self, (str)name, (float)xvalue[, (object)index=None]) → float :#

Returns the named fitting parameter of the component identified by ‘index’ (the root component by default), evaluated at ‘xvalue’ from its look-up table or formula.

getIntParameter((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → mantid.kernel._kernel.std_vector_int :#

Returns the named integer parameter of the component identified by ‘index’ (the root component by default), or an empty sequence if it is unset.

getMemorySize((ComponentInfo)self) → int :#

Return the memory footprint of the component info in bytes.

getNumberParameter((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → mantid.kernel._kernel.std_vector_dbl :#

Returns the named double parameter of the component identified by ‘index’ (the root component by default), or an empty sequence if it is unset.

getParameterNames((ComponentInfo)self[, (object)index=None[, (bool)recursive=True]]) → mantid.kernel._kernel.std_set_str :#

Returns the names of the parameters on the component identified by ‘index’ (the root component by default).

getParameterType((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → str :#

Returns the type of the named parameter of the component identified by ‘index’ (the root component by default), or an empty string if it is unset.

getStringParameter((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → mantid.kernel._kernel.std_vector_str :#

Returns the named string parameter of the component identified by ‘index’ (the root component by default), or an empty sequence if it is unset.

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.

hasParameter((ComponentInfo)self, (str)name[, (object)index=None[, (bool)recursive=True]]) → bool :#

Returns True if the component identified by ‘index’ (the root component by default) has a parameter of this name.

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

indexOfFullName((ComponentInfo)self, (str)fullName) → int :#

Returns the index of the component with this fully-qualified name, or ComponentInfo.invalidIndex if there is none.

invalidIndex = 18446744073709551615#
isDetector((ComponentInfo)self, (int)index) → bool :#

Checks if the component is a detector.

isGridDetector((ComponentInfo)self, (int)index) → bool :#

Returns True if the component identified by ‘index’ is a Rectangular or Grid bank. Every pixelGrid* accessor requires this to be True.

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’.

pixelGridIdFillOrder((ComponentInfo)self, (int)index) → str :#

Returns the axis order in which detector IDs are filled for the Rectangular/Grid bank identified by ‘index’, as a 3-character string permutation of ‘x’, ‘y’ and ‘z’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridIdStart((ComponentInfo)self, (int)index) → int :#

Returns the detector ID of the first pixel of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridIdStep((ComponentInfo)self, (int)index) → int :#

Returns the detector ID step between pixels along the first-filled axis of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridIdStepByRow((ComponentInfo)self, (int)index) → int :#

Returns the detector ID step between rows along the second-filled axis of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridMaxDetectorID((ComponentInfo)self, (int)index) → int :#

Returns the maximum detector ID in the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridMinDetectorID((ComponentInfo)self, (int)index) → int :#

Returns the minimum detector ID in the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridNX((ComponentInfo)self, (int)index) → int :#

Returns the number of pixels in the X (horizontal) direction of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridNY((ComponentInfo)self, (int)index) → int :#

Returns the number of pixels in the Y (vertical) direction of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridNZ((ComponentInfo)self, (int)index) → int :#

Returns the number of pixels in the Z (usually beam) direction of the Rectangular/Grid bank identified by ‘index’, or 0 for a 2D (rectangular) bank. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridXStart((ComponentInfo)self, (int)index) → float :#

Returns the X position of pixel (0, 0, 0), in the local (unrotated, unscaled) frame of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridXStep((ComponentInfo)self, (int)index) → float :#

Returns the step size between neighbouring pixels along X for the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridYStart((ComponentInfo)self, (int)index) → float :#

Returns the Y position of pixel (0, 0, 0), in the local (unrotated, unscaled) frame of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridYStep((ComponentInfo)self, (int)index) → float :#

Returns the step size between neighbouring pixels along Y for the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridZStart((ComponentInfo)self, (int)index) → float :#

Returns the Z position of pixel (0, 0, 0), in the local (unrotated, unscaled) frame of the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

pixelGridZStep((ComponentInfo)self, (int)index) → float :#

Returns the step size between neighbouring pixels along Z for the Rectangular/Grid bank identified by ‘index’. Raises RuntimeError if the component is not a Rectangular or Grid bank.

position((ComponentInfo)self, (int)index) → mantid.kernel._kernel.V3D :#

Returns the absolute position of the component identified by ‘index’.

relativePosition((ComponentInfo)self, (int)index) → mantid.kernel._kernel.V3D :#

Returns the absolute relative position of the component identified by ‘index’.

relativeRotation((ComponentInfo)self, (int)index) → mantid.kernel._kernel.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) → mantid.kernel._kernel.Quat :#

Returns the absolute rotation of the component identified by ‘index’.

sample((ComponentInfo)self) → int :#

Returns the sample component index.

samplePosition((ComponentInfo)self) → mantid.kernel._kernel.V3D :#

Returns the sample position.

scaleFactor((ComponentInfo)self, (int)index) → mantid.kernel._kernel.V3D :#

Returns the scale factor for the component identified by ‘index’.

setPosition((ComponentInfo)self, (int)index, (mantid.kernel._kernel.V3D)newPosition) → None :#

Set the absolute position of the component identified by ‘index’.

setRotation((ComponentInfo)self, (int)index, (mantid.kernel._kernel.Quat)newRotation) → None :#

Set the absolute rotation of the component identified by ‘index’.

setScaleFactor((ComponentInfo)self, (int)index, (mantid.kernel._kernel.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’.

shapeToComponentIndices((ComponentInfo)self) → dict :#

Returns a mapping of shapes to the indices of components with that shape.

size((ComponentInfo)self) → int :#

Returns the number of components.

solidAngle((ComponentInfo)self, (int)index, (mantid.kernel._kernel.V3D)observer) → float :#

Returns the solid angle of the component identified by ‘index’ as seen from the observer position.

source((ComponentInfo)self) → int :#

Returns the source component index.

sourcePosition((ComponentInfo)self) → mantid.kernel._kernel.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.