Two new views, picked from mockups. `sky`: a star chart of the sky over Zlín as seen lying on your back, with the planets, the moon in its phase, tonight's darkness, cloud for the next 12 hours and the next visible ISS pass. `iss`: a dotted world map with day and night, the ISS and its ground track, and the next pass over Zlín with the cloud cover for that hour. Positions are calculated locally with ephem; only the ISS orbit (CelesTrak, every 6 h, retried gently) and cloud cover (Open-Meteo) are fetched. The poller gained a per-source retry delay for that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
105 lines
4.0 KiB
Python
105 lines
4.0 KiB
Python
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, EVENING)
|
|
assert near(p.start, datetime(2026, 10, 29, 5, 38), 2)
|
|
assert 35 < p.max_alt < 45
|
|
assert (direction(p.az_from), direction(p.az_to)) == ("Z", "JV")
|
|
|
|
|
|
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
|