-
Notifications
You must be signed in to change notification settings - Fork 0
/
positions.py
49 lines (40 loc) · 1.7 KB
/
positions.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
import ephem
import datetime
from skyfield.api import Topos, load
def identify_celestial_objects(latitude, longitude, date_time=None):
observer = ephem.Observer()
observer.lat = str(latitude)
observer.lon = str(longitude)
if date_time is None:
observer.date = datetime.datetime.utcnow()
else:
observer.date = date_time
sun = ephem.Sun(observer)
moon = ephem.Moon(observer)
planets = {
"Mercury": ephem.Mercury(observer),
"Venus": ephem.Venus(observer),
"Mars": ephem.Mars(observer),
"Jupiter": ephem.Jupiter(observer),
"Saturn": ephem.Saturn(observer),
"Uranus": ephem.Uranus(observer),
"Neptune": ephem.Neptune(observer)
}
# Create a list of celestial objects including the Sun, Moon, and planets
celestial_objects = [(sun, "Sun"), (moon, "Moon")]
for planet_name, planet in planets.items():
celestial_objects.append((planet, planet_name))
# Sort the celestial objects based on their altitude (angle above the horizon)
celestial_objects.sort(reverse=True, key=lambda x: x[0].alt)
# Display the sorted celestial objects
for obj, name in celestial_objects:
print(f"{name}: Altitude = {obj.alt}, Azimuth = {obj.az}")
if __name__ == "__main__":
user_latitude = float(input("Enter your latitude (degrees): "))
user_longitude = float(input("Enter your longitude (degrees): "))
user_date_time = input("Enter date and time (YYYY/MM/DD HH:MM:SS) or press Enter for current time: ")
if user_date_time:
user_date_time = ephem.Date(user_date_time)
else:
user_date_time = None
identify_celestial_objects(user_latitude, user_longitude, user_date_time)