-
Notifications
You must be signed in to change notification settings - Fork 2
/
deg2str.py
41 lines (39 loc) · 1.25 KB
/
deg2str.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
39
40
41
from numpy import sign
def deg2str(degrees,sp=':',ra=1,dec=0,prec=2):
"""Convert decimal degress to sexagecimal expression.
Inseok Song (2007)
>>> deg2str(123.4567)
Out: '08:13:49.61'
>>> deg2str(123.4567,prec=3)
Out: '08:13:49.608'
>>> deg2str(123.4567,prec=3,sp=' ')
Out: '08 13 49.608'
>>> deg2str(-23.4567,dec=1)
Out: '-23:27.24.12'
...
"""
if (ra & ~dec):
if ( (degrees < 0.0) or (degrees > 360.0) ):
retstr = ' 0>RA<360 '
return(retstr)
formatstr = '%02d%s%02d%s%0'+'%1d.%1df' % (prec+3,prec)
degrees = degrees/15.0
rah = int(degrees)
ram = int((degrees-rah)*60.0)
ras = ((degrees - rah)*60 - ram)*60.0
retstr = formatstr % (rah,sp,ram,sp,ras)
elif (dec):
if (degrees >= 0):
mysign='+'
else:
mysign='-'
if (abs(degrees) > 90):
retstr = ' |DEC|>90'
return(retstr)
formatstr = '%c%02.2d%s%02d%s%0'+'%1d.%1df' % (prec+3,prec)
degrees = abs(degrees)
ded = int(degrees)
dem = int((degrees-ded)*60.0)
des = ((degrees - ded)*60 - dem)*60.0
retstr = formatstr % (mysign,ded,sp,dem,sp,des)
return retstr