MatrixWorkspace Attributes#

Spectra and Bins#

A MatrixWorkspace is a 2D array of data divided into spectra and bins.

Get the number of histograms (spectra) in a workspace:

print(workspace_name.getNumberHistograms())

Get the number of bins:

print(workspace_name.blocksize())

Read or Extract Data#

Access the data using readX,Y,E (simply a view into an existing workspace) or extractX,Y,E (creates a copy of the data). These commands take a workspace index and returns a list of the relevant data.

Create a view of the Y data from the 2nd spectrum:

y_data2 = raw_workspace.y(1)

for y in y_data2:
    print(y)

Workspace Objects#

There is a lot of information about workspaces that can be accessed.

Below is a brief overview of the most commonly used functionality, for further details see:

getSpectrum for info on the structure of a workspace eg. the spectrum number related to workspace index 0:

ws.getSpectrum(0).getSpectrumNo()

getAxis for Workspace labels and structure eg. Give the AxisUnit a new label:

ws.getAxis(0).getUnit().setLabel("Time-of-flight", "Milliseconds")

getInstrumentName for the name of the instrument, and componentInfo for Sample and Source Geometry. The ComponentInfo describes every part of the instrument (source, sample, detectors and the banks that hold them) by an index:

print(ws.getInstrumentName())
component_info = ws.componentInfo()
print(component_info.sourcePosition())
print(component_info.samplePosition())

SpectrumInfo (detector geometry by workspace index), DetectorInfo (by detector) and ComponentInfo have many other features:

info = ws.spectrumInfo()
print(info.hasDetectors(0))