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]>
125 lines
5.0 KiB
Python
125 lines
5.0 KiB
Python
import math
|
|
from datetime import datetime, timedelta
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
import astro
|
|
from astro import direction
|
|
from sky_data import parse_tle
|
|
|
|
TLE = parse_tle((Path(__file__).parent / "fixtures" / "celestrak-iss.tle").read_text()) # epoch 28 Oct 2026
|
|
EVENING = datetime(2026, 10, 28, 19, 30) # local time in Zlín (CET)
|
|
|
|
|
|
def near(actual: datetime, expected: datetime, minutes: float = 4) -> bool:
|
|
return abs(actual - expected) <= timedelta(minutes=minutes)
|
|
|
|
|
|
@pytest.mark.parametrize("az, name", [(0, "S"), (22, "S"), (23, "SV"), (90, "V"), (135, "JV"), (180, "J"),
|
|
(270, "Z"), (315, "SZ"), (359, "S")])
|
|
def test_direction_uses_czech_compass_letters(az, name):
|
|
assert direction(az) == name
|
|
|
|
|
|
def test_moon_is_waning_two_days_after_full_moon():
|
|
pct, waxing = astro.moon_phase(EVENING) # full moon was on 26 Oct
|
|
assert 85 < pct < 96
|
|
assert not waxing
|
|
|
|
|
|
def test_darkness_tonight():
|
|
start, end = astro.darkness(EVENING)
|
|
assert near(start, datetime(2026, 10, 28, 18, 22))
|
|
assert near(end, datetime(2026, 10, 29, 4, 44))
|
|
|
|
|
|
def test_after_midnight_darkness_is_the_current_night():
|
|
assert astro.darkness(datetime(2026, 10, 29, 2, 0)) == astro.darkness(EVENING)
|
|
|
|
|
|
def test_no_full_darkness_around_midsummer():
|
|
# at 49.2° N the sun sinks at most 90 - 49.2 - 23.4 = 17.4° below the horizon, never the 18° of full darkness
|
|
assert astro.darkness(datetime(2026, 6, 21, 23, 0)) is None
|
|
|
|
|
|
def test_polaris_stands_at_our_latitude_due_north():
|
|
polaris = next(s for s in astro.stars(EVENING) if s.name == "Polaris")
|
|
assert abs(polaris.alt - 49.2) < 1.2
|
|
assert min(polaris.az, 360 - polaris.az) < 1.5
|
|
|
|
|
|
def test_only_stars_above_the_horizon():
|
|
names = {s.name for s in astro.stars(EVENING)}
|
|
assert {"Vega", "Deneb", "Altair", "Capella"} <= names
|
|
assert "Sirius" not in names # an evening in October: below the horizon
|
|
assert all(s.alt > 0 for s in astro.stars(EVENING))
|
|
|
|
|
|
def test_planets_tonight():
|
|
bodies = {b.name: b for b in astro.bodies(EVENING)}
|
|
assert list(bodies) == ["Měsíc", "Merkur", "Venuše", "Mars", "Jupiter", "Saturn"]
|
|
assert 25 < bodies["Saturn"].alt < 40 and direction(bodies["Saturn"].az) == "JV"
|
|
assert bodies["Měsíc"].alt > 0 and direction(bodies["Měsíc"].az) == "V"
|
|
assert bodies["Mars"].alt < 0 and near(bodies["Mars"].rise, datetime(2026, 10, 28, 23, 12), 5)
|
|
assert near(bodies["Jupiter"].rise, datetime(2026, 10, 28, 23, 54), 5)
|
|
|
|
|
|
def test_iss_stays_within_its_orbit():
|
|
fix = astro.iss_fix(TLE, EVENING)
|
|
assert abs(fix.lat) <= 51.7 # orbit inclination 51.6°
|
|
assert 370 < fix.km < 460
|
|
|
|
|
|
def test_iss_track_runs_east_minute_by_minute():
|
|
track = astro.iss_track(TLE, EVENING)
|
|
assert [m for m, _, _ in track] == list(range(-40, 96))
|
|
for (_, lat0, lon0), (_, lat1, lon1) in zip(track, track[1:]):
|
|
assert abs(lat1) <= 51.7
|
|
assert 2 < (lon1 - lon0) % 360 < 6 # one orbit in ~93 min, minus the earth turning under it
|
|
|
|
|
|
def test_next_visible_iss_pass():
|
|
p = astro.next_visible_pass(TLE, datetime(2026, 10, 29, 4, 30))
|
|
assert near(p.start, datetime(2026, 10, 29, 5, 41), 1) # when it climbs past 10°, not when it rises
|
|
assert 35 < p.max_alt < 45
|
|
assert (direction(p.az_from), direction(p.az_to)) == ("Z", "JV")
|
|
|
|
|
|
def test_pass_that_comes_out_of_the_earths_shadow_counts_from_there():
|
|
p = astro.next_visible_pass(TLE, EVENING) # in the shadow at its highest, so easy to miss
|
|
assert near(p.start, datetime(2026, 10, 29, 4, 8), 1)
|
|
assert 35 < p.max_alt < 45
|
|
assert (direction(p.az_from), direction(p.az_to)) == ("V", "V")
|
|
|
|
|
|
def test_pass_brightness_is_that_of_a_typical_iss_pass():
|
|
p = astro.next_visible_pass(TLE, datetime(2026, 10, 29, 4, 30))
|
|
assert -4.2 < p.mag < -2.5 # a 40° pass: brighter than any star, short of the best overhead passes
|
|
|
|
|
|
def test_magnitude_formula():
|
|
assert astro.magnitude(1000, math.pi / 2) == pytest.approx(astro.ISS_STD_MAG)
|
|
assert astro.magnitude(500, math.pi / 2) == pytest.approx(astro.ISS_STD_MAG - 5 * math.log10(2))
|
|
assert astro.magnitude(1000, 0) == pytest.approx(astro.ISS_STD_MAG - 2.5 * math.log10(math.pi)) # fully lit
|
|
assert astro.magnitude(1000, math.pi) > 10 # only the dark side faces us: invisible, not an error
|
|
|
|
|
|
def test_no_visible_pass_within_the_window():
|
|
assert astro.next_visible_pass(TLE, EVENING, within_hours=6) is None
|
|
|
|
|
|
def test_subsolar_point():
|
|
# 18:30 UTC on 28 Oct: declination about -13.3°; the sundial runs 16 minutes ahead of the clock in late
|
|
# October, so it is 18:46 apparent time at Greenwich and the sun stands 6.77 h * 15° = 101.5° west
|
|
lat, lon = astro.subsolar(EVENING)
|
|
assert abs(lat - -13.3) < 1
|
|
assert abs(lon - -101.5) < 2
|
|
|
|
|
|
def test_noon_sun_stands_due_south_at_90_minus_latitude_plus_declination():
|
|
# solar noon in Zlín on 28 Oct: 12:00 CET - 10.6 min (17.66° east of 15°) - 16 min equation of time = 11:33
|
|
sun = astro.sun(datetime(2026, 10, 28, 11, 33))
|
|
assert abs(sun.alt - (90 - 49.2 - 13.0)) < 1
|
|
assert abs(sun.az - 180) < 3
|