def convertQSampleToHKL(ws, OutputWorkspace='__md_hkl', norm=None, UB=None, Extents=[-10, 10, -10, 10, -10, 10], Bins=[101, 101, 101], Append=False): ol = OrientedLattice() ol.setUB(UB) q1 = ol.qFromHKL([1, 0, 0]) q2 = ol.qFromHKL([0, 1, 0]) q3 = ol.qFromHKL([0, 0, 1]) BinMD(InputWorkspace=ws, AxisAligned=False, NormalizeBasisVectors=False, BasisVector0='[H,0,0],A^-1,{},{},{}'.format(q1.X(), q1.Y(), q1.Z()), BasisVector1='[0,K,0],A^-1,{},{},{}'.format(q2.X(), q2.Y(), q2.Z()), BasisVector2='[0,0,L],A^-1,{},{},{}'.format(q3.X(), q3.Y(), q3.Z()), OutputExtents=Extents, OutputBins=Bins, TemporaryDataWorkspace=OutputWorkspace if Append and mtd.doesExist(OutputWorkspace) else None, OutputWorkspace=OutputWorkspace) if norm is not None: mtd[str(norm)].run().getGoniometer().setR( mtd[str(ws)].getExperimentInfo(0).run().getGoniometer().getR()) convertToHKL(norm, OutputWorkspace=str(OutputWorkspace) + '_norm', UB=UB, Extents=Extents, Bins=Bins, Append=Append) return OutputWorkspace
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}")
from mantid.simpleapi import * from mantid.geometry import OrientedLattice van = LoadNexus( '/HFIR/HB2C/IPTS-7776/shared/autoreduce/HB2C_{}.nxs'.format(6558)) LoadIsawUB('van', '/SNS/users/rwp/wand/single5/PNO_T.mat') ub = mtd['van'].sample().getOrientedLattice().getUB().copy() ol = OrientedLattice() ol.setUB(ub) q1 = ol.qFromHKL([1, 0, 0]) q2 = ol.qFromHKL([0, 1, 0]) q3 = ol.qFromHKL([0, 0, 1]) if 'data' in mtd: mtd.remove('data') if 'norm' in mtd: mtd.remove('norm') for run in range(4756, 6558, 1): print(run) md = LoadMD( Filename='/HFIR/HB2C/IPTS-7776/shared/autoreduce/HB2C_{}_MDE.nxs'. format(run)) mtd['van'].run().getGoniometer().setR( mtd['md'].getExperimentInfo(0).run().getGoniometer().getR()) #BinMD(InputWorkspace='md', OutputWorkspace='mdh', AlignedDim0='Q_sample_x,-10,10,401', AlignedDim1='Q_sample_y,-1,1,41', AlignedDim2='Q_sample_z,-10,10,401') BinMD(InputWorkspace='md', OutputWorkspace='mdh',