Skip to content

Instantly share code, notes, and snippets.

@a10y
Created March 31, 2024 00:50
Show Gist options
  • Save a10y/71a087897c5727754224089f268bf39d to your computer and use it in GitHub Desktop.
Save a10y/71a087897c5727754224089f268bf39d to your computer and use it in GitHub Desktop.
Marimo notebook of 2024 Solar Eclipse
import marimo
__generated_with = "0.1.76"
app = marimo.App()
@app.cell
def __():
from astropy.time import Time
from astropy.coordinates import EarthLocation, get_sun, get_moon, AltAz
return AltAz, EarthLocation, Time, get_moon, get_sun
@app.cell
def __(EarthLocation):
# Elevations were found using the API at open-elevation.com
# which gives us HAE in meters.
VIEWING_LOCS = [
# North of the marina, near "Urban Reserve"
# 44.48601606967214, -73.22778890703097
EarthLocation.from_geodetic(
lat=44.48601606967214,
lon=-73.22778890703097,
height=32,
),
# South Burlington, off of Shelburne Rd.
# 44.40584481187132, -73.21991070646659
EarthLocation.from_geodetic(
lat=44.40584481187132, lon=-73.21991070646659, height=32
),
# Near Switchback Brewing
# 44.463173392587, -73.22028440802492
EarthLocation.from_geodetic(
lat=44.463173392587, lon=-73.22028440802492, height=32
),
# Grand Isle State Park Beach
# 44.690602782899205, -73.28958965559401
EarthLocation.from_geodetic(
lat=44.690602782899205, lon=-73.28958965559401, height=36
),
]
return VIEWING_LOCS,
@app.cell
def __(AltAz, Time, VIEWING_LOCS, get_moon, get_sun):
from astropy import units as u
# Setup our simulation
START_TIME = Time(val="2024-04-08T19:26:08Z")
def get_total_eclipse_seconds(view_loc):
import numpy as np
from astropy import units as u
eclipse_seconds = 0
eclipse_start = None
eclipse_end = None
for i in range(200):
time = START_TIME + (i * u.s)
sun_pos = get_sun(time).transform_to(
AltAz(obstime=time, location=view_loc)
)
moon_pos = get_moon(time).transform_to(
AltAz(obstime=time, location=view_loc)
)
sun = [sun_pos.alt.degree, sun_pos.az.degree]
moon = [moon_pos.alt.degree, moon_pos.az.degree]
if np.allclose(sun, moon, atol=0.01):
eclipse_seconds += 1
if eclipse_start is None:
eclipse_start = time
else:
if eclipse_start is not None:
eclipse_end = time
return (eclipse_start, eclipse_end, eclipse_seconds)
return (eclipse_start, time, eclipse_seconds)
utc_off = 4 * u.h
print("BEGIN ECLIPSE SIMULATION")
outputs = []
for i, viewloc in enumerate(VIEWING_LOCS):
eclipse_start, eclipse_end, eclipse_secs = get_total_eclipse_seconds(
viewloc
)
outputs.append(
{
"location": "Location {}".format(i),
"eclipse_begin": "{}".format(eclipse_start - utc_off),
"eclipse_end": "{}".format(eclipse_end - utc_off),
"eclipse_seconds": eclipse_secs,
}
)
print(
f"LOCATION {i+1}: START={eclipse_start - utc_off} END={eclipse_end - utc_off} TOTAL_SECONDS={eclipse_secs}"
)
print("SIMULATION COMPLETE")
outputs
return (
START_TIME,
eclipse_end,
eclipse_secs,
eclipse_start,
get_total_eclipse_seconds,
i,
outputs,
u,
utc_off,
viewloc,
)
@app.cell
def __(outputs):
import marimo as mo
mo.ui.table(outputs)
return mo,
if __name__ == "__main__":
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment