Ticket #10654: replicate_horace_slice.py

File replicate_horace_slice.py, 2.6 KB (added by Owen Arnold, 6 years ago)
Line 
1import numpy as np
2# We create a fake workspace around the original extents of Test22Mev
3CreateMDWorkspace(Dimensions=3, Extents='-0.25,1.45,-0.55,0.55,-0.95,0.65', Names='A,B,C', Units='U,U,U', OutputWorkspace='c')
4# Put peaks in place to mark the edges in the original coordinate systemFakeMDEventData(InputWorkspace='c', PeakParams='10000,-0.25,-0.55,-0.95,0.1')
5FakeMDEventData(InputWorkspace='c', PeakParams='10000,1.45,-0.55,-0.95,0.1')
6FakeMDEventData(InputWorkspace='c', PeakParams='10000,-0.25,0.55,-0.95,0.1')
7FakeMDEventData(InputWorkspace='c', PeakParams='10000,1.45,0.55,-0.95,0.1')
8FakeMDEventData(InputWorkspace='c', PeakParams='10000,-0.25,-0.55,0.65,0.1')
9FakeMDEventData(InputWorkspace='c', PeakParams='10000,1.45,-0.55,0.65,0.1')
10FakeMDEventData(InputWorkspace='c', PeakParams='10000,-0.25,0.55,0.65,0.1')
11FakeMDEventData(InputWorkspace='c', PeakParams='10000,1.45,0.55,0.65,0.1')
12# Normalize NormalizeBasisVectors = False is important!
13u = np.array([1,1,0])v = np.array([0,0,1])
14w = np.cross(v,u)c = mtd['c']
15
16def calculate_extents(v, u, w, ws):     
17        M=np.array([u,v,w])     Minv=np.linalg.inv(M)           # We are assuming that the workspace has dimensions H, K, L in that order. The workspace MUST have 3 dimensions at least for the following to work.     
18        Hrange=[ws.getDimension(0).getMinimum(), ws.getDimension(0).getMaximum()]       Krange=[ws.getDimension(1).getMinimum(), ws.getDimension(1).getMaximum()]       Lrange=[ws.getDimension(2).getMinimum(), ws.getDimension(2).getMaximum()]               new_coords = np.empty([8, 3])   counter = 0     for h in Hrange:           for k in Krange:            for l in Lrange:            originalCorner=np.array([h,k,l])                new_coords[counter]=originalCorner.dot(Minv)            counter += 1 extents = list()        print new_coords        for i in range(0,3):            extents.append(np.amin(new_coords[:,i]))                extents.append(np.amax(new_coords[:,i]))                # Copy extents for non crystallographic dimensions              non_crystallographic_dimensions = ws.getNumDims() - 3   if non_crystallographic_dimensions > 0:         for i in range(0, non_crystallographic_dimensions):                     extents.append(ws.getDimension(i + 3).getMinimum())                     extents.append(ws.getDimension(i + 3).getMaximum())                     return extents  extents = calculate_extents(u,v,w,c)print 'x1,t,' + ','.join(map(str, u.tolist()))BinMD(InputWorkspace='c', NormalizeBasisVectors=False, AxisAligned=False, BasisVector0='x1,t,' + ','.join(map(str, u.tolist())), BasisVector1='x2,t,' + ','.join(map(str, v.tolist())), BasisVector2='x3,t,' + ','.join(map(str, w.tolist())), OutputExtents=','.join(map(str, extents)), OutputBins='100,100,100', OutputWorkspace='demo_histo')plotSlice('demo_histo')print np.identity(3)[0, :]