Skip to content

Commit

Permalink
fix: add compatibility for Skyfield 1.17
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérôme Deuchnord committed Feb 3, 2020
1 parent 52bce62 commit 081aab1
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions kosmorrolib/ephemerides.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Union

from skyfield import almanac
from skyfield.searchlib import find_discrete, find_maxima
from skyfield.timelib import Time
from skyfield.constants import tau

Expand All @@ -36,9 +37,9 @@ def __init__(self, position: Union[Position, None]):
self.position = position

def get_sun(self, start_time, end_time) -> dict:
times, is_risen = almanac.find_discrete(start_time,
end_time,
almanac.sunrise_sunset(get_skf_objects(), self.position))
times, is_risen = find_discrete(start_time,
end_time,
almanac.sunrise_sunset(get_skf_objects(), self.position))

sunrise = times[0] if is_risen[0] else times[1]
sunset = times[1] if not is_risen[1] else times[0]
Expand All @@ -64,7 +65,7 @@ def moon_phase_at(time: Time):
time1 = get_timescale().utc(year, month, day - 10)
time2 = get_timescale().utc(year, month, day + 10)

times, phase = almanac.find_discrete(time1, time2, moon_phase_at)
times, phase = find_discrete(time1, time2, moon_phase_at)

return skyfield_to_moon_phase(times, phase, today)

Expand All @@ -84,9 +85,9 @@ def is_risen(time: Time) -> bool:
start_time = get_timescale().utc(date.year, date.month, date.day)
end_time = get_timescale().utc(date.year, date.month, date.day, 23, 59, 59)

rise_times, arr = almanac.find_discrete(start_time, end_time, is_risen)
rise_times, arr = find_discrete(start_time, end_time, is_risen)
try:
culmination_time, _ = almanac._find_maxima(start_time, end_time, get_angle, epsilon=1./3600/24)
culmination_time, _ = find_maxima(start_time, end_time, f=get_angle, epsilon=1./3600/24, num=12)
except ValueError:
culmination_time = None

Expand Down Expand Up @@ -138,7 +139,7 @@ def compute_ephemerides_for_year(self, year: int) -> [dict]:
def get_seasons(year: int) -> dict:
start_time = get_timescale().utc(year, 1, 1)
end_time = get_timescale().utc(year, 12, 31)
times, almanac_seasons = almanac.find_discrete(start_time, end_time, almanac.seasons(get_skf_objects()))
times, almanac_seasons = find_discrete(start_time, end_time, almanac.seasons(get_skf_objects()))

seasons = {}
for time, almanac_season in zip(times, almanac_seasons):
Expand Down

0 comments on commit 081aab1

Please sign in to comment.