Skip to content

Commit 3d90e55

Browse files
Fix
1 parent 563345f commit 3d90e55

2 files changed

Lines changed: 24 additions & 12 deletions

File tree

skyfield/almanac.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def fraction_illuminated(ephemeris, body, t):
5252
def find_discrete(start_time, end_time, f, epsilon=EPSILON, num=12):
5353
"""Find the times when a function changes value.
5454
55-
Searches between ``start_time`` and ``end_time``, which should both
56-
be :class:`~skyfield.timelib.Time` objects, for the occasions where
57-
the function ``f`` changes from one value to another. Use this to
55+
Search between ``start_time`` and ``end_time``, which should both be
56+
:class:`~skyfield.timelib.Time` objects, for the occasions where the
57+
function ``f`` changes from one value to another. Use this to
5858
search for events like sunrise or moon phases.
5959
6060
A tuple of two arrays is returned. The first array gives the times
@@ -82,7 +82,10 @@ def find_discrete(start_time, end_time, f, epsilon=EPSILON, num=12):
8282
periods = 1.0
8383

8484
jd = linspace(jd0, jd1, int(periods * num))
85+
return _find_discrete(ts, jd, f, epsilon, num)
8586

87+
def _find_discrete(ts, jd, f, epsilon, num):
88+
"""Algorithm core, for callers that already have a `jd` vector."""
8689
end_mask = linspace(0.0, 1.0, num)
8790
start_mask = end_mask[::-1]
8891
o = multiply.outer
@@ -268,6 +271,14 @@ def is_sun_up_at(t):
268271
is_sun_up_at.rough_period = 0.5 # twice a day
269272
return is_sun_up_at
270273

274+
TWILIGHTS = {
275+
0: 'Night',
276+
1: 'Astronomical twilight',
277+
2: 'Nautical twilight',
278+
3: 'Civil twilight',
279+
4: 'Day',
280+
}
281+
271282
def dark_twilight_day(ephemeris, topos):
272283
"""Build a function of time returning whether it is dark, twilight, or day.
273284

skyfield/documentation/almanac.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,20 @@ of the phases of twilight using integers:
226226
t0 = ts.utc(2019, 11, 8, 5)
227227
t1 = ts.utc(2019, 11, 9, 5)
228228
t, y = almanac.find_discrete(t0, t1, almanac.dark_twilight_day(e, bluffton))
229+
229230
for ti, yi in zip(t, y):
230-
print(yi, ti.utc_iso())
231+
print(yi, ti.utc_iso(), ' Start of', almanac.TWILIGHTS[yi])
231232

232233
.. testoutput::
233234

234-
1 2019-11-08T10:40:20Z
235-
2 2019-11-08T11:12:31Z
236-
3 2019-11-08T11:45:18Z
237-
4 2019-11-08T12:14:15Z
238-
3 2019-11-08T22:23:52Z
239-
2 2019-11-08T22:52:49Z
240-
1 2019-11-08T23:25:34Z
241-
0 2019-11-08T23:57:44Z
235+
1 2019-11-08T10:40:20Z Start of Astronomical twilight
236+
2 2019-11-08T11:12:31Z Start of Nautical twilight
237+
3 2019-11-08T11:45:18Z Start of Civil twilight
238+
4 2019-11-08T12:14:15Z Start of Day
239+
3 2019-11-08T22:23:52Z Start of Civil twilight
240+
2 2019-11-08T22:52:49Z Start of Nautical twilight
241+
1 2019-11-08T23:25:34Z Start of Astronomical twilight
242+
0 2019-11-08T23:57:44Z Start of Night
242243

243244
Satellite Events
244245
================

0 commit comments

Comments
 (0)