Beispiel #1
0
def test_virtualgonios(session, tas):
    gx, gy = session.getDevice('sgx'), session.getDevice('sgy')
    v1, v2 = session.getDevice('vg1'), session.getDevice('vg2')

    # when psi0 = 0, gx == v1 and gy == v2
    tas._attached_cell.psi0 = 0
    gx.maw(0)
    gy.maw(0)
    assert v1.read(0) == 0
    assert v2.read(0) == 0
    gx.maw(2)
    assert v1.read(0) == approx(2)
    assert v2.read(0) == approx(0)
    gy.maw(1)
    assert v1.read(0) == approx(2)
    assert v2.read(0) == approx(1)

    v1.maw(0)
    v2.maw(1.3)
    assert gx.read(0) == approx(0)
    assert gy.read(0) == approx(1.3)

    # psi0 = 45deg
    tas._attached_cell.psi0 = 45
    gx.maw(0)
    gy.maw(0)
    assert v1.read(0) == 0
    assert v2.read(0) == 0
    v1.maw(4)
    assert gx.read(0) == approx(2 * sqrt(2), abs=5e-2)
    assert gy.read(0) == approx(2 * sqrt(2), abs=5e-2)

    # limits of sgx, sgy are +/- 5 deg
    v1.maw(7)
    assert raises(LimitError, v2.maw, 3)

    # make sure the calculations match intent
    D2R = pi / 180
    tas._attached_cell.psi0 = 64
    v1.maw(1.5)
    v2.maw(-2)

    # extract angles in radians
    psi = 64 * D2R
    x1 = 1.5 * D2R
    y1 = -2 * D2R
    x2 = gx.read(0) * D2R
    y2 = gy.read(0) * D2R

    # these two matrices should deliver the same rotation
    m1 = dot(Xrot(x1), Yrot(y1))
    m2 = dot(dot(Zrot(psi), Xrot(x2)), dot(Yrot(y2), Zrot(-psi)))
    assert allclose(m1, m2, atol=1e-3)
Beispiel #2
0
 def asG(self, _wavelength=None):
     """ Conversion. Part of Position subclass protocol.
     """
     return PositionFactory(ptype='gr',
                            theta=self.theta,
                            matrix=np.dot(
                                Zrot(self.omega),
                                np.dot(
                                    Yrot(-self.alpha),
                                    np.dot(
                                        Zrot(self.kappa),
                                        np.dot(Yrot(self.alpha),
                                               Zrot(self.phi))))))
Beispiel #3
0
 def asG(self, _wavelength=None):
     """ Conversion. Part of Position subclass protocol.
     """
     if self.theta > 0:
         S = 0
     else:
         S = np.pi
     if np.cos(self.chi) > 0:
         C = 0
     else:
         C = np.pi
     return PositionFactory(
         ptype='gr',
         theta=self.theta,
         matrix=np.dot(Zrot(self.theta),
                       np.dot(Xrot(S),
                              np.dot(Yrot(-self.psi),
                                     np.dot(Zrot(S + C),
                                            np.dot(Xrot(C),
                                                   np.dot(Xrot(self.chi),
                                                          Zrot(self.phi))))))))
Beispiel #4
0
def calcEsmeraldaRots(xrot, yrot, zrot):
    """Move goniometer to new position as specified by orienting angles.

    *x*,*y*,*z* Orienting angles as determined e.g. by Esmeralda
    """

    try:
        laue = session.getDevice('kappagon')
        cpos = laue.read().With(phi=0)
    except Exception:  # enables standalone testing
        cpos = PositionFactory('k', phi=0, kappa=0, omega=0, theta=0)
    ma = cpos.asG().matrix
    # note: internal coordinate system is different from Esmeralda:
    #  X_E = Y_int
    #  Y_E = -X_int
    #  Z_E = Z_int
    rx = Xrot(np.radians(yrot))
    ry = Yrot(np.radians(-xrot))
    rz = Zrot(np.radians(zrot))
    rotmat = np.dot(rz, np.dot(ry, rx))
    newmat = np.dot(ma, rotmat)
    npos = cpos.asG().With(matrix=newmat)
    return npos.asK()
Beispiel #5
0
 def Yrot(self, angle):
     """ Rotate 'angle' (clockwise) around the Y axis.
     """
     return self.With(matrix=np.dot(Yrot(angle), self.matrix))
Beispiel #6
0
 def get_new_cell(p):
     # reconstruct UB matrix
     Umat = Zrot(-p.phi).dot(Yrot(-p.theta)).dot(Xrot(-p.psi))
     Bmat = matrixfromcell(p.a, p.b, p.c, p.alpha, p.beta, p.gamma)
     return SXTalCell(Umat.dot(Bmat).T)