コード例 #1
0
class Test_calc_remaining_sample_angles_given_one():
    #_calc_remaining_detector_angles_given_one
    def setup_method(self):
        self.calc = YouHklCalculator(createMockUbcalc(None),
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor(), Mock())

    def check(self, name, value, Q_lab, n_lab, Q_phi, n_phi, phi_e, chi_e,
              eta_e, mu_e):
        mu, eta, chi, phi = zip(*self.calc._calc_remaining_sample_angles(
            name, value * TORAD, Q_lab, n_lab, Q_phi, n_phi))
        for mu_, eta_, chi_, phi_ in zip(mu, eta, chi, phi):
            print 'phi', phi_ * TODEG, ' chi:', chi_ * TODEG, ' eta:', eta_ * TODEG,\
                  ' mu:', mu_ * TODEG
        if phi_e is not None:
            assert_array_almost_equal([v * TODEG for v in phi], phi_e)
        if chi_e is not None:
            assert_array_almost_equal([v * TODEG for v in chi], chi_e)
        if eta_e is not None:
            assert_array_almost_equal([v * TODEG for v in eta], eta_e)
        if mu_e is not None:
            assert_array_almost_equal([v * TODEG for v in mu], mu_e)

    def test_constrain_xx_degenerate(self):
        self.check('mu',
                   0,
                   Q_lab=x,
                   n_lab=x,
                   Q_phi=x,
                   n_phi=x,
                   phi_e=[
                       0,
                   ],
                   chi_e=[
                       0,
                   ],
                   eta_e=[
                       0,
                   ],
                   mu_e=[
                       0,
                   ])

    def test_constrain_mu_0(self):
        self.check('mu',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[
                       0,
                   ],
                   chi_e=[
                       0,
                   ],
                   eta_e=[
                       0,
                   ],
                   mu_e=[
                       0,
                   ])

    def test_constrain_mu_10(self):
        self.check('mu',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[90, -90],
                   chi_e=[10, -10],
                   eta_e=[-90, 90],
                   mu_e=[10, 10])

    def test_constrain_mu_n10(self):
        self.check('mu',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[-90, 90],
                   chi_e=[10, -10],
                   eta_e=[90, -90],
                   mu_e=[-10, -10])

    def test_constrain_eta_10_wasfailing(self):
        # Required the choice of a different equation
        self.check('eta',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[-10, -170],
                   chi_e=[0, 180],
                   eta_e=[10, 10],
                   mu_e=[0, -180])

    def test_constrain_eta_n10(self):
        self.check('eta',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[10, 170],
                   chi_e=[0, 180],
                   eta_e=[-10, -10],
                   mu_e=[0, 180])

    def test_constrain_eta_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('eta',
                   20,
                   Q_lab=Q_lab,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[0, -140],
                   chi_e=[0, 180],
                   eta_e=[20, 20],
                   mu_e=[0, -180])

    @raises(DiffcalcException)
    def test_constrain_chi_0_degenerate(self):
        self.check('chi',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_chi_10(self):
        self.check('chi',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[-90, 90],
                   chi_e=[10, 10],
                   eta_e=[90, -90],
                   mu_e=[-10, 10])

    @raises(DiffcalcException)
    def test_constrain_chi_90(self):
        self.check('chi',
                   90,
                   Q_lab=z * (-1),
                   n_lab=x,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[0, 0],
                   chi_e=[90, 90],
                   eta_e=[0, 0],
                   mu_e=[-180, 0])

    def test_constrain_phi_0(self):
        self.check('phi',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[0, 0],
                   chi_e=[0, -180],
                   eta_e=[0, 180],
                   mu_e=[0, -180])

    def test_constrain_phi_10(self):
        self.check('phi',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[10, 10],
                   chi_e=[0, -180],
                   eta_e=[-10, 190],
                   mu_e=[0, -180])

    def test_constrain_phi_n10(self):
        self.check('phi',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[-10, -10],
                   chi_e=[0, -180],
                   eta_e=[10, 170],
                   mu_e=[0, -180])

    def test_constrain_phi_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('phi',
                   20,
                   Q_lab=Q_lab,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=[20, 20],
                   chi_e=[0, -180],
                   eta_e=[0, 180],
                   mu_e=[0, -180])
コード例 #2
0
class Test_calc_remaining_sample_angles_given_one():
    #_calc_remaining_detector_angles_given_one
    def setup(self):
        self.calc = YouHklCalculator(createMockUbcalc(None),
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor(),
                                     Mock())

    def check(self, name, value, Q_lab, n_lab, Q_phi, n_phi,
              phi_e, chi_e, eta_e, mu_e):
        phi, chi, eta, mu = self.calc._calc_remaining_sample_angles(
                            name, value * TORAD, Q_lab, n_lab, Q_phi, n_phi)
        print 'phi', phi * TODEG, ' chi:', chi * TODEG, ' eta:', eta * TODEG,\
              ' mu:', mu * TODEG
        if phi_e is not None:
            assert_almost_equal(phi * TODEG, phi_e)
        if chi_e is not None:
            assert_almost_equal(chi * TODEG, chi_e)
        if eta_e is not None:
            assert_almost_equal(eta * TODEG, eta_e)
        if mu_e is not None:
            assert_almost_equal(mu * TODEG, mu_e)

    @raises(ValueError)
    def test_constrain_xx_degenerate(self):
        self.check('mu', 0, Q_lab=x, n_lab=x, Q_phi=x, n_phi=x,
                    phi_e=0, chi_e=0, eta_e=0, mu_e=0)

    def test_constrain_mu_0(self):
        raise SkipTest()
        self.check('mu', 0, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=0, chi_e=0, eta_e=0, mu_e=0)

    def test_constrain_mu_10(self):
        raise SkipTest()
        self.check('mu', 10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=-90, chi_e=10, eta_e=-90, mu_e=10)

    def test_constrain_mu_n10(self):
        raise SkipTest()
        self.check('mu', -10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=90, chi_e=10, eta_e=90, mu_e=-10)

    def test_constrain_eta_10_wasfailing(self):
        # Required the choice of a different equation
        self.check('eta', 10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=-10, chi_e=0, eta_e=10, mu_e=0)

    def test_constrain_eta_n10(self):
        self.check('eta', -10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=10, chi_e=0, eta_e=-10, mu_e=0)

    def test_constrain_eta_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('eta', 20, Q_lab=Q_lab, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=0, chi_e=0, eta_e=20, mu_e=0)

    @raises(ValueError)
    def test_constrain_chi_0_degenerate(self):
        self.check('chi', 0, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=0, chi_e=0, eta_e=0, mu_e=0)

    def test_constrain_chi_10(self):
        self.check('chi', 10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=-90, chi_e=10, eta_e=90, mu_e=-10)

    def test_constrain_chi_90(self):
        # mu is off by 180, but youcalc tries +-x and 180+-x anyway
        raise SkipTest()
        self.check('chi', 90, Q_lab=z * (-1), n_lab=x, Q_phi=x, n_phi=z,
                    phi_e=0, chi_e=90, eta_e=0, mu_e=0)

    def test_constrain_phi_0(self):
        self.check('phi', 0, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=0, chi_e=0, eta_e=0, mu_e=0)

    def test_constrain_phi_10(self):
        self.check('phi', 10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=10, chi_e=0, eta_e=-10, mu_e=0)

    def test_constrain_phi_n10(self):
        self.check('phi', -10, Q_lab=x, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=-10, chi_e=0, eta_e=10, mu_e=0)

    def test_constrain_phi_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('phi', 20, Q_lab=Q_lab, n_lab=z, Q_phi=x, n_phi=z,
                    phi_e=20, chi_e=0, eta_e=0, mu_e=0)
コード例 #3
0
class Test_calc_remaining_sample_angles_given_one():
    #_calc_remaining_detector_angles_given_one
    def setup_method(self):
        self.calc = YouHklCalculator(createMockUbcalc(None),
                                     createMockDiffractometerGeometry(),
                                     createMockHardwareMonitor(), Mock())

    def check(self, name, value, Q_lab, n_lab, Q_phi, n_phi, phi_e, chi_e,
              eta_e, mu_e):
        phi, chi, eta, mu = self.calc._calc_remaining_sample_angles(
            name, value * TORAD, Q_lab, n_lab, Q_phi, n_phi)
        print 'phi', phi * TODEG, ' chi:', chi * TODEG, ' eta:', eta * TODEG,\
              ' mu:', mu * TODEG
        if phi_e is not None:
            assert_almost_equal(phi * TODEG, phi_e)
        if chi_e is not None:
            assert_almost_equal(chi * TODEG, chi_e)
        if eta_e is not None:
            assert_almost_equal(eta * TODEG, eta_e)
        if mu_e is not None:
            assert_almost_equal(mu * TODEG, mu_e)

    @raises(ValueError)
    def test_constrain_xx_degenerate(self):
        self.check('mu',
                   0,
                   Q_lab=x,
                   n_lab=x,
                   Q_phi=x,
                   n_phi=x,
                   phi_e=0,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_mu_0(self):
        raise SkipTest()
        self.check('mu',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_mu_10(self):
        raise SkipTest()
        self.check('mu',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=-90,
                   chi_e=10,
                   eta_e=-90,
                   mu_e=10)

    def test_constrain_mu_n10(self):
        raise SkipTest()
        self.check('mu',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=90,
                   chi_e=10,
                   eta_e=90,
                   mu_e=-10)

    def test_constrain_eta_10_wasfailing(self):
        # Required the choice of a different equation
        self.check('eta',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=-10,
                   chi_e=0,
                   eta_e=10,
                   mu_e=0)

    def test_constrain_eta_n10(self):
        self.check('eta',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=10,
                   chi_e=0,
                   eta_e=-10,
                   mu_e=0)

    def test_constrain_eta_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('eta',
                   20,
                   Q_lab=Q_lab,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=0,
                   eta_e=20,
                   mu_e=0)

    @raises(ValueError)
    def test_constrain_chi_0_degenerate(self):
        self.check('chi',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_chi_10(self):
        self.check('chi',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=-90,
                   chi_e=10,
                   eta_e=90,
                   mu_e=-10)

    def test_constrain_chi_90(self):
        # mu is off by 180, but youcalc tries +-x and 180+-x anyway
        raise SkipTest()
        self.check('chi',
                   90,
                   Q_lab=z * (-1),
                   n_lab=x,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=90,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_phi_0(self):
        self.check('phi',
                   0,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=0,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)

    def test_constrain_phi_10(self):
        self.check('phi',
                   10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=10,
                   chi_e=0,
                   eta_e=-10,
                   mu_e=0)

    def test_constrain_phi_n10(self):
        self.check('phi',
                   -10,
                   Q_lab=x,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=-10,
                   chi_e=0,
                   eta_e=10,
                   mu_e=0)

    def test_constrain_phi_20_with_theta_20(self):
        theta = 20 * TORAD
        Q_lab = matrix([[cos(theta)], [-sin(theta)], [0]])
        self.check('phi',
                   20,
                   Q_lab=Q_lab,
                   n_lab=z,
                   Q_phi=x,
                   n_phi=z,
                   phi_e=20,
                   chi_e=0,
                   eta_e=0,
                   mu_e=0)