Find ISS passes that start or end in the earth's shadow

Visibility was only checked at the highest point, so passes that enter the
shadow on the way up (or leave it on the way down) were dropped. Sample the
whole pass and keep the part above 10°, sunlit, under a dark sky; times now
match Clear Outside.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Opus 5.5 committed 2026-11-15 18:49:46 +01:00
1 parent 70b02f865d
commit 581d12324d
3 files changed
+39 -27

No files matched your search

+28 -23
View File
@@ -21,7 +21,8 @@ DARK_SUN_ALT = "-18" # astronomical darkness
VISIBLE_SUN_ALT = -6 # a satellite pass is visible once the sky is at least this dark
TRACK_BACK, TRACK_AHEAD = 40, 95 # minutes of ISS ground track around now
ISS_STD_MAG = -1.8 # brightness at 1000 km and a 90° phase angle; observers quote -1.3 to -1.8
PASS_STEP_S = 10 # how finely a pass is sampled to find its brightest moment
PASS_STEP_S = 10 # how finely a pass is sampled to find when it is visible and how bright
PASS_MIN_ALT = 10 # degrees; a pass counts from here up, as on Heavens-Above and Clear Outside
@dataclass(frozen=True)
@@ -150,19 +151,37 @@ def next_visible_pass(tle: Tle, now: datetime, within_hours: float = 72) -> Pass
o = _observer(now)
limit = ephem.Date(to_utc(now + timedelta(hours=within_hours)))
while o.date < limit:
rise, az_rise, top, top_alt, set_, az_set = o.next_pass(iss)
if rise is None or rise > limit:
rise, _, _, _, set_, _ = o.next_pass(iss)
if rise is None or set_ is None or rise > limit:
return None
o.date = top
iss.compute(o)
sun.compute(o)
if not iss.eclipsed and math.degrees(sun.alt) < VISIBLE_SUN_ALT:
return Pass(_local(rise), math.degrees(top_alt), math.degrees(az_rise), math.degrees(az_set), True,
_brightest(iss, sun, o, rise, set_))
seen = _visible_part(iss, sun, o, rise, set_)
if seen:
start, end = seen[0], seen[-1]
return Pass(_local(start[0]), max(alt for _, alt, _, _ in seen), start[2], end[2], True,
min(mag for *_, mag in seen))
o.date = set_ + ephem.minute
return None
def _visible_part(iss: ephem.EarthSatellite, sun: ephem.Sun, o: ephem.Observer, rise,
set_) -> list[tuple[ephem.Date, float, float, float]]:
"""(date, alt, az, magnitude) every PASS_STEP_S while the ISS is high enough, sunlit and the sky here dark.
A pass often starts in daylight or ends in the earth's shadow well before it sets, so only this part is seen.
"""
seen = []
t = rise
while t <= set_:
o.date = t
iss.compute(o)
sun.compute(o)
if math.degrees(iss.alt) >= PASS_MIN_ALT and not iss.eclipsed and math.degrees(sun.alt) < VISIBLE_SUN_ALT:
seen.append((ephem.Date(t), math.degrees(iss.alt), math.degrees(iss.az),
magnitude(iss.range / 1000, _phase(iss, sun))))
t += PASS_STEP_S * ephem.second
return seen
def magnitude(range_km: float, phase: float, std_mag: float = ISS_STD_MAG) -> float:
"""Estimated magnitude of a satellite seen as a diffusely reflecting sphere (Robert Matson's formula).
@@ -183,20 +202,6 @@ def _phase(sat: ephem.EarthSatellite, sun: ephem.Sun) -> float:
return math.acos(max(-1.0, min(1.0, cos)))
def _brightest(iss: ephem.EarthSatellite, sun: ephem.Sun, o: ephem.Observer, rise, set_) -> float:
"""The lowest magnitude while the ISS is above the horizon and sunlit."""
best = math.inf
t = rise
while t <= set_:
o.date = t
iss.compute(o)
sun.compute(o)
if iss.alt > 0 and not iss.eclipsed:
best = min(best, magnitude(iss.range / 1000, _phase(iss, sun)))
t += PASS_STEP_S * ephem.second
return best
def subsolar(now: datetime) -> tuple[float, float]:
"""Latitude and longitude where the sun is straight overhead."""
o = ephem.Observer()