-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
37 lines (30 loc) · 1.2 KB
/
utils.py
File metadata and controls
37 lines (30 loc) · 1.2 KB
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
from datetime import date as Date
from ephem import Moon, Mercury, Venus, Sun, Mars, Jupiter, Saturn, Uranus, Neptune
# Constants both for Flask and __main__.py
DEFAULT_NUM_DAYS = 1000
MAX_NUM_DAYS = 1000
DEFAULT_INTERVAL = 5
MAX_INTERVAL = 20
# Ephem planet classes
PLANETS = Moon(), Mercury(), Venus(), Sun(), Mars(), Jupiter(), Saturn(), Uranus(), Neptune()
def solar_system_json(date: Date) -> dict:
"""Generate JSON data for the solar system at a given date."""
data = {"date": date.isoformat(), "planets": []}
for radius, planet in enumerate(PLANETS):
planet.compute(date)
if planet.name == "Sun":
heliocentric_label = "Earth"
elif planet.name == "Moon":
heliocentric_label = "Sun"
else:
heliocentric_label = planet.name
data["planets"].append({
"name": planet.name,
"geocentric_label": planet.name,
"heliocentric_label": heliocentric_label,
"radius": radius,
"geo_radius": 0.5 if planet.name == "Moon" else radius,
"hlon": round(planet.hlon, 2), # Heliocentric longitude
"ra": round(planet.ra, 2) # Right ascension
})
return data