Workspace#

This is a Python binding to the C++ class Mantid::API::Workspace.

bases: mantid.kernel.DataItem

What are Workspaces?#

Workspaces store data that algorithms operate on. Workspaces are usually stored in-memory. An algorithm can manipulate a workspace in-place or create a new one as an output.

Workspace is as loose term that encompases a range of possible data structures. All forms of Workspace provide some common information:

  • The type identifier (id) of the workspace (see below), unique to every type of workspace

  • The name of the workspace, unique to every instance of a workspace even those of the same type

  • The history of algorithms that were run to form and manipulate the workspace to its current state

Tip

In MantidWorkbench the data from the workspaces can be graphically viewed, inspected, and plotted in many ways.

Note

In addition to data, workspaces hold a workspace history, which details the algorithms which have been run on this workspace. This means workspaces carry all the meta-information to fully recreate themeselves.

Workspaces Types#

  • MatrixWorkspace - Is really a categorisation for a family which contains measured (or derived) data with associated errors and an axis giving information about where the measurement was made. Matrix Workspaces are typically create initially by executing one of Mantid’s Load algorithms, for example LoadRaw or LoadNexus. Of data structures representing 2D measurement data. The following are common sorts of Matrix Workspace:

    • Workspace2D - A workspace for holding two dimensional histogram data in memory, this is the most commonly used workspace.

    • EventWorkspace - A workspace that retains the individual neutron event data often including the pulse time corresponding to the reading.

  • TableWorkspace - A workspace holding data in rows of columns having a particular type (e.g. text, integer, …).

  • WorkspaceGroup - A container for a collection of workspaces. Algorithms given a group as input usually run sequentially on each member of the group.

The workspace type id identifies the type of a Workspace instance.

Tip

For C++ or Python development, these values are needed in such functions as the AnalysisDataService createWorkspace.

ID

Workspace Type

“IEventWorkspace”

IEventWorkspace

“ITableWorkspace”

ITableWorkspace

“WorkspaceGroup”

WorkspaceGroup

“AbsManagedWorkspace2D”

AbsManagedWorkspace2D

“CompressedWorkspace2D”

CompressedWorkspace2D

“EventWorkspace”

EventWorkspace

“ManagedWorkspace2D”

ManagedWorkspace2D

“TableWorkspace”

TableWorkspace

“Workspace2D”

Workspace2D

“WorkspaceSingleValue”

WorkspaceSingleValue

“ManagedRawFileWorkspace2D”

ManagedRawFileWorkspace2D

“MDWorkspace”

MDWorkspace

“MDHistoWorkspace”

MDHistoWorkspace

Working with Workspaces#

This page describes how you can work with workspaces in python, including accessing their properties and history

Writing your own Workspace#

TableWorkspace is the best solution at present for customising the data structures you need.Changes beyond that are at present not trivial. For specialisation of existing data structures, or new data requirements, please contact the Mantid Team for help.

Reference#

class mantid.api.Workspace#
clone(InputWorkspace)#

Copies an existing workspace into a new one.

Property descriptions:

InputWorkspace(Input:req) Workspace Name of the input workspace. Must be a MatrixWorkspace (2D or EventWorkspace), a PeaksWorkspace or a MDEventWorkspace.

OutputWorkspace(Output:req) Workspace Name of the newly created cloned workspace.

convertUnits(InputWorkspace, Target, EMode=None, EFixed=None, AlignBins=None, ConvertFromPointData=None)#

Performs a unit change on the X values of a workspace

Property descriptions:

InputWorkspace(Input:req) MatrixWorkspace Name of the input workspace

OutputWorkspace(Output:req) MatrixWorkspace Name of the output workspace, can be the same as the input

Target(Input:req) string The name of the units to convert to (must be one of those registered in the Unit Factory)[DeltaE, DeltaE_inFrequency, DeltaE_inWavenumber, dSpacing, dSpacingPerpendicular, Energy, Energy_inWavenumber, Momentum, MomentumTransfer, QSquared, SpinEchoLength, SpinEchoTime, TOF, Wavelength]

EMode(Input) string The energy mode (default: elastic)[Elastic, Direct, Indirect]

EFixed(Input) number Value of fixed energy in meV : EI (EMode=’Direct’) or EF (EMode=’Indirect’) . Must be set if the target unit requires it (e.g. DeltaE)

AlignBins(Input) boolean If true (default is false), rebins after conversion to ensure that all spectra in the output workspace have identical bin boundaries. This option is not recommended (see http://docs.mantidproject.org/algorithms/ConvertUnits).

ConvertFromPointData(Input) boolean When checked, if the Input Workspace contains Points the algorithm ConvertToHistogram will be run to convert the Points to Bins. The Output Workspace will contains Bins.

delete(Workspace)#

Removes a workspace from memory.

Property descriptions:

Workspace(Input:req) Workspace Name of the workspace to delete.

getComment((Workspace)self) str :#

Returns the comment field on the workspace

getHistory((Workspace)self) WorkspaceHistory :#

Return read-only access to the WorkspaceHistory

getMemorySize((Workspace)self) int :#

Returns the memory footprint of the workspace in KB

getName((Workspace)self) str :#

Returns the name of the workspace. This could be an empty string

getTitle((Workspace)self) str :#

Returns the title of the workspace

id((DataItem)self) str :#

The string ID of the class

isDirty((Workspace)self[, (int)n]) bool :#

True if the workspace has run more than n algorithms (Default=1)

isGroup((Workspace)self) bool :#

Returns if it is a group workspace

maskDetectors(Workspace, SpectraList=None, DetectorList=None, WorkspaceIndexList=None, MaskedWorkspace=None, ForceInstrumentMasking=None, StartWorkspaceIndex=None, EndWorkspaceIndex=None, ComponentList=None)#

An algorithm to mask a detector, or set of detectors, as not to be used. The workspace spectra associated with those detectors are zeroed.

Property descriptions:

Workspace(InOut:req) Workspace The name of the input and output workspace on which to perform the algorithm.

SpectraList(Input) int list A list of spectra to mask

DetectorList(Input) int list A list of detector ID’s to mask

WorkspaceIndexList(Input) unsigned int list A list of the workspace indices to mask

MaskedWorkspace(Input) MatrixWorkspace If given but not as a SpecialWorkspace2D, the masking from this workspace will be copied. If given as a SpecialWorkspace2D, the masking is read from its Y values.[]

ForceInstrumentMasking(Input) boolean Works when ‘MaskedWorkspace’ is provided and forces to use spectra-detector mapping even in case when number of spectra in ‘Workspace’ and ‘MaskedWorkspace’ are equal

StartWorkspaceIndex(Input) number If other masks fields are provided, it’s the first index of the target workspace to be allowed to be masked from by these masks, if not, its the first index of the target workspace to mask. Default value is 0 if other masking is present or ignored if not.

EndWorkspaceIndex(Input) number If other masks are provided, it’s the last index of the target workspace allowed to be masked to by these masks, if not, its the last index of the target workspace to mask. Default is number of histograms in target workspace if other masks are present or ignored if not.

ComponentList(Input) str list A list names of components to mask

name((DataItem)self) str :#

The name of the object

readLock((DataItem)self) None :#

Acquires a read lock on the data item.

setComment((Workspace)self, (str)comment) None :#

Set the comment field of the workspace

setTitle((Workspace)self, (str)title) None :#

Set the title of the workspace

threadSafe((DataItem)self) bool :#

Returns true if the object can be accessed safely from multiple threads

unlock((DataItem)self) None :#

Unlocks a read or write lock on the data item.