Last active
October 18, 2025 19:28
-
-
Save tstarling/5e89bb970f8ab93f6e46dd8d0dd23370 to your computer and use it in GitHub Desktop.
sun-earth-relative-size.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| from skyfield import almanac | |
| from skyfield.api import Angle, load | |
| from skyfield.toposlib import wgs84 | |
| from skyfield.units import Distance | |
| from zoneinfo import ZoneInfo | |
| ts = load.timescale() | |
| eph = load('de440.bsp') | |
| earth = eph['earth'] | |
| moon = eph['moon'] | |
| sun = eph['sun'] | |
| zion = earth + wgs84.latlon(latitude_degrees=42.47, longitude_degrees=-87.868611, elevation_m=211) | |
| moon_radius = Distance(km=1737.4) | |
| sun_radius = Distance(km=695700) | |
| start = ts.utc(2025, 10, 1) | |
| end = ts.utc(2030,10, 1) | |
| tz = ZoneInfo("America/Chicago") | |
| def get_diameter(body, radius, time): | |
| distance = zion.at(time).observe(body).apparent().radec()[2] | |
| return Angle(radians=math.atan(radius.km / distance.km) * 2.0) | |
| print("Time,Moon,Sun") | |
| times, phases = almanac.find_discrete(start, end, almanac.moon_phases(eph)) | |
| for i, t in enumerate(times): | |
| if (phases[i] != 2): | |
| continue | |
| midday = almanac.find_transits(zion, sun, t - 1, t)[0] | |
| midnight = midday + 0.5 | |
| ts = midnight.astimezone(tz).strftime("%Y-%m-%d %H:%M") | |
| moon_diameter = get_diameter(moon, moon_radius, midnight).arcminutes() | |
| sun_diameter = get_diameter(sun, sun_radius, midnight).arcminutes() | |
| print(f"{ts},{moon_diameter},{sun_diameter}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment