def skyToPix(self, ra_deg, dec_deg): sin = np.sin cos = np.cos #Parse inputs and allocate space for outputs ra_deg, dec_deg = self.parseInputs(ra_deg, dec_deg) long_deg = ra_deg * 0 lat_deg = long_deg * 0 #Get longitude and latitude relative to defined origin. for i in range(len(ra_deg)): vec = rotate.vecFromRaDec(ra_deg[i], dec_deg[i]) aVec = np.dot( self.Rmatrix, vec) long_deg[i], lat_deg[i] = rotate.raDecFromVec(aVec) long_deg = np.fmod(long_deg + 180, 360.) long_rad = np.radians(long_deg) - np.pi #[-pi,pi] lat_rad = np.radians(lat_deg) #long_rad = np.fmod(long_rad+ np.pi, 2*np.pi) gamma = 1 + cos(lat_rad)* cos(long_rad/2.) gamma = np.sqrt(2/gamma) x = -2*gamma*cos(lat_rad)*sin(long_rad/2) y = gamma*sin(lat_rad) return x, y
def skyToPix(self, ra_deg, dec_deg): sin = np.sin cos = np.cos #Parse inputs and allocate space for outputs ra_deg, dec_deg = self.parseInputs(ra_deg, dec_deg) long_deg = ra_deg * 0 lat_deg = long_deg * 0 #Get longitude and latitude relative to defined origin. for i in range(len(ra_deg)): vec = rotate.vecFromRaDec(ra_deg[i], dec_deg[i]) aVec = np.dot(self.Rmatrix, vec) long_deg[i], lat_deg[i] = rotate.raDecFromVec(aVec) long_deg = np.fmod(long_deg + 180, 360.) long_rad = np.radians(long_deg) - np.pi #[-pi,pi] lat_rad = np.radians(lat_deg) #long_rad = np.fmod(long_rad+ np.pi, 2*np.pi) gamma = 1 + cos(lat_rad) * cos(long_rad / 2.) gamma = np.sqrt(2 / gamma) x = -2 * gamma * cos(lat_rad) * sin(long_rad / 2) y = gamma * sin(lat_rad) return x, y
def __init__(self, ra0_deg, dec0_deg): self.ra0_deg = ra0_deg self.dec0_deg = dec0_deg #Construct rotation matrix used to convert ra/dec into #angle relative to tangent point Rdec = rotate.declinationRotationMatrix(-self.dec0_deg) Rra = rotate.rightAscensionRotationMatrix(-self.ra0_deg) self.Rmatrix = np.dot(Rdec, Rra) #Check I created the matrix correctly. origin = rotate.vecFromRaDec(self.ra0_deg, self.dec0_deg) origin = np.dot(self.Rmatrix, origin) assert (np.fabs(origin[0] - 1) < 1e-9) assert (np.fabs(origin[1]) < 1e-9) assert (np.fabs(origin[2]) < 1e-9)
def skyToPix(self, ra_deg, dec_deg): ra_deg, dec_deg = self.parseInputs(ra_deg, dec_deg) #Transform ra dec into angle away from tangent point #using the rotation matrix theta_rad= np.empty( (len(ra_deg),) ) phi_rad = theta_rad * 0 R = self.Rmatrix for i in range(len(ra_deg)): #Convert the ra/dec to a vector, then rotate so #that the tangent point is at [1,0,0]. Then pull out #the angle relative to the x-axis, and the angle #around the y-z plane. #@TODO: Can I make this faster with dot products? vec =rotate.vecFromRaDec(ra_deg[i], dec_deg[i]) aVec = np.dot(R, vec) #aVec = (sint, cost*cosp, cost*sinp) sint = aVec[0] cost = np.hypot(aVec[1], aVec[2]) theta = np.arctan2(sint, cost) cost = np.cos(theta) cosp = aVec[1] / cost sinp = aVec[2] / cost phi = np.arctan2(sinp, cosp) if phi < 0: phi += 2*np.pi if phi > 2*np.pi: phi -= 2*np.pi #Just to be explicit theta_rad[i] = theta phi_rad[i] = phi #Project onto tangent plane #theta_rad = np.pi/2. - theta_rad r = 1/(np.tan(theta_rad) + 1e-10) #Prevent division by zero x = r * np.cos(phi_rad) y = r * np.sin(phi_rad) #print x, y return x, y
def __init__(self, ra0_deg, dec0_deg): self.ra0_deg = ra0_deg self.dec0_deg = dec0_deg #Construct rotation matrix used to convert ra/dec into #angle relative to tangent point Rdec = rotate.declinationRotationMatrix(-self.dec0_deg) Rra = rotate.rightAscensionRotationMatrix(-self.ra0_deg) self.Rmatrix = np.dot(Rdec, Rra) #Check I created the matrix correctly. origin = rotate.vecFromRaDec(self.ra0_deg, self.dec0_deg) origin = np.dot(self.Rmatrix, origin) assert( np.fabs(origin[0] -1 ) < 1e-9) assert( np.fabs(origin[1]) < 1e-9) assert( np.fabs(origin[2]) < 1e-9)
def skyToPix(self, ra_deg, dec_deg): ra_deg, dec_deg = self.parseInputs(ra_deg, dec_deg) #Transform ra dec into angle away from tangent point #using the rotation matrix theta_rad = np.empty((len(ra_deg), )) phi_rad = theta_rad * 0 R = self.Rmatrix for i in range(len(ra_deg)): #Convert the ra/dec to a vector, then rotate so #that the tangent point is at [1,0,0]. Then pull out #the angle relative to the x-axis, and the angle #around the y-z plane. #@TODO: Can I make this faster with dot products? vec = rotate.vecFromRaDec(ra_deg[i], dec_deg[i]) aVec = np.dot(R, vec) #aVec = (sint, cost*cosp, cost*sinp) sint = aVec[0] cost = np.hypot(aVec[1], aVec[2]) theta = np.arctan2(sint, cost) cost = np.cos(theta) cosp = aVec[1] / cost sinp = aVec[2] / cost phi = np.arctan2(sinp, cosp) if phi < 0: phi += 2 * np.pi if phi > 2 * np.pi: phi -= 2 * np.pi #Just to be explicit theta_rad[i] = theta phi_rad[i] = phi #Project onto tangent plane #theta_rad = np.pi/2. - theta_rad r = 1 / (np.tan(theta_rad) + 1e-10) #Prevent division by zero x = r * np.cos(phi_rad) y = r * np.sin(phi_rad) #print x, y return x, y