Get workspace names in grouped workspace

I want to get the names of workspaces in a workspace group. Is there a way to do this?

This may be the wrong question to ask, so I’m open to other ways of doing this.

If I perform ISISIndirectEnergyTransferWrapper the output is a grouped workspace with names assigned to the workspaces contained within the group in a way I can’t figure out and that varies across instruments.

For further manipulation with algorithms that will not work on workspace groups I want to ungroup the workspaces, get their names and run the algorithm on the individual workspaces. I could iterate across the items contained with the workspace group, but this seems as though it contradicts the idea of workspace groups in the first place so I can imagine there is no way to do this.

Hi Ian,

Assuming you have the grouped workspace object in a variable (lets say ‘grouped_workspace’), then you can get a list of names of the workspaces inside the group by doing

names = grouped_workspace.getNames()

Workspace groups are primarily used to keep the list of workspaces on the left hand side tidy and organised. There should therefore be no need to ungroup these workspaces to do further analysis of the workspaces inside the group. You can just pass the individual workspace names inside the group to the relevant algorithms one at a time and it should work fine.

I hope this helps.


Thanks Rob, that’s what I was after.
It may be a naive question but is there some way to find documentation on what methods are associated with an object?

The documentation page you’re probably looking for is: WorkspaceGroup

You could print the type of the object and then lookup the class that is printed to the Messages Box:

from mantid.simpleapi import *

ws = CreateSampleWorkspace()
ws1 = CreateSampleWorkspace()
wsGroup = GroupWorkspaces((ws,ws1))


Output: <class 'mantid.api._api.WorkspaceGroup'>

Alternatively, you could briefly change from the Script Editor to the IPython window in MantidWorkbench, run enough of your script to create the object then type object_name.(dot) and click tab and a list of possible methods, such as getNames() will be displayed.

1 Like

Brilliant, thanks a lot!

Alternatively dir(wsGroup) will list all the functions, same as for any python object

1 Like