Workspace Group

A WorkspaceGroup is a group of workspaces.

Most algorithms will execute on a WorkspaceGroup by simply executing the algorithm on each workspace contained within.

Creating a Workspace Group

  • Select a few workspaces in MantidPlot and click the “Group” button above the list of workspaces.
  • Use the GroupWorkspaces algorithm.

Un-grouping Workspaces

  • Select the WorkspaceGroup and click “Ungroup”.
  • Use the UnGroupWorkspace algorithm.

Working with Event Workspaces in Python

Creating and splitting groups

ws1 = CreateSampleWorkspace()
ws2 = CreateSampleWorkspace()
ws3 = CreateSampleWorkspace()


# Create a group workpace
wsList = [ws1,ws2,ws3]
wsGroup = GroupWorkspaces(wsList)
# or
wsGroup = GroupWorkspaces("ws1,ws2,ws3")

print wsGroup.getNames()

# Remove the group
# The child workspaces will be preserved
UnGroupWorkspace(wsGroup)
# Using wsGroup now will cause a runtime error
# RuntimeError: Variable invalidated, data has been deleted.

Accessing Workspace Groups

The methods for getting a variable to an EventWorkspace is the same as shown in the Workspace help page.

If you want to check if a variable points to something that is a Workspace Group you can use this:

from mantid.api import WorkspaceGroup

ws1 = CreateSampleWorkspace()
ws2 = CreateSampleWorkspace()
wsGroup = GroupWorkspaces("ws1,ws2")

if isinstance(wsGroup, WorkspaceGroup):
    print wsGroup.getName() + " is an " + wsGroup.id()

Output:

wsGroup is an WorkspaceGroup
Looping over all of the members of a group
ws1 = CreateSampleWorkspace()
ws2 = CreateSampleWorkspace()
wsGroup = GroupWorkspaces("ws1,ws2")

print "Number of members:", wsGroup.getNumberOfEntries()
print "List of names:", wsGroup.getNames()

# Get the member workspaces in a loop
for i in range(wsGroup.getNumberOfEntries()):
    wsLoop = wsGroup.getItem(i)
    print "Member", i, wsLoop

Output:

Number of members: 2
List of names: ['ws1','ws2']
Member 0 ws1
Member 1 ws2

Using Workspace Groups in Algorithms

You can pass workspace groups into any algorithm and Mantid will run that algorithm for each member of the workspace group.

ws1 = CreateSampleWorkspace()
ws2 = CreateSampleWorkspace()
wsGroup = GroupWorkspaces("ws1,ws2")
wsGroup2 = GroupWorkspaces("ws2,ws1")

#  This will add the member workspaces in a pair like manner
wsGroup3 = wsGroup + wsGroup2

# Rebin all of wsGroup
wsRebinned = Rebin(wsGroup, Params=200)

# You can still of course refer to members of a group directly
ws1 = Rebin(ws1, Params=100)

Other Information on Workspaces

  • Workspace - Overview of workspaces, which include the following classes:
    • MatrixWorkspace - A base class that contains among others:
      • WorkspaceSingleValue - Holds a single number (and X & error value, if desired). Mainly used for workspace algebra, e.g. to divide all bins in a 2D workspace by a single value.
      • Workspace2D - A workspace for holding two dimensional data in memory, this is the most commonly used workspace.
      • EventWorkspace - A workspace that retains the individual neutron event data.
    • 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 run sequentially on each member of the group.

Category: Concepts