mantid
mantid copied to clipboard
Add support for 1D MDHisto objects in SaveASCII
Is your feature request related to a problem? Please describe. WISH users want to be able to save 1D MDHisto cuts made using the non-axis aligned sliceviewer tool as an ASCII
Describe the solution you'd like
WISH users want SaveASCII
to support this workspace type
Describe alternatives you've considered
Could have separate algorithm e.g. Save1DMDHistoASCII
but good to keep the number of algorithms down! But this is acceptable as a solution.
Additional context Here is some python code (1) Generate a 1D MDHisto workspace
# create a workspace
CreateMDWorkspace(Dimensions=3, Extents='-5,5,-4,4,-3,3', Names='H,K,L', Units='r.l.u.,r.l.u.,r.l.u.', Frames='HKL,HKL,HKL', SplitInto='2', SplitThreshold=50, OutputWorkspace='ws') # 2023-10-18T13:20:50.683328000 execCount: 19
FakeMDEventData(InputWorkspace='ws', UniformParams='100000', PeakParams='100000,0,0,1,0.3', RandomSeed=3873875) # 2023-10-18T13:20:50.737205000 execCount: 24
ws_cut = BinMD(InputWorkspace='ws', AxisAligned=False, BasisVector0='(0.0+1.0x 0.0 0.0), in 7.26 Ang^-1, 1.0,0.0,0.0', BasisVector1='u2, in 7.26 Ang^-1, 0.0,1.0,0.0', BasisVector2='u3, in 3.14 Ang^-1, 0.0,0.0,1.0',
OutputExtents='-2.5,2.5,-0.16,0.16,-0.05,0.05', OutputBins='50,1,1', NormalizeBasisVectors=False, OutputWorkspace='ws_1Dcut') # 2023-10-18T13:21:00.379543000 execCount: 26
(2) Save 1D MDHisto workspace ws_1
Dcut`
# save it to file
dim = ws_cut.getDimension(0)
nbins = dim.getNBins()
xye = np.zeros((nbins, 3))
xye[:,1] = ws_cut.getSignalArray().flat
xye[:,2] = np.sqrt(ws_cut.getErrorSquaredArray().flat)
xye[:,0] = np.linspace(dim.getMinimum() + dim.getBinWidth()/2, dim.getMaximum() - dim.getBinWidth()/2, nbins)
# get header (using workspace history!)
alg = ws_cut.getHistory().lastAlgorithm()
header = str({prop.name: prop.valueAsStr for prop in list(alg.getProperties()) if prop.valueAsStr})
np.savetxt(r"C:\Users\xhg73778\Desktop\cut.txt", xye, fmt='%1.4e', delimiter=",", header=header)
The python prototype code assumes the cut is along the first dimension - in actuality you will need to check which dimension has nbins > 1 e.g. ws_cut.getDimension(0).geNBins()
produces 50
- so this is the direction of the cut. This issue is only for saving 1D cuts, to you will also need to check there is only 1 dimension with nbins > 1.