Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems with workspace grouping display with multiple calls in scripts #1680

Closed
NickDraper opened this issue Aug 26, 2009 · 1 comment
Closed
Milestone

Comments

@NickDraper
Copy link
Contributor

Hi Martyn, Nick,

I’ve also notice a similar problem with two back to back ExtractSingleSpectrum calls. The first call seems to work but the second call results in a workspace that gets placed on its own outside of the workspace group. It also looks like the result of the second call has incorrect data in it.

The code which produces this error looks like this:
d=LoadRaw(Filename=TheFile,OutputWorkspace="all") # First get everything ExtractSingleSpectrum("all","Mon1","0") # Extract the monitors ExtractSingleSpectrum("all","Mon2","1") CropWorkspace("all","Det",StartWorkspaceIndex="2") # Extract the rest
Here the data is a 4 period dataset.

I may try looping over the workspace group to see if I get different answers.

-Tim

On 26/08/2009 12:08, "Timothy Charlton" <Timothy.Charlton@stfc.ac.uk> wrote:
Thanks Martyn,

Using your example that part of the code seems to work now.

I have found a curious bug when I run a Rebin() immediately following an Divide().

Divide(“A�, �B�, �C�) # A and B are four element workspace groups
Rebin(“C�, “C�,�0.55,0.001,6.5�)

Mistakenly puts C_2, C_3 and C_4 out side of the C workspace group which only contains C_1. If we add a simple print statement between the Divide and the Rebin then the code works as intended.

Divide(“A�, �B�, �C�) # A and B are four element workspace groups
print “C is now correct �
Rebin(“C�, “C�,�0.55,0.001,6.5�)

-Tim

On 26/08/2009 10:06, "Gigg, Martyn (Tessella,RAL,ISIS)" <martyn.gigg@stfc.ac.uk> wrote:
Hi Tim,

To distinguish between a group and a workspace at the moment, the best way is to use getMatrixWorkspaceGroup('name'), which returns a list of MatrixWorkspaces, and check it's size. If the name is a MatrixWorkspace then the list will be empty and you can use getMatrixWorkspace as before. E.g.

grp = mtd.getMatrixWorkspaceGroup('Det')
if len(grp) ==0:
grp = [mtd.getMatrixWorkspace('Det')]

Now you should have a list that has the matrix workspace inside.

for w in grp:
print w.getNumberHistograms()

While thinking about this I've realised that it might be sensible to check that if something isn't a group but the same name exists as a matrixworkspace then just return a list of size 1 but that's not something that you'll be able to use yet but the above solution will work.

Regarding the return of either a matrixworkspace or a group, I'm not sure if we are going to be able to do that. While in Python functions can return different things, C++ cannot so we are more limited in our use of Python. Either that or I haven't come up with a creative enough solution yet.

Regards,
Martyn

-----Original Message-----
From: Draper, Nick (-,RAL,ISIS)
Sent: Wed 26/08/2009 09:24
To: Gigg, M (Martyn)
Subject: FW: Workspace groups in a python script

Martyn,

Could you help Tim please.

Regards,

Nick Draper

From: Charlton, Timothy (STFC,RAL,ISIS)
Sent: 26 August 2009 08:57
To: Draper, Nick (-,RAL,ISIS)
Subject: Workspace groups in a python script

Hi Nick,

The addition of workspace groups is a good step forward but I seem to have some trouble using them is a script.

After poking around I can see the getWorkspaceGroupNames and getWorkspaceGroupEntries however they do not seem to be usable yet. An example using these and elegantly indexing over a workspace group would be useful.

Also at some point in my data reduction script I run a check to see how many spectra are present so that the right correction may be applied. The following code fails if "Det" is a workspace groups.

w = mtd.getMatrixWorkspace("Det")
nHistograms = w.getNumberHistograms()

Ideally this should work regardless of whether it's a workspace group or just a single workspace. In the case of a workspace group you would expect nHistograms to be an array.

Many thanks,
Tim

@NickDraper
Copy link
Contributor Author

This issue was originally trac ticket 832

@NickDraper NickDraper added this to the Iteration 19 milestone Jun 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant