def asB(self, wavelength=None): if wavelength is None: wavelength = session.instrument.wavelength or None if not wavelength: raise NicosError( "Cannot perform conversion without knowing wavelength") cosx = np.sqrt(self.c[0]**2 + self.c[1]**2) chi = np.arctan2(self.c[2], cosx) if cosx < 1.0E-6: phi = 0.0 else: try: phi = np.arctan2(-self.c[0], self.c[1]) except ValueError: print("Oops: ", self) phi = 0 sinx = np.sqrt(cosx**2 + self.c[2]**2) * wavelength / 2.0 if sinx >= 1.0: theta = self.signtheta * np.pi / 2.0 else: theta = self.signtheta * np.arcsin(sinx) if self.signtheta < 0: phi = phi + np.deg2rad(180) chi = -chi return PositionFactory(ptype='br', theta=normalangle(theta), phi=normalangle(phi), chi=normalangle(chi), psi=self.psi)
def asB(self, _wavelength=None): """ Conversion. Part of Position subclass protocol. """ sineps = np.sin(self.omega - self.theta) coseps = np.cos(self.omega - self.theta) if coseps < 0: signcb = -1.0 else: signcb = 1.0 coschi = np.cos(self.chi) sinchi = np.sin(self.chi) if self.theta < 0: signth = -1.0 else: signth = 1.0 sinchib = coseps * sinchi coschib = signcb * np.sqrt(coschi**2 + (sinchi * sineps)**2) chib = np.arctan2(sinchib, coschib) if sineps == 0 and coschi == 0: phib = 0 sinpsi = -signcb * np.sin(self.phi) * sinchi cospsi = signth * signcb * np.cos(self.phi) * coseps else: sinphi = -signcb * sineps cosphi = signcb * coseps * coschi phib = self.phi - np.arctan2(sinphi, cosphi) sinpsi = sinchi * sineps cospsi = signth * coschi psi = np.arctan2(sinpsi, cospsi) return PositionFactory(ptype='br', theta=self.theta, phi=normalangle(phib), chi=normalangle(chib), psi=normalangle(psi))
def asK(self, _wavelength=None): """ Conversion. Part of Position subclass protocol. """ if not hasattr(self, 'alpha'): self.alpha = np.deg2rad(60) # TODO: get from experiment? self.kappamax = np.deg2rad(180) si = np.sin(0.5 * self.chi) co = np.sin(self.alpha)**2 - si**2 con3 = np.cos(self.kappamax / 2.0)**2 * np.sin(self.alpha)**2 if con3 > co: self.log.warning("Chi can not be reached on this hardware") kappa = np.deg2rad(180.0) omega = np.deg2rad(90.0) # raise error("Chi high") co = con3 co = np.sqrt(co) kappa = 2.0 * np.arctan2(si, co) si = si * np.cos(self.alpha) omega = np.arctan2(si, co) else: co = np.sqrt(co) kappa = 2.0 * np.arctan2(si, co) si = si * np.cos(self.alpha) omega = np.arctan2(si, co) phi = self.phi - omega omega = -omega + self.omega return PositionFactory(ptype='kr', theta=self.theta, omega=normalangle(omega), kappa=normalangle(kappa), phi=normalangle(phi))
def Alternate(self): """ The alternate N-position that has the same orientation. """ return PositionFactory(ptype='nr', omega=normalangle(self.omega + np.pi), theta=self.theta, chi=-self.chi, phi=normalangle(self.phi + np.pi))
def __init__(self, p=None, theta=None, ttheta=None, omega=None, kappa=None, phi=None, _rad=False): """ Constructor. Part of Position subclass protocol. """ PositionBase.__init__(self) self.alpha = np.deg2rad(60) # TODO: get from experiment? if p: self.theta = p.theta self.omega = p.omega self.kappa = p.kappa self.phi = normalangle(p.phi) else: if ttheta is not None: theta = ttheta / 2. self.theta = self._r2d(theta, _rad) self.omega = self._r2d(omega, _rad) self.kappa = self._r2d(kappa, _rad) self.phi = self._r2d(phi, _rad)
def asE(self, _wavelength=None): """ Conversion. Part of Position subclass protocol. """ sinpsi = np.sin(self.psi) cospsi = np.cos(self.psi) signth = sign(np.sin(self.theta)) sinchb = np.sin(self.chi) coschb = np.cos(self.chi) signcb = sign(coschb) sinche = signcb * sign(sinchb) * np.sqrt((cospsi * sinchb) ** 2 + sinpsi ** 2) cosche = signth * signcb * cospsi * coschb try: chi = np.arctan2(sinche, cosche) except ValueError: self.log.warning("B-E Chi problem: %r", self) chi = 0.0 if sinchb == 0 and sinpsi == 0: omega = self.theta - 90.0 * (signcb - 1.0) sinphe = -np.sin(omega - self.theta) * coschb cosphe = signth * signcb * np.cos(omega - self.theta) * cospsi else: signch = sign(np.sin(chi)) sinome = signch * signcb * coschb * sinpsi cosome = signch * sinchb try: omega = np.arctan2(sinome, cosome) + self.theta except ValueError: self.log.warning("B-E Omega problem: %r", self) omega = 0.0 sinphe = -signch * signcb * sinpsi cosphe = signch * signth * signcb * sinchb * cospsi try: phi = np.arctan2(sinphe, cosphe) + self.phi except ValueError: self.log.warning("B-E Phi problem: %r", self) phi = 0.0 return PositionFactory(ptype='er', theta=self.theta, omega=normalangle(omega), chi=normalangle(chi), phi=normalangle(phi))
def asL(self, wavelength=None): """ Conversion. Part of Position subclass protocol. """ if wavelength is None: wavelength = session.instrument.wavelength or None if not wavelength: raise NicosError( "Cannot perform conversion without knowing wavelength") cxy = np.sqrt(self.c[0]**2 + self.c[1]**2) cabs2 = self.c[0]**2 + self.c[1]**2 + self.c[2]**2 theta = np.arcsin(np.sqrt(cabs2) * wavelength / 2.0) nu = np.arcsin(wavelength * self.c[2]) gamma = np.arccos(np.cos(2 * theta) / np.cos(nu)) * self.signtheta omega = -np.arctan2(self.c[1], self.c[0]) + \ self.signtheta * np.arcsin(cabs2/cxy * wavelength / 2.0) - np.pi/2 return PositionFactory(ptype='lr', signtheta=self.signtheta, gamma=normalangle(gamma), omega=normalangle(omega), nu=normalangle(nu), psi=self.psi)
def asE(self, _wavelength=None): """ Conversion. Part of Position subclass protocol. """ if self.kappa is None: print("DBG> Convert incomplete kappa to eulerian!") return PositionFactory(ptype='e', theta=self.theta) halfkappa = 0.5 * self.kappa # Modulo 360 while halfkappa > np.pi / 2: halfkappa -= np.pi while halfkappa < -np.pi / 2: halfkappa += np.pi sinx = np.cos(self.alpha) * np.sin(halfkappa) cosx = np.cos(halfkappa) x = np.arctan2(sinx, cosx) omegae = self.omega + x phie = self.phi + x sinc = np.sin(self.alpha) * np.sin(halfkappa) chie = 2.0 * np.arcsin(sinc) return PositionFactory(ptype='er', theta=self.theta, omega=normalangle(omegae), chi=normalangle(chie), phi=normalangle(phie))
def asE(self, _wavelength=None): """ Conversion. Part of Position subclass protocol. """ if self.omega is not None: om = np.deg2rad(180) - self.omega else: om = None if self.phi is not None: ph = normalangle(self.phi + np.deg2rad(90)) else: ph = None if self.theta is not None: th = -self.theta else: th = None return PositionFactory(ptype='er', theta=th, chi=self.chi, phi=ph, omega=om)