Skip to content

Commit 9ab9633

Browse files
Prevent satellite find_events() from exiting early
The discrete finder, as it narrowed in on N events, was watching only how tightly it was bracketing the first event, on the assumption that they were all bracketed by roughly equal intervals. But for satellite find_events(), this is not the case: their brackets are not the same size, so all intervals need watching. Fixes #1000.
1 parent 3ca3426 commit 9ab9633

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

CHANGELOG.rst

+10-3
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,19 @@ Next version
3030

3131
So Skyfield now encourages code to ask for ``position.xyz`` instead.
3232
An advantage is that the new name is self-documenting: the name
33-
reminds the user that it is a 3-vector with Cartesian components.
33+
reminds the user that it is a 3-vector of Cartesian components.
3434

3535
* Fix: the :meth:`~skyfield.sgp4lib.EarthSatellite.find_events()` Earth
3636
satellite method was returning an empty list of events if the only
37-
event in the time period was a sole rising or setting. It should now
38-
find them successfully.
37+
event in the time period was a lone rising or setting. It should now
38+
detect and return them.
39+
`#996 <https://github.com/skyfielders/python-skyfield/issues/996>`_
40+
41+
* Fix: the :meth:`~skyfield.sgp4lib.EarthSatellite.find_events()` Earth
42+
satellite method, faced with a single pass that was very close to the
43+
start time, was returning an inaccurate setting time. It should now
44+
return an accurate setting time.
45+
`#1000 <https://github.com/skyfielders/python-skyfield/issues/1000>`_
3946

4047
* Fix: bodies with Kepler orbits (like comets and asteroids) were
4148
incorrectly returning positions with only a single dimension if given

skyfield/searchlib.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ def _find_discrete(ts, jd, f, epsilon, num):
6565
starts = jd[indices]
6666
ends = jd[indices + 1]
6767

68-
# Since we start with equal intervals, they all should fall
69-
# below epsilon at around the same time; so for efficiency we
70-
# only test the first pair.
71-
if ends[0] - starts[0] <= epsilon:
68+
if (ends - starts).max() <= epsilon:
7269
y = y[indices + 1]
7370
# Keep only the last of several zero crossings that might
7471
# possibly be separated by less than epsilon.

skyfield/tests/test_satellite_events.py

+18
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,21 @@ def run_sat(name, line1, line2, number_events_expected):
141141
'2 41105 5.0153 78.6193 0002491 153.4123 31.4253 1.00270890 31881',
142142
1,
143143
)
144+
145+
def test_earth_satellite_pass_very_close_to_start_time():
146+
ts = load.timescale()
147+
t0 = ts.utc(2024, 9, 5)
148+
t1 = ts.utc(2024, 9, 6)
149+
observer = wgs84.latlon(+48.6622, +34.8862, 0)
150+
satellite = EarthSatellite(
151+
'1 38707U 12039A 24247.82317651 .00138984 00000-0 16635-2 0 9998',
152+
'2 38707 97.4945 189.8924 0007050 108.0286 252.1739 15.60479551673427',
153+
'KANOPUS', ts,
154+
)
155+
t, y = satellite.find_events(observer, t0, t1, 70.0)
156+
assert list(y) == [0, 1, 2]
157+
assert t.utc_strftime() == [
158+
'2024-09-05 00:00:32 UTC',
159+
'2024-09-05 00:00:50 UTC',
160+
'2024-09-05 00:01:08 UTC', # was 00:02:56 before bug was fixed
161+
]

0 commit comments

Comments
 (0)