def setup_method(self):
     hardware = Mock()
     hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p')
     settings.geometry = WillmottHorizontalGeometry()
     settings.hardware = hardware
     self.ubcalc = UBCalculation(UbCalculationNonPersister(),
                                 WillmottHorizontalUbCalcStrategy())
Ejemplo n.º 2
0
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)
Ejemplo n.º 3
0
    def setup_method(self):

        hardware = Mock()
        hardware.get_axes_names.return_value = ('m', 'd', 'n', 'e', 'c', 'p')
        self.ubcalc = UBCalculation(hardware, SixCircle(),
                                    UbCalculationNonPersister(),
                                    YouUbCalcStrategy())
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)
Ejemplo n.º 5
0
 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()
    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())
Ejemplo n.º 7
0
 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())
Ejemplo n.º 8
0
 def setup_method(self):
     self.geometry = SixCircleGammaOnArmGeometry()
     mock_hardware = Mock()
     mock_hardware.energyScannableMultiplierToGetKeV = 1
     mock_hardware.get_axes_names.return_value = ('a', 'd', 'g', 'o', 'c',
                                                  'p')
     settings.hardware = mock_hardware
     settings.geometry = self.geometry
     self.ubcalc = UBCalculation(UbCalculationNonPersister(),
                                 VliegUbCalcStrategy())
     self.time = datetime.now()
Ejemplo n.º 9
0
 def setup_method(self):
     print "TestUBCalcWithCubic.setup_method"
     hardware = Mock()
     hardware.get_axes_names.return_value = \
         ('a', 'd', 'g', 'o', 'c', 'p')
     self.ubcalc = UBCalculation(hardware,
                                 SixCircleGammaOnArmGeometry(),
                                 UbCalculationNonPersister(),
                                 VliegUbCalcStrategy())
     self.ubcalc.start_new('xtalubcalc')
     self.ubcalc.set_lattice("xtal", *CUBIC)
     self.energy = CUBIC_EN
Ejemplo n.º 10
0
 def setup_method(self):
     print "TestUBCalcWithCubic.setup_method"
     mock_hardware = Mock()
     mock_hardware.energyScannableMultiplierToGetKeV = 1
     mock_hardware.get_axes_names.return_value = \
         ('a', 'd', 'g', 'o', 'c', 'p')
     settings.hardware = mock_hardware
     settings.geometry = SixCircleGammaOnArmGeometry()
     self.ubcalc = UBCalculation(UbCalculationNonPersister(),
                                 VliegUbCalcStrategy())
     self.ubcalc.start_new('xtalubcalc')
     self.ubcalc.set_lattice("xtal", *CUBIC)
     self.energy = CUBIC_EN
Ejemplo n.º 11
0
    def setup_method(self):

        self.tempdir = tempfile.mkdtemp()

        geometry = SixCircle()  # pass through
        hardware = Mock()
        names = 'm', 'd', 'n', 'e', 'c', 'p'
        hardware.get_axes_names.return_value = names
        self.tmpdir = tempfile.mkdtemp()
        print self.tmpdir
        self.ubcalc = UBCalculation(hardware, geometry,
                                    UBCalculationJSONPersister(self.tmpdir),
                                    YouUbCalcStrategy())
Ejemplo n.º 12
0
    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 setUp(self):
     hardware = Mock()
     hardware.get_axes_names.return_value = ("a", "d", "g", "o", "c", "p")
     self.ubcalc = UBCalculation(
         hardware, SixCircleGammaOnArmGeometry(), UbCalculationNonPersister(), VliegUbCalcStrategy()
     )
     self.ubcalc.start_new("xtalubcalc")
     self.ubcalc.set_lattice("xtal", *CUBIC)
     self.energy = CUBIC_EN
 def setUp(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())
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 17
0
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)
Ejemplo n.º 18
0
    def setUp(self):
        
        self.tempdir = tempfile.mkdtemp()

        geometry = SixCircle()  # pass through
        hardware = Mock()
        names = 'm', 'd', 'n', 'e', 'c', 'p'
        hardware.get_axes_names.return_value = names
        self.tmpdir = tempfile.mkdtemp()
        print self.tmpdir
        self.ubcalc = UBCalculation(hardware,
                                    geometry,
                                    UBCalculationJSONPersister(self.tmpdir),
                                    YouUbCalcStrategy())
Ejemplo n.º 19
0
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)
Ejemplo n.º 20
0
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)
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
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 TestUBCalcWithCubic:
    def setUp(self):
        hardware = Mock()
        hardware.get_axes_names.return_value = ("a", "d", "g", "o", "c", "p")
        self.ubcalc = UBCalculation(
            hardware, SixCircleGammaOnArmGeometry(), UbCalculationNonPersister(), VliegUbCalcStrategy()
        )
        self.ubcalc.start_new("xtalubcalc")
        self.ubcalc.set_lattice("xtal", *CUBIC)
        self.energy = CUBIC_EN

    def addref(self, hklref):
        hkl, position = hklref
        now = datetime.now()
        self.ubcalc.add_reflection(hkl[0], hkl[1], hkl[2], position, self.energy, "ref", now)
Ejemplo n.º 24
0
class TestUBCalcWithCubic(object):

    def setup_method(self):
        print "TestUBCalcWithCubic.setup_method"
        hardware = Mock()
        hardware.get_axes_names.return_value = \
            ('a', 'd', 'g', 'o', 'c', 'p')
        self.ubcalc = UBCalculation(hardware,
                                    SixCircleGammaOnArmGeometry(),
                                    UbCalculationNonPersister(),
                                    VliegUbCalcStrategy())
        self.ubcalc.start_new('xtalubcalc')
        self.ubcalc.set_lattice("xtal", *CUBIC)
        self.energy = CUBIC_EN

    def addref(self, hklref):
        hkl, position = hklref
        now = datetime.now()
        self.ubcalc.add_reflection(
            hkl[0], hkl[1], hkl[2], position, self.energy, "ref", now)
class TestUBCalculationWithYouStrategy():
    """Testing the math only here.
    """
    def setup_method(self):

        self.tempdir = tempfile.mkdtemp()

        geometry = SixCircle()  # pass through
        hardware = Mock()
        names = 'm', 'd', 'n', 'e', 'c', 'p'
        hardware.get_axes_names.return_value = names
        self.tmpdir = tempfile.mkdtemp()
        print self.tmpdir
        settings.hardware = hardware
        settings.geometry = geometry
        self.ubcalc = UBCalculation(
            UBCalculationJSONPersister(self.tmpdir, UBCalcStateEncoder),
            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)
        matrixeq_(self.ubcalc.UB, UB1)

    def test_save_and_restore_empty_ubcalc_with_one_already_started(self):
        NAME = 'test_save_and_restore_empty_ubcalc_with_one_already_started'
        self.ubcalc.start_new(NAME)
        self.ubcalc.start_new(NAME)

    def test_save_and_restore_empty_ubcalc(self):
        NAME = 'test_save_and_restore_empty_ubcalc'
        self.ubcalc.start_new(NAME)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        eq_(self.ubcalc.name, NAME)

    def test_save_and_restore_ubcalc_with_lattice(self):
        NAME = 'test_save_and_restore_ubcalc_with_lattice'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        eq_(self.ubcalc._state.crystal.getLattice(),
            ('latt', 1, 1, 1, 90, 90, 90))

    def test_save_and_restore_ubcalc_with_reflections(self):
        NAME = 'test_save_and_restore_ubcalc_with_reflections'
        self.ubcalc.start_new(NAME)
        now = datetime.datetime.now()
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', now)
        self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', now)
        self.ubcalc.add_reflection(0, 0, 1.5, REF1b, EN1, '001_5', now)
        ref1 = self.ubcalc.get_reflection(1)
        ref2 = self.ubcalc.get_reflection(2)
        ref3 = self.ubcalc.get_reflection(3)
        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)

    def test_save_and_restore_ubcalc_with_UB_from_two_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_two_ref'
        self.ubcalc.start_new(NAME)
        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)
        matrixeq_(self.ubcalc.UB, UB1)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        matrixeq_(self.ubcalc.UB, UB1)

    def test_save_and_restore_ubcalc_with_UB_from_one_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_one_ref'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
        self.ubcalc.calculate_UB_from_primary_only()
        matrixeq_(self.ubcalc.UB, UB1, places=2)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        matrixeq_(self.ubcalc.UB, UB1, places=2)

    def test_save_and_restore_ubcalc_with_manual_ub(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_ub'
        UB = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_UB_manually(UB)
        matrixeq_(self.ubcalc.UB, UB)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        matrixeq_(self.ubcalc.UB, UB)

    def test_save_and_restore_ubcalc_with_manual_u(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_u'
        U = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.set_U_manually(U)
        matrixeq_(self.ubcalc.UB, U * 2 * pi)

        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)

        matrixeq_(self.ubcalc.UB, U * 2 * pi)

    def test_calc_hkl_offset(self):
        NAME = 'test_calc_hkl_offset'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.set_U_manually(x_rotation(0))
        hkloff_110 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 90. * TORAD,
                                                 -45 * TORAD)
        hkloff_m101 = self.ubcalc.calc_hkl_offset(0, 0, sqrt(2), 45. * TORAD,
                                                  90 * TORAD)
        alpha = atan2(2, 1)
        hkloff_102 = self.ubcalc.calc_hkl_offset(sqrt(5), 0, 0, alpha,
                                                 90 * TORAD)
        matrixeq_(matrix('1 1 0'), matrix(hkloff_110))
        matrixeq_(matrix('-1 0 1'), matrix(hkloff_m101))
        matrixeq_(matrix('1 0 2'), matrix(hkloff_102))

    def test_calc_offset_for_hkl(self):
        NAME = 'test_calc_offset_for_hkl'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.set_U_manually(x_rotation(0))
        for hklref, hkloff, pol_ref, az_ref, sc_ref in [
            ([0, 0, 1], [1, 1, 0], 90 * TORAD, -45 * TORAD, sqrt(2)),
            ([0, 0, 1], [-1, 0, 1], 45 * TORAD, 90 * TORAD, sqrt(2)),
            ([1, 0, 0], [1, 0, 2], atan2(2, 1), 90 * TORAD, sqrt(5)),
        ]:
            pol, az, sc = self.ubcalc.calc_offset_for_hkl(hkloff, hklref)
            matrixeq_(matrix([[pol_ref, az_ref, sc_ref]]),
                      matrix([[pol, az, sc]]))
Ejemplo n.º 26
0
class TestUBCalculationWithYouStrategy():
    """Testing the math only here.
    """

    def setup_method(self):
        
        self.tempdir = tempfile.mkdtemp()

        geometry = SixCircle()  # pass through
        hardware = Mock()
        names = 'm', 'd', 'n', 'e', 'c', 'p'
        hardware.get_axes_names.return_value = names
        self.tmpdir = tempfile.mkdtemp()
        print self.tmpdir
        self.ubcalc = UBCalculation(hardware,
                                    geometry,
                                    UBCalculationJSONPersister(self.tmpdir),
                                    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)
        matrixeq_(self.ubcalc.UB, UB1)
        
    def test_save_and_restore_empty_ubcalc_with_one_already_started(self):
        NAME = 'test_save_and_restore_empty_ubcalc_with_one_already_started'
        self.ubcalc.start_new(NAME)
        self.ubcalc.start_new(NAME)
    
    
    def test_save_and_restore_empty_ubcalc(self):
        NAME = 'test_save_and_restore_empty_ubcalc'
        self.ubcalc.start_new(NAME)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc.name, NAME)
        
    def test_save_and_restore_ubcalc_with_lattice(self):
        NAME = 'test_save_and_restore_ubcalc_with_lattice'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc._state.crystal.getLattice(), ('latt', 1, 1, 1, 90, 90, 90))
        
    def test_save_and_restore_ubcalc_with_reflections(self):
        NAME = 'test_save_and_restore_ubcalc_with_reflections'
        self.ubcalc.start_new(NAME)
        now = datetime.datetime.now()
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', now)
        self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', now)
        self.ubcalc.add_reflection(0, 0, 1.5, REF1b, EN1, '001_5', now)
        ref1 = self.ubcalc.get_reflection(1)
        ref2 = self.ubcalc.get_reflection(2)
        ref3 = self.ubcalc.get_reflection(3)
        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)
        
    def test_save_and_restore_ubcalc_with_UB_from_two_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_two_ref'
        self.ubcalc.start_new(NAME)
        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)
        matrixeq_(self.ubcalc.UB, UB1)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB1)
        
    def test_save_and_restore_ubcalc_with_UB_from_one_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_one_ref'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
        self.ubcalc.calculate_UB_from_primary_only()
        matrixeq_(self.ubcalc.UB, UB1,  places=2)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB1,  places=2)

    def test_save_and_restore_ubcalc_with_manual_ub(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_ub'
        UB = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_UB_manually(UB)
        matrixeq_(self.ubcalc.UB, UB)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB)

    def test_save_and_restore_ubcalc_with_manual_u(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_u'
        U = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.set_U_manually(U)
        matrixeq_(self.ubcalc.UB, U * 2 * pi)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, U * 2 * pi)
 def setUp(self):
     self.geometry = SixCircleGammaOnArmGeometry()
     self.ubcalc = UBCalculation(
         ("a", "d", "g", "o", "c", "p"), self.geometry, UbCalculationNonPersister(), VliegUbCalcStrategy()
     )
     self.time = datetime.now()
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__()
Ejemplo n.º 29
0
 def setUp(self):
     hardware = Mock()
     hardware.get_axes_names.return_value = ('d', 'g', 'oh', 'p')
     self.ubcalc = UBCalculation(hardware, WillmottHorizontalGeometry(),
                                 UbCalculationNonPersister(),
                                 WillmottHorizontalUbCalcStrategy())
Ejemplo n.º 30
0
__all__ = ['addorient', 'addref', 'c2th', 'hklangle', 'calcub', 'delorient', 'delref', 'editorient',
           'editref', 'listub', 'loadub', 'newub', 'orientub', 'saveubas', 'setlat',
           'addmiscut', 'setmiscut', 'setu', 'setub', 'showorient', 'showref', 'swaporient',
           'swapref', 'trialub', 'fitub', 'checkub', 'ub', 'ubcalc', 'rmub', 'clearorient',
           'clearref', 'lastub', 'refineub', 'surfnphi', 'surfnhkl']

if settings.include_sigtau:
    __all__.append('sigtau')

if settings.include_reference:
    __all__.append('setnphi')
    __all__.append('setnhkl')


ubcalc = UBCalculation(settings.ubcalc_persister,
                       settings.ubcalc_strategy,
                       settings.include_sigtau,
                       settings.include_reference)



### UB state ###

@command
def newub(name=None):
    """newub {'name'} -- start a new ub calculation name
    """
    if name is None:
        # interactive
        name = promptForInput('calculation name')
        while not name:
            print('Please provide non-empty UB calculation name')
Ejemplo n.º 31
0
class TestUBCalculationWithYouStrategy():
    """Testing the math only here.
    """

    def setUp(self):
        
        self.tempdir = tempfile.mkdtemp()

        geometry = SixCircle()  # pass through
        hardware = Mock()
        names = 'm', 'd', 'n', 'e', 'c', 'p'
        hardware.get_axes_names.return_value = names
        self.tmpdir = tempfile.mkdtemp()
        print self.tmpdir
        self.ubcalc = UBCalculation(hardware,
                                    geometry,
                                    UBCalculationJSONPersister(self.tmpdir),
                                    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)
        matrixeq_(self.ubcalc.UB, UB1)
        
    def test_save_and_restore_empty_ubcalc_with_one_already_started(self):
        NAME = 'test_save_and_restore_empty_ubcalc_with_one_already_started'
        self.ubcalc.start_new(NAME)
        self.ubcalc.start_new(NAME)
    
    
    def test_save_and_restore_empty_ubcalc(self):
        NAME = 'test_save_and_restore_empty_ubcalc'
        self.ubcalc.start_new(NAME)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc.name, NAME)
        
    def test_save_and_restore_ubcalc_with_lattice(self):
        NAME = 'test_save_and_restore_ubcalc_with_lattice'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc._state.crystal.getLattice(), ('latt', 1, 1, 1, 90, 90, 90))
        
    def test_save_and_restore_ubcalc_with_reflections(self):
        NAME = 'test_save_and_restore_ubcalc_with_reflections'
        self.ubcalc.start_new(NAME)
        now = datetime.datetime.now()
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', now)
        self.ubcalc.add_reflection(0, 0, 1, REF1b, EN1, '001', now)
        self.ubcalc.add_reflection(0, 0, 1.5, REF1b, EN1, '001_5', now)
        ref1 = self.ubcalc.get_reflection(1)
        ref2 = self.ubcalc.get_reflection(2)
        ref3 = self.ubcalc.get_reflection(3)
        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        eq_(self.ubcalc.get_reflection(1), ref1)
        eq_(self.ubcalc.get_reflection(2), ref2)
        eq_(self.ubcalc.get_reflection(3), ref3)
        
    def test_save_and_restore_ubcalc_with_UB_from_two_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_two_ref'
        self.ubcalc.start_new(NAME)
        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)
        matrixeq_(self.ubcalc.UB, UB1)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB1)
        
    def test_save_and_restore_ubcalc_with_UB_from_one_ref(self):
        NAME = 'test_save_and_restore_ubcalc_with_UB_from_one_ref'
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.add_reflection(1, 0, 0, REF1a, EN1, '100', None)
        self.ubcalc.calculate_UB_from_primary_only()
        matrixeq_(self.ubcalc.UB, UB1,  places=2)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB1,  places=2)

    def test_save_and_restore_ubcalc_with_manual_ub(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_ub'
        UB = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_UB_manually(UB)
        matrixeq_(self.ubcalc.UB, UB)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, UB)

    def test_save_and_restore_ubcalc_with_manual_u(self):
        NAME = 'test_save_and_restore_ubcalc_with_manual_u'
        U = matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
        self.ubcalc.start_new(NAME)
        self.ubcalc.set_lattice('latt', 1, 1, 1, 90, 90, 90)
        self.ubcalc.set_U_manually(U)
        matrixeq_(self.ubcalc.UB, U * 2 * pi)
        
        self.ubcalc.start_new(NAME + '2')
        self.ubcalc.load(NAME)
        
        matrixeq_(self.ubcalc.UB, U * 2 * pi)
Ejemplo n.º 32
0
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__()