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]>
This commit is contained in:
1 parent
6c9a1420d2
commit
2132262896
28 files changed
+1342
-18
No files matched your search
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
ISS (ZARYA)
|
||||
1 25544U 98067A 26301.46699108 .00005372 00000+0 10526-3 0 9998
|
||||
2 25544 51.6335 0.5562 0007038 319.9799 40.0670 15.49088092592412
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"latitude":49.23005,"longitude":17.657297,"generationtime_ms":0.030279159545898438,"utc_offset_seconds":3600,"timezone":"Europe/Prague","timezone_abbreviation":"GMT+1","elevation":221.0,"hourly_units":{"time":"iso8601","cloud_cover":"%"},"hourly":{"time":["2026-10-28T00:00","2026-10-28T01:00","2026-10-28T02:00","2026-10-28T03:00","2026-10-28T04:00","2026-10-28T05:00","2026-10-28T06:00","2026-10-28T07:00","2026-10-28T08:00","2026-10-28T09:00","2026-10-28T10:00","2026-10-28T11:00","2026-10-28T12:00","2026-10-28T13:00","2026-10-28T14:00","2026-10-28T15:00","2026-10-28T16:00","2026-10-28T17:00","2026-10-28T18:00","2026-10-28T19:00","2026-10-28T20:00","2026-10-28T21:00","2026-10-28T22:00","2026-10-28T23:00","2026-10-29T00:00","2026-10-29T01:00","2026-10-29T02:00","2026-10-29T03:00","2026-10-29T04:00","2026-10-29T05:00","2026-10-29T06:00","2026-10-29T07:00","2026-10-29T08:00","2026-10-29T09:00","2026-10-29T10:00","2026-10-29T11:00","2026-10-29T12:00","2026-10-29T13:00","2026-10-29T14:00","2026-10-29T15:00","2026-10-29T16:00","2026-10-29T17:00","2026-10-29T18:00","2026-10-29T19:00","2026-10-29T20:00","2026-10-29T21:00","2026-10-29T22:00","2026-10-29T23:00"],"cloud_cover":[0,0,0,4,0,0,44,100,18,0,0,0,0,0,0,0,0,0,0,0,31,36,82,100,99,98,99,100,100,100,99,95,94,69,74,83,79,84,91,86,91,93,76,68,82,96,96,99]}}
|
||||
@@ -0,0 +1,104 @@
|
||||
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
|
||||
@@ -0,0 +1,93 @@
|
||||
import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
from PIL import ImageChops
|
||||
|
||||
import astro
|
||||
from iss_view import MAP_TOP, MARKER, IssView, is_day, map_xy
|
||||
from sky_data import parse_clouds, parse_tle
|
||||
from tests.helpers import count_near
|
||||
|
||||
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)
|
||||
NIGHT_IN_ZLIN = (-13.3, -101.5) # subsolar point at that moment
|
||||
|
||||
|
||||
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):
|
||||
return IssView(StubPoller(tle, age=tle_age), StubPoller(clouds))
|
||||
|
||||
|
||||
def test_render_size_is_480x320():
|
||||
assert view().render(NOW).size == (480, 320)
|
||||
|
||||
|
||||
def test_frame_key_changes_every_ten_seconds():
|
||||
v = view()
|
||||
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 0)) == v.frame_key(datetime(2026, 10, 28, 19, 30, 9))
|
||||
assert v.frame_key(datetime(2026, 10, 28, 19, 30, 9)) != v.frame_key(datetime(2026, 10, 28, 19, 30, 10))
|
||||
|
||||
|
||||
def test_frame_key_changes_when_the_orbit_updates():
|
||||
tle = StubPoller(TLE)
|
||||
v = IssView(tle, StubPoller(CLOUDS))
|
||||
before = v.frame_key(NOW)
|
||||
tle.version = 2
|
||||
assert v.frame_key(NOW) != before
|
||||
|
||||
|
||||
def test_nothing_to_patch_between_frames():
|
||||
assert view().patch(NOW) is None
|
||||
|
||||
|
||||
def test_map_is_equirectangular_under_the_header():
|
||||
assert map_xy(0, 0) == pytest.approx((240, MAP_TOP + 120))
|
||||
assert map_xy(90, -180) == pytest.approx((0, MAP_TOP))
|
||||
assert map_xy(-90, 180) == pytest.approx((480, MAP_TOP + 240))
|
||||
|
||||
|
||||
def test_day_and_night():
|
||||
assert is_day(0, 0, (0, 0))
|
||||
assert not is_day(0, 180, (0, 0))
|
||||
assert not is_day(49.2, 17.7, NIGHT_IN_ZLIN) # Zlín at 19:30 in October
|
||||
assert is_day(-10, -50, NIGHT_IN_ZLIN) # Brazil in the afternoon
|
||||
|
||||
|
||||
def test_marker_is_where_the_iss_is():
|
||||
img = view().render(NOW)
|
||||
fix = astro.iss_fix(TLE, NOW)
|
||||
x, y = map_xy(fix.lat, fix.lon)
|
||||
assert count_near(img, MARKER, 40, (int(x) - 9, int(y) - 9, int(x) + 10, int(y) + 10)) > 20
|
||||
|
||||
|
||||
def test_without_an_orbit_there_is_no_marker():
|
||||
with_orbit, without = view().render(NOW), view(tle=None).render(NOW)
|
||||
fix = astro.iss_fix(TLE, NOW)
|
||||
x, y = map_xy(fix.lat, fix.lon)
|
||||
box = (int(x) - 9, int(y) - 9, int(x) + 10, int(y) + 10)
|
||||
assert count_near(without, MARKER, 40, box) < count_near(with_orbit, MARKER, 40, box) / 4
|
||||
|
||||
|
||||
def test_stale_tag_only_when_the_orbit_is_old_and_only_in_the_header():
|
||||
fresh = view().render(NOW)
|
||||
old = view(tle_age=4 * 86400).render(NOW)
|
||||
bbox = ImageChops.difference(fresh, old).getbbox()
|
||||
assert bbox is not None and bbox[3] <= MAP_TOP
|
||||
@@ -81,3 +81,18 @@ def test_slow_fetch_does_not_block_reader():
|
||||
finally:
|
||||
release.set()
|
||||
p.stop()
|
||||
|
||||
|
||||
def test_failed_fetch_retries_within_a_minute_by_default():
|
||||
p = Poller(lambda: 1, interval=6 * 3600)
|
||||
assert p.wait_after(ok=True) == 6 * 3600
|
||||
assert p.wait_after(ok=False) == 60
|
||||
|
||||
|
||||
def test_retry_can_be_slower_for_sources_that_ban_eager_clients():
|
||||
p = Poller(lambda: 1, interval=6 * 3600, retry=15 * 60)
|
||||
assert p.wait_after(ok=False) == 15 * 60
|
||||
|
||||
|
||||
def test_retry_never_waits_longer_than_the_interval():
|
||||
assert Poller(lambda: 1, interval=30, retry=15 * 60).wait_after(ok=False) == 30
|
||||
+12
-5
@@ -3,20 +3,20 @@ import pytest
|
||||
from registry import REGISTRY, UnknownView, make_view
|
||||
|
||||
|
||||
def test_registry_has_both_views():
|
||||
assert sorted(REGISTRY) == ["server", "weather"]
|
||||
def test_registry_has_all_views():
|
||||
assert sorted(REGISTRY) == ["iss", "server", "sky", "weather"]
|
||||
|
||||
|
||||
def test_make_view_builds_named_views():
|
||||
assert make_view("weather").name == "weather"
|
||||
assert make_view("server").name == "server"
|
||||
for name in ("weather", "server", "sky", "iss"):
|
||||
assert make_view(name).name == name
|
||||
|
||||
|
||||
def test_make_view_unknown_lists_valid_names():
|
||||
with pytest.raises(UnknownView) as err:
|
||||
make_view("bogus")
|
||||
assert err.value.name == "bogus"
|
||||
assert err.value.valid == ["server", "weather"]
|
||||
assert err.value.valid == ["iss", "server", "sky", "weather"]
|
||||
|
||||
|
||||
def test_make_view_empty_name_is_unknown():
|
||||
@@ -28,3 +28,10 @@ def test_server_view_polls_every_second_and_weather_every_quarter_hour():
|
||||
import registry
|
||||
assert registry.SERVER_REFRESH_S == 1
|
||||
assert registry.WEATHER_REFRESH_S == 15 * 60
|
||||
|
||||
|
||||
def test_sky_views_fetch_the_orbit_gently_and_clouds_every_quarter_hour():
|
||||
import registry
|
||||
assert registry.TLE_REFRESH_S == 6 * 3600
|
||||
assert registry.TLE_RETRY_S >= 15 * 60 # CelesTrak blocks clients that retry eagerly
|
||||
assert registry.CLOUDS_REFRESH_S == 15 * 60
|
||||
@@ -0,0 +1,109 @@
|
||||
import copy
|
||||
import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
import sky_data
|
||||
from sky_data import CloudHour, Tle, cloud_at, cloud_story, parse_clouds, parse_tle
|
||||
|
||||
FIXTURES = Path(__file__).parent / "fixtures"
|
||||
TLE_TEXT = (FIXTURES / "celestrak-iss.tle").read_text()
|
||||
CLOUDS = json.loads((FIXTURES / "open-meteo-clouds.json").read_text())
|
||||
|
||||
|
||||
def clouds_payload():
|
||||
return copy.deepcopy(CLOUDS)
|
||||
|
||||
|
||||
class Response:
|
||||
def __init__(self, text="", payload=None):
|
||||
self.text, self._payload = text, payload
|
||||
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
def json(self):
|
||||
return self._payload
|
||||
|
||||
|
||||
def test_parse_tle_from_celestrak():
|
||||
tle = parse_tle(TLE_TEXT)
|
||||
assert tle.name == "ISS (ZARYA)"
|
||||
assert tle.line1.startswith("1 25544U")
|
||||
assert tle.line2.startswith("2 25544 ")
|
||||
|
||||
|
||||
@pytest.mark.parametrize("text", ["", "<html>Too many requests</html>", "ISS\n1 nonsense\n2 nonsense\n",
|
||||
"No GP data found"])
|
||||
def test_parse_tle_rejects_anything_else(text):
|
||||
with pytest.raises(ValueError):
|
||||
parse_tle(text)
|
||||
|
||||
|
||||
def test_fetch_tle_asks_for_the_iss_only():
|
||||
calls = []
|
||||
|
||||
def fake_get(url, params=None, timeout=None):
|
||||
calls.append((url, params, timeout))
|
||||
return Response(text=TLE_TEXT)
|
||||
|
||||
assert isinstance(sky_data.fetch_tle(get=fake_get), Tle)
|
||||
url, params, timeout = calls[0]
|
||||
assert url.startswith("https://celestrak.org/")
|
||||
assert params == {"CATNR": 25544, "FORMAT": "TLE"}
|
||||
assert timeout == 10
|
||||
|
||||
|
||||
def test_parse_clouds():
|
||||
clouds = parse_clouds(clouds_payload())
|
||||
assert len(clouds) == 48
|
||||
assert clouds[0] == CloudHour(datetime(2026, 10, 28, 0, 0), 0)
|
||||
assert clouds[22] == CloudHour(datetime(2026, 10, 28, 22, 0), 82)
|
||||
|
||||
|
||||
def test_parse_clouds_keeps_nulls_as_none_and_survives_missing_sections():
|
||||
p = clouds_payload()
|
||||
p["hourly"]["cloud_cover"][5] = None
|
||||
assert parse_clouds(p)[5].pct is None
|
||||
assert parse_clouds({}) == ()
|
||||
|
||||
|
||||
def test_fetch_clouds_asks_for_hourly_cloud_cover_in_zlin():
|
||||
calls = []
|
||||
|
||||
def fake_get(url, params=None, timeout=None):
|
||||
calls.append(params)
|
||||
return Response(payload=clouds_payload())
|
||||
|
||||
assert len(sky_data.fetch_clouds(get=fake_get)) == 48
|
||||
params = calls[0]
|
||||
assert (params["latitude"], params["longitude"]) == (49.2265, 17.6627)
|
||||
assert params["hourly"] == "cloud_cover"
|
||||
assert params["timezone"] == "Europe/Prague"
|
||||
|
||||
|
||||
def test_cloud_at_matches_the_hour_containing_the_moment():
|
||||
clouds = parse_clouds(clouds_payload())
|
||||
assert cloud_at(clouds, datetime(2026, 10, 29, 5, 38, 12, 345678)) == 100
|
||||
assert cloud_at(clouds, datetime(2026, 10, 28, 20, 0)) == 31
|
||||
assert cloud_at(clouds, datetime(2026, 11, 5, 20, 0)) is None
|
||||
|
||||
|
||||
def test_cloud_story_tonight():
|
||||
clouds = parse_clouds(clouds_payload()) # clear until 19 h, 31 % at 20 h, 82 % at 22 h
|
||||
assert cloud_story(clouds, datetime(2026, 10, 28, 19, 30)) == "Jasno do 20 h, od 22 h zataženo"
|
||||
|
||||
|
||||
def test_cloud_story_other_skies():
|
||||
def flat(pct):
|
||||
return tuple(CloudHour(datetime(2026, 10, 28, h, 0), pct) for h in range(24))
|
||||
|
||||
at = datetime(2026, 10, 28, 8, 15)
|
||||
assert cloud_story(flat(5), at) == "Jasno"
|
||||
assert cloud_story(flat(40), at) == "Polojasno"
|
||||
assert cloud_story(flat(90), at) == "Zataženo"
|
||||
clearing = tuple(CloudHour(datetime(2026, 10, 28, h, 0), 30 if h < 10 else 0) for h in range(24))
|
||||
assert cloud_story(clearing, at) == "Polojasno"
|
||||
assert cloud_story((), at) is None
|
||||
@@ -0,0 +1,109 @@
|
||||
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
|
||||
@@ -0,0 +1,29 @@
|
||||
from PIL import Image
|
||||
|
||||
import skykit
|
||||
from tests.helpers import count_colour
|
||||
|
||||
LIT, DARK, BG = (255, 255, 255), (40, 40, 40), (0, 0, 0)
|
||||
|
||||
|
||||
def moon(pct, waxing):
|
||||
img = Image.new("RGB", (40, 40), BG)
|
||||
skykit.moon_disc(img, 20, 20, 16, pct, waxing, lit=LIT, dark=DARK)
|
||||
return img
|
||||
|
||||
|
||||
def lit(img, box=None):
|
||||
return count_colour(img, LIT, box)
|
||||
|
||||
|
||||
def test_waxing_moon_is_lit_on_the_right_waning_on_the_left():
|
||||
waxing, waning = moon(50, True), moon(50, False)
|
||||
assert lit(waxing, (20, 0, 40, 40)) > 10 * max(1, lit(waxing, (0, 0, 20, 40)))
|
||||
assert lit(waning, (0, 0, 20, 40)) > 10 * max(1, lit(waning, (20, 0, 40, 40)))
|
||||
|
||||
|
||||
def test_lit_area_grows_with_illumination():
|
||||
areas = [lit(moon(pct, True)) for pct in (0, 10, 50, 90, 100)]
|
||||
assert areas == sorted(areas)
|
||||
assert areas[0] == 0
|
||||
assert areas[-1] > 0.9 * 3.14 * 16 * 16
|
||||
@@ -0,0 +1,13 @@
|
||||
from datetime import datetime
|
||||
|
||||
from timeutil import from_utc, to_utc
|
||||
|
||||
|
||||
def test_to_utc_in_winter_and_summer_time():
|
||||
assert to_utc(datetime(2026, 10, 28, 19, 30), "Europe/Prague") == datetime(2026, 10, 28, 18, 30)
|
||||
assert to_utc(datetime(2026, 10, 22, 12, 0), "Europe/Prague") == datetime(2026, 10, 22, 10, 0)
|
||||
|
||||
|
||||
def test_from_utc_in_winter_and_summer_time():
|
||||
assert from_utc(datetime(2026, 10, 28, 18, 30), "Europe/Prague") == datetime(2026, 10, 28, 19, 30)
|
||||
assert from_utc(datetime(2026, 10, 22, 10, 0), "Europe/Prague") == datetime(2026, 10, 22, 12, 0)
|
||||
Reference in new issue
Block a user