-
Notifications
You must be signed in to change notification settings - Fork 0
/
cv_coord.py
38 lines (35 loc) · 878 Bytes
/
cv_coord.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import numpy
def cv_coord(a,b,c,fr=None,to=None,degr=False):
if degr:
degrad = numpy.deg2rad
raddeg = numpy.rad2deg
else:
degrad = lambda x: x
raddeg = lambda x: x
if fr=='sph':
cosa = numpy.cos(degrad(a))
sina = numpy.sin(degrad(a))
cosb = numpy.cos(degrad(b))
sinb = numpy.sin(degrad(b))
x=c*cosa*cosb
y=c*sina*cosb
z=c*sinb
elif fr=='rect':
x=a
y=b
z=c
elif fr is None:
raise Exception('You must specify the input coordinate system')
else:
raise Exception('Unknown input coordinate system')
if to=='rect':
return (x,y,z)
elif to=='sph':
ra = raddeg(numpy.arctan2(y,x))
dec = raddeg(numpy.arctan2(z,numpy.sqrt(x**2+y**2)))
rad = numpy.sqrt(x**2+y**2+z**2)
return (ra,dec,rad)
elif to is None:
raise Exception('You must specify the output coordinate system')
else:
raise Exception('Unknown output coordinate system')