Ticket #832 (closed: fixed)
Problems with workspace grouping display with multiple calls in scripts
Reported by: | Nick Draper | Owned by: | Sofia Antony |
---|---|---|---|
Priority: | major | Milestone: | Iteration 19 |
Component: | Keywords: | ||
Cc: | Blocked By: | ||
Blocking: | Tester: |
Description
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@…> 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@…> 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
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
Change History
comment:1 Changed 11 years ago by Sofia Antony
- Status changed from new to closed
- Resolution set to worksforme
comment:2 Changed 11 years ago by Sofia Antony
- Status changed from closed to reopened
- Resolution worksforme deleted
comment:4 Changed 11 years ago by Sofia Antony
- Status changed from reopened to closed
- Resolution set to fixed
I've followed the steps above,but not reproducible