Skip to content

Instantly share code, notes, and snippets.

@dougneal
Created August 12, 2026 13:12
Show Gist options
  • Select an option

  • Save dougneal/37c989d3e4bf12d8814016c328473ee2 to your computer and use it in GitHub Desktop.

Select an option

Save dougneal/37c989d3e4bf12d8814016c328473ee2 to your computer and use it in GitHub Desktop.
Visualise the sun azimuth during the eclipse
from pysolar.solar import get_azimuth, get_altitude
import datetime
import json
import math
from datetime import timedelta
from zoneinfo import ZoneInfo
LAT = 51.5649288
LON = 0.0172429
ZONE_INFO = ZoneInfo("Europe/London")
ECL_START = datetime.datetime(2026, 8, 12, 18, tzinfo=ZONE_INFO)
ECL_END = datetime.datetime(2026, 8, 12, 21, tzinfo=ZONE_INFO)
STEP = timedelta(minutes=5)
LINE_LENGTH_METRES = 100.0
OUTPUT_PATH = "sun_position.geojson"
METRES_PER_DEGREE_LATITUDE = 111_320.0
def destination_point(lat, lon, azimuth_degrees, distance_metres):
"""Point at the given distance and bearing from (lat, lon).
Uses a flat-earth approximation, which is accurate to well under
a metre at the distances these lines span.
"""
azimuth_radians = math.radians(azimuth_degrees)
delta_lat = distance_metres * math.cos(azimuth_radians) / METRES_PER_DEGREE_LATITUDE
delta_lon = (
distance_metres
* math.sin(azimuth_radians)
/ (METRES_PER_DEGREE_LATITUDE * math.cos(math.radians(lat)))
)
return lat + delta_lat, lon + delta_lon
def time_range(start, end, step):
current = start
while current <= end:
yield current
current += step
features = []
for steptime in time_range(ECL_START, ECL_END, STEP):
azimuth = get_azimuth(LAT, LON, steptime)
elevation = get_altitude(LAT, LON, steptime)
print(f"time={steptime} azimuth={azimuth} elevation={elevation}")
if elevation <= 0:
continue
end_lat, end_lon = destination_point(LAT, LON, azimuth, LINE_LENGTH_METRES)
features.append(
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [[LON, LAT], [end_lon, end_lat]],
},
"properties": {
"time": steptime.isoformat(),
"azimuth": azimuth,
"elevation": elevation,
},
}
)
with open(OUTPUT_PATH, "w") as output_file:
json.dump(
{"type": "FeatureCollection", "features": features}, output_file, indent=2
)
print(f"Wrote {len(features)} features to {OUTPUT_PATH}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment