forked from zkbt/zachopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspherical.py
23 lines (21 loc) · 968 Bytes
/
spherical.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
'''Some spherical coordinate tools.'''
import numpy as np
import astropy.coordinates
# use matrices to handle the rotations due to jitter
def rx(theta):
return np.mat([[1, 0, 0], [0, np.cos(theta), -np.sin(theta)], [0, np.sin(theta), np.cos(theta)]])
def ry(theta):
return np.mat([[np.cos(theta), 0, np.sin(theta)],[0, 1, 0], [-np.sin(theta), 0, np.cos(theta)]])
def rz(theta):
return np.mat([[np.cos(theta), -np.sin(theta), 0],[np.sin(theta), np.cos(theta), 0], [0, 0, 1]])
def rotate(ra, dec, x, y):
cart = np.transpose(np.mat(astropy.coordinates.spherical_to_cartesian(1,dec*np.pi/180, ra*np.pi/180)))
#assert(x==0.0)
rotated = rx(x*np.pi/180)*ry(y*np.pi/180)*cart
#print cart
#print ' --> '
#print rotated
sphe = np.array(astropy.coordinates.cartesian_to_spherical(rotated[0], rotated[1], rotated[2]))*180/np.pi
sphe = sphe.squeeze()
#print " {0:f}, {1:f} --> {2:f},{3:f}".format(ra, dec, sphe[2], sphe[1])
return sphe[2], sphe[1]