def test_mdhisto_workspace_q(self): from mantid.simpleapi import (CreateMDWorkspace, FakeMDEventData, BinMD) md_event = CreateMDWorkspace(Dimensions=3, Extents=[-10, 10, -10, 10, -10, 10], Names='Q_x,Q_y,Q_z', Units='U,U,U', Frames='QLab,QLab,QLab', StoreInADS=False) FakeMDEventData(InputWorkspace=md_event, PeakParams=[100000, 0, 0, 0, 1], StoreInADS=False) # Add Peak md_histo = BinMD(InputWorkspace=md_event, AlignedDim0='Q_y,-10,10,3', AlignedDim1='Q_x,-10,10,4', AlignedDim2='Q_z,-10,10,5', StoreInADS=False) histo_data_array = mantidcompat.convert_MDHistoWorkspace_to_data_array( md_histo) self.assertEqual(histo_data_array.coords[sc.Dim.Qx].values.shape, (4, )) self.assertEqual(histo_data_array.coords[sc.Dim.Qy].values.shape, (3, )) self.assertEqual(histo_data_array.coords[sc.Dim.Qz].values.shape, (5, )) self.assertEqual(histo_data_array.coords[sc.Dim.Qx].unit, sc.units.dimensionless / sc.units.angstrom) self.assertEqual(histo_data_array.coords[sc.Dim.Qy].unit, sc.units.dimensionless / sc.units.angstrom) self.assertEqual(histo_data_array.coords[sc.Dim.Qz].unit, sc.units.dimensionless / sc.units.angstrom) self.assertEquals(histo_data_array.values.shape, (3, 4, 5)) # Sum over 2 dimensions to simplify finding max. max_1d = sc.sum(sc.sum(histo_data_array, dim=sc.Dim.Qy), dim=sc.Dim.Qx).values max_index = np.argmax(max_1d) # Check position of max 'peak' self.assertEqual(np.floor(len(max_1d) / 2), max_index) # All events in central 'peak' self.assertEqual(100000, max_1d[max_index]) self.assertTrue('nevents' in histo_data_array.attrs)
def test_mdhisto_workspace_many_dims(self): from mantid.simpleapi import (CreateMDWorkspace, FakeMDEventData, BinMD) md_event = CreateMDWorkspace( Dimensions=4, Extents=[-10, 10, -10, 10, -10, 10, -10, 10], Names='deltae,y,z,T', Units='U,U,U,U', StoreInADS=False) FakeMDEventData(InputWorkspace=md_event, PeakParams=[100000, 0, 0, 0, 0, 1], StoreInADS=False) # Add Peak md_histo = BinMD(InputWorkspace=md_event, AlignedDim0='deltae,-10,10,3', AlignedDim1='y,-10,10,4', AlignedDim2='z,-10,10,5', AlignedDim3='T,-10,10,7', StoreInADS=False) histo_data_array = mantidcompat.convert_MDHistoWorkspace_to_data_array( md_histo) self.assertEqual(4, len(histo_data_array.dims))