Skip to content

Commit

Permalink
Make example sunrise-sunset script 12 times faster
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon-rhodes committed Feb 7, 2024
1 parent 4f397d2 commit d1ad1f8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions examples/grand_canyon_daylight.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Runtime was around 1 minute 4 seconds under the old find-discrete
# regime; with the new find_risings() and find_settings() routines, this
# script now takes around 5 seconds. Nice.

from skyfield.api import load, wgs84
from skyfield import almanac

ts = load.timescale()
eph = load('de421.bsp')
grand_canyon_village = wgs84.latlon(+36.0544, -112.1401)
observer = eph['earth'] + grand_canyon_village
tz_hours = -7
start = ts.utc(1986, 1, 17, -tz_hours)
#end = ts.utc(1987, 7, 14, -tz_hours)
end = ts.utc(2022, 7, 14, -tz_hours)
ss = almanac.sunrise_sunset(eph, grand_canyon_village)
t, y = almanac.find_discrete(start, end, ss)
sunrises = t[::2]
sunsets = t[1::2]
sunrises, _ = almanac.find_risings(observer, eph['Sun'], start, end)
sunsets, _ = almanac.find_settings(observer, eph['Sun'], start, end)
lengths = sunsets - sunrises
print('date,hours_sunlight')
for ti, length in zip(sunrises, lengths):
Expand Down

0 comments on commit d1ad1f8

Please sign in to comment.