Files
rickzkmandClaude Opus 5.5 2132262896 Sky and ISS views
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]>
2026-10-29 00:03:38 +01:00

110 lines
3.9 KiB
Python

import json
from datetime import datetime, timedelta
from pathlib import Path
import numpy as np
import pytest
from PIL import ImageChops
from astro import Body
from sky_data import parse_clouds, parse_tle
from sky_view import CX, CY, R, SkyView, dome_xy, panel_rows
FIXTURES = Path(__file__).parent / "fixtures"
TLE = parse_tle((FIXTURES / "celestrak-iss.tle").read_text())
CLOUDS = parse_clouds(json.loads((FIXTURES / "open-meteo-clouds.json").read_text()))
NOW = datetime(2026, 10, 28, 19, 30, 8)
class StubPoller:
def __init__(self, value=None, version=1, age=60.0):
self.value, self.version, self._age = value, version, age
self.failures = 0
def age(self):
return self._age
def start(self):
pass
def stop(self):
pass
def view(tle=TLE, clouds=CLOUDS, tle_age=3600.0, clouds_age=60.0):
return SkyView(StubPoller(tle, age=tle_age), StubPoller(clouds, age=clouds_age))
def brightness(img, box):
return float(np.asarray(img.crop(box).convert("L")).mean())
def test_render_size_is_480x320():
assert view().render(NOW).size == (480, 320)
def test_frame_key_changes_each_minute_not_each_second():
v = view()
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 0)) == v.frame_key(datetime(2026, 10, 28, 19, 30, 59))
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 59)) != v.frame_key(datetime(2026, 10, 28, 19, 31, 0))
def test_frame_key_changes_when_orbit_or_clouds_update():
tle, clouds = StubPoller(TLE), StubPoller(CLOUDS)
v = SkyView(tle, clouds)
before = v.frame_key(NOW)
tle.version = 2
assert v.frame_key(NOW) != before
before = v.frame_key(NOW)
clouds.version = 2
assert v.frame_key(NOW) != before
def test_nothing_to_patch_between_minutes():
assert view().patch(NOW) is None
def test_dome_has_north_up_and_east_on_the_left_like_looking_up():
assert dome_xy(90, 0) == pytest.approx((CX, CY))
assert dome_xy(0, 0) == pytest.approx((CX, CY - R))
assert dome_xy(0, 90) == pytest.approx((CX - R, CY))
assert dome_xy(0, 180) == pytest.approx((CX, CY + R))
assert dome_xy(45, 270) == pytest.approx((CX + R / 2, CY))
def test_panel_lists_what_is_up_and_what_rises_soon():
bodies = (Body("Měsíc", 10.0, 95.0, None), Body("Merkur", -20.0, 250.0, NOW + timedelta(hours=12)),
Body("Venuše", -30.0, 270.0, datetime(2026, 10, 29, 6, 6)),
Body("Mars", -10.0, 30.0, datetime(2026, 10, 28, 23, 12)),
Body("Jupiter", -25.0, 14.0, datetime(2026, 10, 28, 23, 54)), Body("Saturn", 32.4, 140.0, None))
assert panel_rows(bodies, 91.2, NOW) == [("Saturn", "32° JV"), ("Měsíc", "91 % · V"), ("Mars", "↑ 23:12"),
("Jupiter", "↑ 23:54")]
def test_panel_keeps_the_four_most_useful_rows():
up = tuple(Body(name, alt, 180.0, None) for name, alt in (("Merkur", 5.0), ("Venuše", 30.0), ("Mars", 12.0)))
rising = (Body("Jupiter", -5.0, 90.0, datetime(2026, 10, 28, 21, 0)),
Body("Saturn", -5.0, 90.0, datetime(2026, 10, 28, 20, 0)))
assert [name for name, _ in panel_rows(up + rising, 50.0, NOW)] == ["Venuše", "Mars", "Merkur", "Saturn"]
def test_renders_without_orbit_or_clouds_and_still_shows_the_stars():
img = view(tle=None, clouds=None).render(NOW)
assert img.size == (480, 320)
stars = np.asarray(img.crop((CX - R, CY - R, CX + R, CY + R)).convert("L")) > 180
assert stars.sum() > 60
def test_stale_tags_only_when_old_and_only_in_the_panel():
fresh = view().render(NOW)
old = view(tle_age=4 * 86400, clouds_age=2 * 3600).render(NOW)
bbox = ImageChops.difference(fresh, old).getbbox()
assert bbox is not None and bbox[0] >= 320
def test_daytime_sky_is_lighter_than_the_night():
day = view().render(datetime(2026, 10, 28, 12, 0))
night = view().render(NOW)
box = (CX - 100, CY - 100, CX + 100, CY + 100)
assert brightness(day, box) > brightness(night, box) + 10