def setUpClass(self): self.ws_MD_3D = CreateMDHistoWorkspace( Dimensionality=3, Extents='-3,3,-10,10,-1,1', SignalInput=range(100), ErrorInput=range(100), NumberOfBins='5,5,4', Names='Dim1,Dim2,Dim3', Units='MomentumTransfer,EnergyTransfer,Angstrom', OutputWorkspace='ws_MD_3D') self.ws_MDE_3D = CreateMDWorkspace(Dimensions='3', Extents='-3,3,-4,4,-5,5', Names='h,k,l', Units='rlu,rlu,rlu', SplitInto='4', OutputWorkspace='ws_MDE_3D') FakeMDEventData('ws_MDE_3D', PeakParams='100000,0,0,0,0.1', RandomSeed='63759', RandomizeSignal='1') FakeMDEventData('ws_MDE_3D', PeakParams='40000,1,0,0,0.1', RandomSeed='63759', RandomizeSignal='1') self.ws2d_histo = CreateWorkspace(DataX=[10, 20, 30, 10, 20, 30], DataY=[2, 3, 4, 5], DataE=[1, 2, 3, 4], NSpec=2, Distribution=True, UnitX='Wavelength', VerticalAxisUnit='DeltaE', VerticalAxisValues=[4, 6, 8], OutputWorkspace='ws2d_histo')
def setUpClass(cls): """ Create fake workspaces, 3D and 2D """ # 3D DeltaPDF3DTest_MDE = CreateMDWorkspace(Dimensions='3', Extents='-3.1,3.1,-3.1,3.1,-3.1,3.1', Names='[H,0,0],[0,K,0],[0,0,L]', Units='rlu,rlu,rlu', SplitInto='4',Frames='HKL,HKL,HKL') # Add Bragg peaks for h in range(-3,4): for k in range(-3,4): for l in range(-3,4): FakeMDEventData(DeltaPDF3DTest_MDE, PeakParams='100,'+str(h)+','+str(k)+','+str(l)+',0.1', RandomSeed='1337') # Add addiontal peaks on [0.5,0.5,0.5] type positions # This would correspond to negative substitutional correlations for h in np.arange(-2.5,3): for k in np.arange(-2.5,3): for l in np.arange(-2.5,3): FakeMDEventData(DeltaPDF3DTest_MDE, PeakParams='20,'+str(h)+','+str(k)+','+str(l)+',0.1', RandomSeed='13337') BinMD(InputWorkspace='DeltaPDF3DTest_MDE', AlignedDim0='[H,0,0],-3.05,3.05,61', AlignedDim1='[0,K,0],-3.05,3.05,61', AlignedDim2='[0,0,L],-3.05,3.05,61', OutputWorkspace='DeltaPDF3DTest_MDH') # 2D DeltaPDF3DTest_MDE_2 = CreateMDWorkspace(Dimensions='3', Extents='-3.1,3.1,-3.1,3.1,-0.1,0.1', Names='[H,0,0],[0,K,0],[0,0,L]', Units='rlu,rlu,rlu', SplitInto='4',Frames='HKL,HKL,HKL') # Add Bragg peaks for h in range(-3,4): for k in range(-3,4): FakeMDEventData(DeltaPDF3DTest_MDE_2, PeakParams='100,'+str(h)+','+str(k)+',0,0.01', RandomSeed='1337') # Add addiontal peaks on [0.5,0.5,0.5] type positions # This would correspond to negative substitutional correlations for h in np.arange(-2.5,3): for k in np.arange(-2.5,3): FakeMDEventData(DeltaPDF3DTest_MDE_2, PeakParams='20,'+str(h)+','+str(k)+',0,0.1', RandomSeed='13337') BinMD(InputWorkspace='DeltaPDF3DTest_MDE_2', AlignedDim0='[H,0,0],-3.05,3.05,61', AlignedDim1='[0,K,0],-3.05,3.05,61', AlignedDim2='[0,0,L],-0.1,0.1,1', OutputWorkspace='DeltaPDF3DTest_MDH_2')
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 runTest(self): HelperTestingClass.__init__(self) def scale_ws(ws): ws = ws * 100 ws = CreateMDWorkspace(Dimensions='3', EventType='MDEvent', Extents='-10,10,-5,5,-1,1', Names='Q_lab_x,Q_lab_y,Q_lab_z', Units='1\\A,1\\A,1\\A') FakeMDEventData(ws, UniformParams="1000000") pres = SliceViewer(ws) self._assertNoErrorInADSHandlerFromSeparateThread(partial(scale_ws, ws)) self._qapp.sendPostedEvents() self.assertTrue(pres.view in self.find_widgets_of_type(str(type(pres.view)))) self.assertNotEqual(pres.ads_observer, None) pres.view.close()
def test_view_updates_on_replace_when_model_properties_dont_change_mdeventws( self): def scale_ws(ws): ws = ws * 100 ws = CreateMDWorkspace(Dimensions='3', EventType='MDEvent', Extents='-10,10,-5,5,-1,1', Names='Q_lab_x,Q_lab_y,Q_lab_z', Units='1\\A,1\\A,1\\A') FakeMDEventData(ws, UniformParams="1000000") pres = SliceViewer(ws) self._assertNoErrorInADSHandlerFromSeparateThread(partial( scale_ws, ws)) QApplication.sendPostedEvents() self.assertTrue( pres.view in self.find_widgets_of_type(str(type(pres.view)))) self.assertNotEqual(pres.ads_observer, None) pres.view.close()
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 = scn.mantid.convert_MDHistoWorkspace_to_data_array( md_histo) self.assertEqual(4, len(histo_data_array.dims))
def runTest(self): # Na Mn Cl3 # R -3 H (148) # 6.592 6.592 18.585177 90 90 120 # UB/wavelength from /HFIR/HB3A/IPTS-25470/shared/autoreduce/HB3A_exp0769_scan0040.nxs ub = np.array([[1.20297e-01, 1.70416e-01, 1.43000e-04], [8.16000e-04, -8.16000e-04, 5.38040e-02], [1.27324e-01, -4.05110e-02, -4.81000e-04]]) wavelength = 1.553 # create fake MDEventWorkspace, similar to what is expected from exp769 after loading with HB3AAdjustSampleNorm MD_Q_sample = CreateMDWorkspace( Dimensions='3', Extents='-5,5,-5,5,-5,5', Names='Q_sample_x,Q_sample_y,Q_sample_z', Units='rlu,rlu,rlu', Frames='QSample,QSample,QSample') inst = LoadEmptyInstrument(InstrumentName='HB3A') AddTimeSeriesLog(inst, 'omega', '2010-01-01T00:00:00', 0.) AddTimeSeriesLog(inst, 'phi', '2010-01-01T00:00:00', 0.) AddTimeSeriesLog(inst, 'chi', '2010-01-01T00:00:00', 0.) MD_Q_sample.addExperimentInfo(inst) SetUB(MD_Q_sample, UB=ub) ol = OrientedLattice() ol.setUB(ub) sg = SpaceGroupFactory.createSpaceGroup("R -3") hkl = [] sat_hkl = [] for h in range(0, 6): for k in range(0, 6): for l in range(0, 11): if sg.isAllowedReflection([h, k, l]): if h == k == l == 0: continue q = V3D(h, k, l) q_sample = ol.qFromHKL(q) if not np.any(np.array(q_sample) > 5): hkl.append(q) FakeMDEventData( MD_Q_sample, PeakParams='1000,{},{},{},0.05'.format( *q_sample)) # satellite peaks at 0,0,+1.5 q = V3D(h, k, l + 1.5) q_sample = ol.qFromHKL(q) if not np.any(np.array(q_sample) > 5): sat_hkl.append(q) FakeMDEventData( MD_Q_sample, PeakParams='100,{},{},{},0.02'.format( *q_sample)) # satellite peaks at 0,0,-1.5 q = V3D(h, k, l - 1.5) q_sample = ol.qFromHKL(q) if not np.any(np.array(q_sample) > 5): sat_hkl.append(q) FakeMDEventData( MD_Q_sample, PeakParams='100,{},{},{},0.02'.format( *q_sample)) # Check that this fake workpsace gives us the expected UB peaks = FindPeaksMD(MD_Q_sample, PeakDistanceThreshold=1, OutputType='LeanElasticPeak') FindUBUsingFFT(peaks, MinD=5, MaxD=20) ShowPossibleCells(peaks) SelectCellOfType(peaks, CellType='Rhombohedral', Centering='R', Apply=True) OptimizeLatticeForCellType(peaks, CellType='Hexagonal', Apply=True) found_ol = peaks.sample().getOrientedLattice() self.assertAlmostEqual(found_ol.a(), 6.592, places=2) self.assertAlmostEqual(found_ol.b(), 6.592, places=2) self.assertAlmostEqual(found_ol.c(), 18.585177, places=2) self.assertAlmostEqual(found_ol.alpha(), 90) self.assertAlmostEqual(found_ol.beta(), 90) self.assertAlmostEqual(found_ol.gamma(), 120) # nuclear peaks predict = HB3APredictPeaks( MD_Q_sample, Wavelength=wavelength, ReflectionCondition='Rhombohedrally centred, obverse', SatellitePeaks=True, IncludeIntegerHKL=True) predict = HB3AIntegratePeaks(MD_Q_sample, predict, 0.25) self.assertEqual(predict.getNumberPeaks(), 66) # check that the found peaks are expected for n in range(predict.getNumberPeaks()): HKL = predict.getPeak(n).getHKL() self.assertTrue(HKL in hkl, msg=f"Peak {n} with HKL={HKL}") # magnetic peaks satellites = HB3APredictPeaks( MD_Q_sample, Wavelength=wavelength, ReflectionCondition='Rhombohedrally centred, obverse', SatellitePeaks=True, ModVector1='0,0,1.5', MaxOrder=1, IncludeIntegerHKL=False) satellites = HB3AIntegratePeaks(MD_Q_sample, satellites, 0.1) self.assertEqual(satellites.getNumberPeaks(), 80) # check that the found peaks are expected for n in range(satellites.getNumberPeaks()): HKL = satellites.getPeak(n).getHKL() self.assertTrue(HKL in sat_hkl, msg=f"Peak {n} with HKL={HKL}")