def test_multiple_histograms(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([1.1, 1.3, 1.5, 1.7]) EFixed = 8. Ys = np.ones(3 * (len(energyBins) - 1)) Es = Ys verticalAxis = [str(q) for q in qs] ws = CreateWorkspace(energyBins, Ys, Es, NSpec=3, UnitX='DeltaE', VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=verticalAxis, StoreInADS=False) LoadInstrument(ws, InstrumentName='IN4', RewriteSpectraMap=False, StoreInADS=False) AddSampleLog(ws, LogName='Ei', LogText=str(EFixed), LogType='Number', LogUnit='meV', StoreInADS=False) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEquals(dos.getNumberHistograms(), 1) self.assertEquals(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEquals(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g1 = self.compute(qs[0:2], energyBins) g2 = self.compute(qs[1:3], energyBins) g3 = self.compute(qs[2:4], energyBins) g = (g1 + g2 + g3) / 3 gE = np.sqrt(g1**2 + g2**2 + g3**2) / 3 np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], gE[i])
def test_multiple_histograms(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([1.1, 1.3, 1.5, 1.7]) EFixed = 8. Ys = np.ones(3 * (len(energyBins) - 1)) Es = Ys verticalAxis = [str(q) for q in qs] ws = CreateWorkspace(energyBins, Ys, Es, NSpec=3, UnitX='DeltaE', VerticalAxisUnit='MomentumTransfer', VerticalAxisValues=verticalAxis, StoreInADS=False) LoadInstrument(ws, InstrumentName='IN4', RewriteSpectraMap=False, StoreInADS=False) AddSampleLog(ws, LogName='Ei', LogText=str(EFixed), LogType='Number', LogUnit='meV', StoreInADS=False) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEqual(dos.getNumberHistograms(), 1) self.assertEqual(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEqual(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g1 = self.compute(qs[0:2], energyBins) g2 = self.compute(qs[1:3], energyBins) g3 = self.compute(qs[2:4], energyBins) g = (g1 + g2 + g3) / 3 gE = np.sqrt(g1**2 + g2**2 + g3**2) / 3 np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], gE[i])
def test_computation_nontransposed_TwoThetaW(self): energyBins = np.arange(-7., 7., 0.13) twoThetas = np.array([17.]) ws = self.unitySTwoThetaWSingleHistogram(energyBins, twoThetas) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEquals(dos.getNumberHistograms(), 1) self.assertEquals(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEquals(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.computeFromTwoTheta(twoThetas, energyBins) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])
def test_computation_nontransposed_TwoThetaW(self): energyBins = np.arange(-7., 7., 0.13) twoThetas = np.array([17.]) ws = self.unitySTwoThetaWSingleHistogram(energyBins, twoThetas) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEqual(dos.getNumberHistograms(), 1) self.assertEqual(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEqual(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.computeFromTwoTheta(twoThetas, energyBins) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])
def test_nondefault_temperature(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.3]) temperature = 666.7 ws = self.unitySQWSingleHistogram(energyBins, qs) dos = ComputeIncoherentDOS(ws, Temperature=temperature, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEquals(dos.getNumberHistograms(), 1) self.assertEquals(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEquals(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins, temperature=temperature) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])
def test_nonzero_MDS(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.3]) msd = 5.5 ws = self.unitySQWSingleHistogram(energyBins, qs) dos = ComputeIncoherentDOS(ws, MeanSquareDisplacement=msd, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEquals(dos.getNumberHistograms(), 1) self.assertEquals(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEquals(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins, msd=msd) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i], delta=g[i] * 1e-12) self.assertAlmostEquals(dos_Es[i], g[i], delta=g[i] * 1e-12)
def test_computation_transposed_QW(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.15, 2.25]) ws = self.unitySQWSingleHistogram(energyBins, qs) ws = Transpose(ws, StoreInADS=False) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEquals(dos.getNumberHistograms(), 1) self.assertEquals(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEquals(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])
def test_nondefault_temperature(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.3]) temperature = 666.7 ws = self.unitySQWSingleHistogram(energyBins, qs) dos = ComputeIncoherentDOS(ws, Temperature=temperature, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEqual(dos.getNumberHistograms(), 1) self.assertEqual(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEqual(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins, temperature=temperature) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])
def test_nonzero_MDS(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.3]) msd = 5.5 ws = self.unitySQWSingleHistogram(energyBins, qs) dos = ComputeIncoherentDOS(ws, MeanSquareDisplacement=msd, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEqual(dos.getNumberHistograms(), 1) self.assertEqual(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEqual(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins, msd=msd) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i], delta=g[i] * 1e-12) self.assertAlmostEquals(dos_Es[i], g[i], delta=g[i] * 1e-12)
def test_computation_transposed_QW(self): energyBins = np.arange(-7., 7., 0.13) qs = np.array([2.15, 2.25]) ws = self.unitySQWSingleHistogram(energyBins, qs) ws = Transpose(ws, StoreInADS=False) dos = ComputeIncoherentDOS(ws, EnergyBinning='Emin, Emax', StoreInADS=False) self.assertEqual(dos.getNumberHistograms(), 1) self.assertEqual(dos.getAxis(0).getUnit().unitID(), 'DeltaE') dos_Xs = dos.readX(0) self.assertEqual(len(dos_Xs), len(energyBins)) dos_Ys = dos.readY(0) dos_Es = dos.readE(0) g = self.compute(qs, energyBins) np.testing.assert_equal(dos_Xs, energyBins) for i in range(len(dos_Ys)): self.assertAlmostEquals(dos_Ys[i], g[i]) self.assertAlmostEquals(dos_Es[i], g[i])