def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print ('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal(hkl, hkl_expected, self.places, note="***Test (not diffcalc!) incorrect*** : the desired settings do not map to the target hkl") assert_second_dict_almost_in_first(virtual, virtual_expected)
def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print ('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal(hkl, hkl_expected, self.places) assert_second_dict_almost_in_first(virtual, virtual_expected)
def _check_hkl_to_angles(self, testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected={}): print ('_check_hkl_to_angles(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() pos, virtual = self.calc.hklToAngles(hkl[0], hkl[1], hkl[2], wavelength) assert_array_almost_equal(pos.totuple(), pos_expected.totuple(), self.places) assert_second_dict_almost_in_first(virtual, virtual_expected)
def check(self, name, value, theta, tau, psi_e, alpha_e, beta_e, places=7): # all in deg alpha, beta = self.calc._calc_remaining_reference_angles( name, value * TORAD, theta * TORAD, tau * TORAD) if alpha_e is not None: assert_almost_equal(alpha * TODEG, alpha_e, places) if beta_e is not None: assert_almost_equal(beta * TODEG, beta_e, places) psi_vals = list(self.calc._calc_psi(alpha, theta * TORAD, tau * TORAD)) if psi_e is not None: assert_array_almost_equal(sorted([v * TODEG for v in psi_vals]), sorted(psi_e)) for psi in psi_vals: print 'psi', psi * TODEG, ' alpha:', alpha * TODEG,\ ' beta:', beta * TODEG
def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal(hkl, hkl_expected, self.places) assert_second_dict_almost_in_first(virtual, virtual_expected)
def _check_hkl_to_angles(self, testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected={}): print('_check_hkl_to_angles(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() pos, virtual = self.calc.hklToAngles(hkl[0], hkl[1], hkl[2], wavelength) assert_array_almost_equal(pos.totuple(), pos_expected.totuple(), self.places) assert_second_dict_almost_in_first(virtual, virtual_expected)
def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal( hkl, hkl_expected, self.places, note= "***Test (not diffcalc!) incorrect*** : the desired settings do not map to the target hkl" ) assert_second_dict_almost_in_first(virtual, virtual_expected)
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 check(self, name, value, theta, delta_e, nu_e, qaz_e): # all in deg delta, nu, qaz = zip( *self.calc._calc_remaining_detector_angles(name, value * TORAD, theta * TORAD)) for delta_, nu_, qaz_ in zip(delta, nu, qaz): print 'delta:', delta_ * TODEG, ' nu:', nu_ * TODEG, ' qaz:', qaz_ * TODEG assert_array_almost_equal([v * TODEG for v in delta], delta_e) assert_array_almost_equal([v * TODEG for v in nu], nu_e) if qaz_e is not None: assert_array_almost_equal([v * TODEG for v in qaz], qaz_e)
def test_wrong_value(self): try: assert_array_almost_equal((3, 2, 1), (3, 2, 1.0000001)) assert False except AssertionError: pass
def test_wrong_length(self): try: assert_array_almost_equal((1, 2, 3), (1, 2)) assert False except AssertionError, e: eq_(e.args[0], '(1, 2, 3) != (1, 2) as lengths differ')
def test__passes(self): assert_array_almost_equal((1, 2, 3), (1.00000001, 2, 3.)) assert_array_almost_equal((1, 2, 3), (1.0000001, 2, 3.), 6) assert_array_almost_equal((1, 2, 3), [1, 2, 3]) assert_array_almost_equal((), ()) assert_array_almost_equal([], ())