\(\renewcommand\AA{\unicode{x212B}}\)
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())
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.readY(1)
for y in y_data2:
print(y)
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")
getInstrument for Sample and Source Geometry.
instrument = ws.getInstrument()
print(instrument.getName())
SpectrumInfo, DetectorInfo and ComponentInfo have many other features:
info = ws.spectrumInfo()
print(info.hasDetectors(0))