class TestUBCalculationWithYouStrategy_Pt531_FixedMuChi(): def setup_method(self): hardware = Mock() names = 'm', 'd', 'n', 'e', 'c', 'p' hardware.get_axes_names.return_value = names self.ubcalc = UBCalculation(hardware, SixCircle(), UbCalculationNonPersister(), YouUbCalcStrategy()) def testAgainstResultsFromJan_28_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Pt531', 6.204, 4.806, 23.215, 90, 90, 49.8) self.ubcalc.add_reflection(Pt531_HKL0[0], Pt531_HKL0[1], Pt531_HKL0[2], willmott_to_you_fixed_mu_chi(Pt531_REF0), 12.39842 / Pt531_WAVELENGTH, 'ref0', None) self.ubcalc.add_reflection(Pt531_HKL1[0], Pt531_HKL1[1], Pt531_HKL1[2], willmott_to_you_fixed_mu_chi(Pt531_REF1), 12.39842 / Pt531_WAVELENGTH, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, Pt531_U_DIFFCALC)
class TestUBCalculationWithWillmotStrategy_Si_5_5_12_FixedMuChi(): def setup_method(self): hardware = Mock() names = 'm', 'd', 'n', 'e', 'c', 'p' hardware.get_axes_names.return_value = names settings.hardware = hardware settings.geometry = SixCircle() self.ubcalc = UBCalculation(UbCalculationNonPersister(), YouUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Si_5_5_12', 7.68, 53.48, 75.63, 90, 90, 90) self.ubcalc.add_reflection( HKL0[0], HKL0[1], HKL0[2], willmott_to_you_fixed_mu_chi(REF0), ENERGY, 'ref0', None) self.ubcalc.add_reflection( HKL1[0], HKL1[1], HKL1[2], willmott_to_you_fixed_mu_chi(REF1), ENERGY, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, U_DIFFCALC)
class TestUBCalculationWithYouStrategy(): """Testing the math only here. """ def setup_method(self): geometry = SixCircle() # pass through hardware = Mock() names = 'm', 'd', 'n', 'e', 'c', 'p' hardware.get_axes_names.return_value = names settings.hardware = hardware settings.geometry = geometry self.ubcalc = UBCalculation(UbCalculationNonPersister(), YouUbCalcStrategy()) def testAgainstI16Results(self): self.ubcalc.start_new('cubcalc') self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90) self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None) self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', None) self.ubcalc.calculate_UB() matrixeq_(self.ubcalc.UB, UB1)
class TestUBCalculationWithWillmotStrategy_Pt531(): def setup_method(self): hardware = Mock() hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p') self.ubcalc = UBCalculation(hardware, WillmottHorizontalGeometry(), UbCalculationNonPersister(), WillmottHorizontalUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Pt531', 6.204, 4.806, 23.215, 90, 90, 49.8) self.ubcalc.add_reflection(Pt531_HKL0[0], Pt531_HKL0[1], Pt531_HKL0[2], Pt531_REF0, 12.39842 / Pt531_WAVELENGTH, 'ref0', None) self.ubcalc.add_reflection(Pt531_HKL1[0], Pt531_HKL1[1], Pt531_HKL1[2], Pt531_REF1, 12.39842 / Pt531_WAVELENGTH, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, Pt531_U_DIFFCALC)
class TestUBCalculationWithYouStrategy(): """Testing the math only here. """ def setup_method(self): geometry = SixCircle() # pass through hardware = Mock() names = 'm', 'd', 'n', 'e', 'c', 'p' hardware.get_axes_names.return_value = names self.ubcalc = UBCalculation(hardware, geometry, UbCalculationNonPersister(), YouUbCalcStrategy()) def testAgainstI16Results(self): self.ubcalc.start_new('cubcalc') self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90) self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None) self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', None) self.ubcalc.calculate_UB() matrixeq_(self.ubcalc.UB, UB1)
class TestUBCalculationWithWillmotStrategy_Pt531(): def setUp(self): hardware = Mock() hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p') self.ubcalc = UBCalculation(hardware, WillmottHorizontalGeometry(), UbCalculationNonPersister(), WillmottHorizontalUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Pt531', 6.204, 4.806, 23.215, 90, 90, 49.8) self.ubcalc.add_reflection( Pt531_HKL0[0], Pt531_HKL0[1], Pt531_HKL0[2], Pt531_REF0, 12.39842 / Pt531_WAVELENGTH, 'ref0', None) self.ubcalc.add_reflection( Pt531_HKL1[0], Pt531_HKL1[1], Pt531_HKL1[2], Pt531_REF1, 12.39842 / Pt531_WAVELENGTH, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, Pt531_U_DIFFCALC)
class TestUBCalculationWithWillmotStrategy_Si_5_5_12(): def setUp(self): hardware = Mock() hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p') self.ubcalc = UBCalculation(hardware, WillmottHorizontalGeometry(), UbCalculationNonPersister(), WillmottHorizontalUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Si_5_5_12', 7.68, 53.48, 75.63, 90, 90, 90) self.ubcalc.add_reflection( Si_5_5_12_HKL0[0], Si_5_5_12_HKL0[1], Si_5_5_12_HKL0[2], Si_5_5_12_REF0, 12.39842 / Si_5_5_12_WAVELENGTH, 'ref0', None) self.ubcalc.add_reflection( Si_5_5_12_HKL1[0], Si_5_5_12_HKL1[1], Si_5_5_12_HKL1[2], Si_5_5_12_REF1, 12.39842 / Si_5_5_12_WAVELENGTH, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, Si_5_5_12_U_DIFFCALC)
class TestUBCalculationWithWillmotStrategy_Si_5_5_12(): def setup_method(self): hardware = Mock() hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p') self.ubcalc = UBCalculation(hardware, WillmottHorizontalGeometry(), UbCalculationNonPersister(), WillmottHorizontalUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Si_5_5_12', 7.68, 53.48, 75.63, 90, 90, 90) self.ubcalc.add_reflection(Si_5_5_12_HKL0[0], Si_5_5_12_HKL0[1], Si_5_5_12_HKL0[2], Si_5_5_12_REF0, 12.39842 / Si_5_5_12_WAVELENGTH, 'ref0', None) self.ubcalc.add_reflection(Si_5_5_12_HKL1[0], Si_5_5_12_HKL1[1], Si_5_5_12_HKL1[2], Si_5_5_12_REF1, 12.39842 / Si_5_5_12_WAVELENGTH, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, Si_5_5_12_U_DIFFCALC)
class TestUBCalculationWithWillmotStrategy_Si_5_5_12_FixedMuChi(): def setup_method(self): hardware = Mock() names = 'm', 'd', 'n', 'e', 'c', 'p' hardware.get_axes_names.return_value = names self.ubcalc = UBCalculation(hardware, SixCircle(), UbCalculationNonPersister(), YouUbCalcStrategy()) def testAgainstResultsFromJan_27_2010(self): self.ubcalc.start_new('test') self.ubcalc.set_lattice('Si_5_5_12', 7.68, 53.48, 75.63, 90, 90, 90) self.ubcalc.add_reflection( HKL0[0], HKL0[1], HKL0[2], willmott_to_you_fixed_mu_chi(REF0), ENERGY, 'ref0', None) self.ubcalc.add_reflection( HKL1[0], HKL1[1], HKL1[2], willmott_to_you_fixed_mu_chi(REF1), ENERGY, 'ref1', None) self.ubcalc.calculate_UB() print "U: ", self.ubcalc.U print "UB: ", self.ubcalc.UB matrixeq_(self.ubcalc.U, U_DIFFCALC)
class TestUBCalculationWithSixCircleGammaOnArm(unittest.TestCase): def setUp(self): self.geometry = SixCircleGammaOnArmGeometry() self.ubcalc = UBCalculation( ("a", "d", "g", "o", "c", "p"), self.geometry, UbCalculationNonPersister(), VliegUbCalcStrategy() ) self.time = datetime.now() ### State ### def testNewCalculation(self): self.ubcalc.start_new("testcalc") self.assertEqual(self.ubcalc.name, "testcalc", "Name not set by newCalcualtion") @raises(DiffcalcException) def testNewCalculationHasNoU(self): self.ubcalc.start_new("testcalc") print self.ubcalc.U @raises(DiffcalcException) def testNewCalculationHasNoUB(self): self.ubcalc.start_new("testcalc") print self.ubcalc.UB ### Lattice ### def testSetLattice(self): # Not much to test, just make sure no exceptions self.ubcalc.start_new("testcalc") self.ubcalc.set_lattice("testlattice", 4.0004, 4.0004, 2.27, 90, 90, 90) ### Calculations ### def testset_U_manually(self): # Test the calculations with U=I U = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] for sess in scenarios.sessions(): self.setUp() self.ubcalc.start_new("testcalc") self.ubcalc.set_lattice(sess.name, *sess.lattice) self.ubcalc.set_U_manually(U) # Check the U matrix mneq_(self.ubcalc.U, matrix(U), 4, note="wrong U after manually setting U") # Check the UB matrix if sess.bmatrix is None: continue print "U: ", U print "actual ub: ", self.ubcalc.UB.tolist() print " desired b: ", sess.bmatrix mneq_(self.ubcalc.UB, matrix(sess.bmatrix), 4, note="wrong UB after manually setting U") @raises(DiffcalcException) def testGetUMatrix(self): self.ubcalc.start_new("testcalc") print self.ubcalc.U @raises(DiffcalcException) def testGetUBMatrix(self): self.ubcalc.start_new("testcalc") print self.ubcalc.UB def testCalculateU(self): for sess in scenarios.sessions(): self.setUp() self.ubcalc.start_new("testcalc") # Skip this test case unless it contains a umatrix if sess.umatrix is None: continue self.ubcalc.set_lattice(sess.name, *sess.lattice) ref1 = sess.ref1 ref2 = sess.ref2 t = sess.time self.ubcalc.add_reflection(ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t) self.ubcalc.add_reflection(ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t) self.ubcalc.calculate_UB() returned = self.ubcalc.U.tolist() print "*Required:" print sess.umatrix print "*Returned:" print returned mneq_(self.ubcalc.U, matrix(sess.umatrix), 4, note="wrong U calulated for sess.name=" + sess.name) def test__str__(self): sess = scenarios.sessions()[0] print "***" print self.ubcalc.__str__() print "***" self.ubcalc.start_new("test") print self.ubcalc.__str__() print "***" self.ubcalc.set_lattice(sess.name, *sess.lattice) print self.ubcalc.__str__() print "***" ref1 = sess.ref1 ref2 = sess.ref2 t = sess.time self.ubcalc.add_reflection(ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t) self.ubcalc.add_reflection(ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t) print self.ubcalc.__str__() print "***" self.ubcalc.calculate_UB() print self.ubcalc.__str__()
class TestUBCalculationWithSixCircleGammaOnArm(object): def setup_method(self): self.geometry = SixCircleGammaOnArmGeometry() mock_hardware = Mock() mock_hardware.get_axes_names.return_value = ('a', 'd', 'g', 'o', 'c', 'p') self.ubcalc = UBCalculation( mock_hardware, self.geometry, UbCalculationNonPersister(), VliegUbCalcStrategy()) self.time = datetime.now() ### State ### def testNewCalculation(self): self.ubcalc.start_new('testcalc') assert self.ubcalc.name, 'testcalc' == "Name not set by newCalcualtion" @raises(DiffcalcException) def testNewCalculationHasNoU(self): self.ubcalc.start_new('testcalc') print self.ubcalc.U @raises(DiffcalcException) def testNewCalculationHasNoUB(self): self.ubcalc.start_new('testcalc') print self.ubcalc.UB ### Lattice ### def testSetLattice(self): # Not much to test, just make sure no exceptions self.ubcalc.start_new('testcalc') self.ubcalc.set_lattice('testlattice', 4.0004, 4.0004, 2.27, 90, 90, 90) ### Calculations ### def testset_U_manually(self): # Test the calculations with U=I U = [[1, 0, 0], [0, 1, 0], [0, 0, 1]] for sess in scenarios.sessions(): self.setup_method() self.ubcalc.start_new('testcalc') self.ubcalc.set_lattice(sess.name, *sess.lattice) self.ubcalc.set_U_manually(U) # Check the U matrix mneq_(self.ubcalc.U, matrix(U), 4, note="wrong U after manually setting U") # Check the UB matrix if sess.bmatrix is None: continue print "U: ", U print "actual ub: ", self.ubcalc.UB.tolist() print " desired b: ", sess.bmatrix mneq_(self.ubcalc.UB, matrix(sess.bmatrix), 4, note="wrong UB after manually setting U") @raises(DiffcalcException) def testGetUMatrix(self): self.ubcalc.start_new('testcalc') print self.ubcalc.U @raises(DiffcalcException) def testGetUBMatrix(self): self.ubcalc.start_new('testcalc') print self.ubcalc.UB def testCalculateU(self): for sess in scenarios.sessions(): self.setup_method() self.ubcalc.start_new('testcalc') # Skip this test case unless it contains a umatrix if sess.umatrix is None: continue self.ubcalc.set_lattice(sess.name, *sess.lattice) ref1 = sess.ref1 ref2 = sess.ref2 t = sess.time self.ubcalc.add_reflection( ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t) self.ubcalc.add_reflection( ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t) self.ubcalc.calculate_UB() returned = self.ubcalc.U.tolist() print "*Required:" print sess.umatrix print "*Returned:" print returned mneq_(self.ubcalc.U, matrix(sess.umatrix), 4, note="wrong U calulated for sess.name=" + sess.name) def test__str__(self): sess = scenarios.sessions()[0] print "***" print self.ubcalc.__str__() print "***" self.ubcalc.start_new('test') print self.ubcalc.__str__() print "***" self.ubcalc.set_lattice(sess.name, *sess.lattice) print self.ubcalc.__str__() print "***" ref1 = sess.ref1 ref2 = sess.ref2 t = sess.time self.ubcalc.add_reflection( ref1.h, ref1.k, ref1.l, ref1.pos, ref1.energy, ref1.tag, t) self.ubcalc.add_reflection( ref2.h, ref2.k, ref2.l, ref2.pos, ref2.energy, ref2.tag, t) print self.ubcalc.__str__() print "***" self.ubcalc.calculate_UB() print self.ubcalc.__str__()