\(\renewcommand\AA{\unicode{x212B}}\)

SpectrumInfo

This is a python binding to the C++ class Mantid::API::SpectrumInfo.

Most of the information concerning SpectrumInfo can be found in the Instrument Access Layers document.

Purpose

The purpose of the SpectrumInfo object is to allow the user to access information about the spectra being used in an experiment. The SpectrumInfo object can be used to access information such as the number of spectra, the absolute position of a spectrum as well as the distance from the sample to the source. There are many other methods available as well.

A spectrum corresponds to (a group of) one or more detectors. However if no instrument/beamline has been set then the number of detectors will be zero. An example test case details this below.

Many users may need more information about the spectra in an experiment so that they can have a better understanding of the beamline they are using. This information is easy and fast to access via SpectrumInfo.

SpectrumInfo is one of three objects that the user can gain access to from a workspace object. The other two are:

Usage

Example 1 - Creating a SpectrumInfo Object: This example shows how to obtain a SpectrumInfo object from a workspace object. The return value is a SpectrumInfo object.

# Create a workspace to use
ws = CreateSampleWorkspace()

# Get the SpectrumInfo object
info = ws.spectrumInfo()
from mantid.api import SpectrumInfo
print("The type is SpectrumInfo: {}".format(isinstance(info, SpectrumInfo)))

Output:

The type is SpectrumInfo: True

Example 2 - Calling the hasDetectors Method on the SpectrumInfo Object: This example shows how to call the hasDetectors method. The method takes in an integer index parameter which corresponds to a spectrum. The return value is True or False.

# Create a workspace to use (should have a preset instrument)
ws = CreateSampleWorkspace()

# Get the SpectrumInfo object
info = ws.spectrumInfo()

# Call hasDetectors
print(info.hasDetectors(0))

"""
The object returned by CreateWorkspace does not have an instrument set so
it is expected that we would be getting False back from hasDetectors().
"""

# Sample data
intx = [1,2,3,4,5]
inty = [1,2,3,4,5]

# Create a workspace to use
wsTwo = CreateWorkspace(intx, inty)

# Get the SpectrumInfo object
info = wsTwo.spectrumInfo()

# Call hasDetectors
print(info.hasDetectors(0))

Output:

True
False

Example 3 - Calling Some Methods on the SpectrumInfo Object: This example shows how to call a few different methods on the SpectrumInfo object.

The l1() method does not take in any parameters and returns the distance from the source to the sample. The return value is a float.

The sourcePosition() method does not take any parameters and returns the absolute source position. The return value is a V3D object which is a point in 3D space.

The getSpectrumDefinition() method takes in an integer index parameter and returns a SpectrumDefinition object. The returned object can then be used to call other methods that belong to SpectrumDefinition.

# Create a workspace to use
ws = CreateSampleWorkspace()

# Get the SpectrumInfo object
info = ws.spectrumInfo()

# Call l1
print(info.l1())

# Call sourcePosition
print(info.sourcePosition())

# Get a SpectrumDefinition object
spectrumDefinition = info.getSpectrumDefinition(0)
from mantid.api import SpectrumDefinition
print("The type is SpectrumDefinition: {}".format(isinstance(spectrumDefinition, SpectrumDefinition)))

Output:

10.0
[0,0,-10]
The type is SpectrumDefinition: True

bases: mantid.api.SpectrumInfo

class mantid.api.SpectrumInfo
azimuthal((SpectrumInfo)self, (int)index) float :

Returns the out-of-plane angle in radians angle w.r.t. to vecPointingHorizontal direction.

detectorCount((SpectrumInfo)self) int :

Returns the total number of detectors used across spectrum info.

difcUncalibrated((SpectrumInfo)self, (int)index) float :

Return the uncalibrated difc diffractometer constant

diffractometerConstants((SpectrumInfo)self, (int)index) UnitParametersMap :

Return the diffractometer constants

geographicalAngles((SpectrumInfo)self, (int)index) object :

Returns the latitude and longitude for given spectrum index. The returned value is a pair of (latitude, longitude)

getSpectrumDefinition((SpectrumInfo)self, (int)index) SpectrumDefinition :

Returns the SpectrumDefinition of the spectrum with the given index.

hasDetectors((SpectrumInfo)arg1, (int)self) bool :

Returns True if the spectrum is associated with detectors in the instrument.

hasUniqueDetector((SpectrumInfo)self, (int)index) bool :

Returns True if the spectrum is associated with exactly one detector.

isMasked((SpectrumInfo)self, (int)index) bool :

Returns True if the detector(s) associated with the spectrum are masked.

isMonitor((SpectrumInfo)self, (int)index) bool :

Returns True if the detector(s) associated with the spectrum are monitors.

l1((SpectrumInfo)self) float :

Returns the distance from the source to the sample.

l2((SpectrumInfo)self, (int)index) float :

Returns the distance from the sample to the spectrum.

position((SpectrumInfo)self, (int)index) V3D :

Returns the absolute position of the spectrum with the given index.

samplePosition((SpectrumInfo)self) V3D :

Returns the absolute sample position.

setMasked((SpectrumInfo)self, (int)index, (bool)masked) None :

Set the mask flag of the spectrum with the given index.

signedTwoTheta((SpectrumInfo)self, (int)index) float :

Returns the signed scattering angle 2 theta in radians w.r.t. beam direction.

size((SpectrumInfo)self) int :

Returns the number of spectra.

sourcePosition((SpectrumInfo)self) V3D :

Returns the absolute source position.

twoTheta((SpectrumInfo)self, (int)index) float :

Returns the scattering angle 2 theta in radians w.r.t. beam direction.