-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheclipse-tell.py
executable file
·87 lines (70 loc) · 2.11 KB
/
eclipse-tell.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python
'''
eclipse-tell.py
takes the latitude, longitude, and time of the observer and determine
if an eclipse is occuring.
'''
import ephem
import re
import sys
import math
from datetime import datetime, timedelta
from dateutil import parser
rad2deg = 180/math.pi
deg2rad = math.pi/180
def dms2dd(degrees, minutes, seconds, sign=1):
dd = float(degrees) + float(minutes)/60 + float(seconds)/(60*60);
dd *= sign
return dd;
def parse_dms(dms):
parts = re.split('[^\d]+', dms)
sign = -1 if re.search('[swSW]', dms) else 1
deg = dms2dd(parts[0], parts[1], parts[2], sign)
return deg
try:
latinput = sys.argv[1]
except IndexError:
latinput = input("latitude: ")
try:
loninput = sys.argv[2]
except IndexError:
loninput = input("longitude: ")
try:
timeinput = sys.argv[3]
except IndexError:
timeinput = input("time: ")
latitude = parse_dms(latinput)
longitude = parse_dms(loninput)
time = parser.parse(timeinput)
print("latitude (degrees): ", latitude)
print("longitude (degrees): ", longitude)
print("time: ", time)
observer = ephem.Observer()
observer.lon = longitude * deg2rad
observer.lat = latitude * deg2rad
observer.date = time
moon = ephem.Moon(observer)
sun = ephem.Sun(observer)
moondiameter = moon.size / 3600
sundiameter = sun.size / 3600
moonradius = moondiameter / 2
sunradius = sundiameter / 2
separation = abs(ephem.separation(moon, sun)) * rad2deg
print("moon angular size (degrees): ", moondiameter)
print("sun angular size (degrees): ", sundiameter)
print("sun altitude (degrees): ", sun.alt * rad2deg )
print("sun azimuth (degrees): ", sun.az * rad2deg)
print("sun moon separation (degrees)", separation)
if sun.alt < 0:
type = "sun is below the horizon, no solar eclipse is possible"
else:
if separation < abs(moonradius - sunradius): # total or annular
if sunradius > moonradius:
type = "annular solar eclipse"
else:
type = "total solar eclipse"
elif separation < moonradius + sunradius:
type = "partial solar eclipse"
else:
type = "no eclipse is occuring"
print("type of eclipse: ", type)