def EulerAngles(equinox, targetEquinox, coord=None, rot=None): #Return the Euler angles (passive Z(-Y)X) to go from equinox to targetEquinox in degrees #Rot is an extra rotation, after precessing #If coord is provided, the inverse coordinate transformation is applied first, then the precession, then the direct coordinate transformation, and then the rotation is calculated deg=apUnits.degree; #Unit vector in current epoch x0=array([1,0,0]) y0=array([0,1,0]) z0=array([0,0,1]) #Go to original coordinates rCoord=Rotator(coord=coord) x=rCoord.I(x0) y=rCoord.I(y0) z=rCoord.I(z0) #Change to longitude and latitude xLonLat=vec2dir(x,lonlat=True) yLonLat=vec2dir(y,lonlat=True) zLonLat=vec2dir(z,lonlat=True) #Put them in astropy xAP=SkyCoord(ra=xLonLat[0]*deg,dec=xLonLat[1]*deg,frame=FK5(equinox=equinox)) yAP=SkyCoord(ra=yLonLat[0]*deg,dec=yLonLat[1]*deg,frame=FK5(equinox=equinox)) zAP=SkyCoord(ra=zLonLat[0]*deg,dec=zLonLat[1]*deg,frame=FK5(equinox=equinox)) #Precess xpAP=xAP.transform_to(FK5(equinox=targetEquinox)) ypAP=yAP.transform_to(FK5(equinox=targetEquinox)) zpAP=zAP.transform_to(FK5(equinox=targetEquinox)) #Go back to vectors xp=dir2vec(theta=xpAP.ra.degree, phi=xpAP.dec.degree, lonlat=True) yp=dir2vec(theta=ypAP.ra.degree, phi=ypAP.dec.degree, lonlat=True) zp=dir2vec(theta=zpAP.ra.degree, phi=zpAP.dec.degree, lonlat=True) #Go back to target coordinates xp=rCoord(xp) yp=rCoord(yp) zp=rCoord(zp) #Perform final rotation from argument rot rf = Rotator(rot=rot) xp=array(rf(xp)) yp=array(rf(yp)) zp=array(rf(zp)) #Get Euler angles if fabs(zp[0])==1: alpha=0.0 beta=zp[0]*pi/2 gamma=arctan2(xp[1],xp[2]) else: alpha=arctan2(yp[0],xp[0]) beta=arcsin(zp[0]) gamma=arctan2(zp[1],zp[2]) return (rad2deg(alpha),rad2deg(beta),rad2deg(gamma))
def xy2vec(self, x, y=None, direct=False): if y is None: x,y = np.asarray(x) else: x,y = np.asarray(x),np.asarray(y) flip = self._flip theta = pi/2.-y*dtor # convert in radian phi = flip*x*dtor # convert in radian # dir2vec does not support 2d arrays, so first use flatten and then # reshape back to previous shape if not direct: vec = self.rotator.I(R.dir2vec(theta.flatten(),phi.flatten())) else: vec = R.dir2vec(theta.flatten(),phi.flatten()) vec = [v.reshape(theta.shape) for v in vec] return vec
def xy2vec(self, x, y=None, direct=False): if y is None: x, y = np.asarray(x) else: x, y = np.asarray(x), np.asarray(y) flip = self._flip theta = pi / 2. - y * dtor # convert in radian phi = flip * x * dtor # convert in radian # dir2vec does not support 2d arrays, so first use flatten and then # reshape back to previous shape if not direct: vec = self.rotator.I(R.dir2vec(theta.flatten(), phi.flatten())) else: vec = R.dir2vec(theta.flatten(), phi.flatten()) vec = [v.reshape(theta.shape) for v in vec] return vec
def precess(ra,dec,equinox,targetEquinox): #Function to check that the above one actually works vec=dir2vec(ra,dec,lonlat=True) R=Rotator(rot=EulerAngles(equinox,targetEquinox)) vec=R(vec) [oRA,oDec]=vec2dir(vec,lonlat=True) while oRA<0: oRA = oRA+360 return (oRA,oDec)
def ang2xy(self, theta, phi=None, lonlat=False, direct=False): return self.vec2xy(R.dir2vec(theta,phi,lonlat=lonlat),direct=direct)
def ang2xy(self, theta, phi=None, lonlat=False, direct=False): return self.vec2xy(R.dir2vec(theta, phi, lonlat=lonlat), direct=direct)