Give the aerodromes a colour of their own, and say what each aircraft is

Four things about the animated pictures, and the window kept in step with
them.

The aerodromes were amber, and so is an aeroplane at twelve thousand feet.
Sixteen units of CIELAB apart is not two colours, it is one: an aircraft low
over a field was drawn in the field's own colour and neither could be picked
out from the other.  They are magenta now, fifty-six units from the nearest
altitude colour, which is what the ramp leaves free once red, amber, green,
cyan and violet have gone on height -- and what an aeronautical chart marks
an aerodrome in anyway.  The test states that as the distance rather than as
the colour, so that changing the ramp cannot quietly walk an aircraft back
into the airports.

The height beside an aircraft was the flight level, which is shorter and is
what an aviator reads, but "376" is only a height to somebody who already
knows it is one.  It is feet with the unit on it now, rounded to the
twenty-five feet Mode S reports altitude in: a real reading is a multiple of
that and comes through untouched, while a moment interpolated between two
reports stops claiming to know the height to the foot.

The flag of the country of registration now comes off the address block
where no register answered.  Taking it from the register's answer alone left
the flag off exactly the aircraft that had nothing else beside them either.
Mexico was missing from the address table while we were in there, which a
receiver in the American southwest notices; two registers independently give
XA- registrations for that block.

And what sort of aircraft it is, which is two facts and not one.  What it is
comes off the air: every identification message carries three bits under its
type code saying whether it is light, large, heavy, a rotorcraft, a glider,
a drone or a van on the apron, and that is the only word about what an
aircraft *is* that needs no register.  They were being decoded and thrown
away.  They are inside the identification frame the log already writes down
in full, so every log this program has ever written has them, including the
ones written before anything here knew to look.

Whether it is military comes off no air at all -- a tanker calls itself
heavy exactly as an airliner does -- and is read from the address block
instead.  On one evening here AE07D3 broadcast "heavy" and sat in the United
States military block; the register, asked separately, came back with a
C-17A Globemaster III, tail 90-0534, United States Air Force.

Labels in an animation now behave as the boxes in the window do.  One keeps
its place for as long as that place still works and is moved only when
something takes it, which on a real log is about half as many moves as
deciding afresh every frame; the moves that are left are eased over half a
second of playback; and what the next label is laid out against is where a
moving one is going rather than where it has reached.  A still has no frame
before it and places its labels exactly as it always did.

The fading was only half done.  A label's name faded, because it is drawn in
the aircraft's own colour, but its rows and its flag were fixed colours and
stayed at full brightness -- so the brightest thing on that part of the
picture was the one aeroplane nothing had been heard from.  An indexed
picture cannot blend, so the row grey and all twelve flag colours now have
dimmed copies at each of the four fade steps, and the whole box goes
together.  A crowded frame, which drops back to the short label, drops the
class and the flag with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016PsWPTweCT6pwxKngvVxcg
This commit is contained in:
The Dust Council 2026-09-04 22:45:41 -07:00
parent 8eb3bdbb86
commit f9b21f7e35
13 changed files with 1616 additions and 67 deletions

View file

@ -763,7 +763,9 @@ def test_the_label_says_height_speed_type_and_both_ends_of_the_route():
track = straight()
rows = fm.label_lines(track, track.fixes[0], "knots", _Entry())
text = [line for line, _flag in rows]
assert text[0].startswith("350") # flight level
# The height in feet with its unit on it: "350" is only a height to
# somebody who already knows it is one.
assert text[0].startswith("35,000 ft")
assert "480KT" in text[0]
assert "B739 N904DN" in text
assert "KATL" in text and "EGLL" in text
@ -778,9 +780,24 @@ def test_each_end_of_the_route_carries_its_own_country():
def test_with_no_register_the_label_is_what_the_aircraft_itself_said():
"""The height and the speed, which came off the air, and the flag of the
country that issued the address, which needs no register either."""
track = straight()
rows = fm.label_lines(track, track.fixes[0], "knots", None)
assert len(rows) == 1 and rows[0][1] == ""
assert rows[0][0].startswith("35,000 ft") and rows[0][1] == ""
assert [flag for _text, flag in rows if flag] == ["IE"]
assert not any("N904DN" in text for text, _flag in rows)
def test_the_flag_is_there_for_an_aircraft_no_register_has_heard_of():
"""Taking the country from the register's answer left the flag off
exactly the aircraft that had nothing else beside them either. The
address block says it without asking anybody."""
for icao, expected in (("4CA1FA", "IE"), ("A12345", "US"),
("0D0468", "MX"), ("406B12", "GB")):
track = straight(icao=icao)
rows = fm.label_lines(track, track.fixes[0], "knots", None)
assert [flag for _text, flag in rows if flag] == [expected], icao
def test_an_airport_with_no_code_is_named_short_rather_than_in_full():
@ -861,11 +878,28 @@ def test_the_route_reaches_the_drawn_picture(tmp_path):
known = {t.icao: _Entry() for t in tracks}
frame = fm.render_frame(base, view, tracks, tracks[0].first_seen + 60,
known=known)
assert (frame >= fm.FLAG).any(), "no flag was drawn"
assert _has_flag(frame), "no flag was drawn"
assert _has_text(frame, "KATL")
assert _has_text(frame, "B739")
def _has_flag(frame) -> bool:
"""Whether any flag was drawn: its own colours, at any fade step.
Checked by the exact palette ranges rather than "any index above the
flags", because everything a fading label is drawn in lives above them
too.
"""
import numpy as np
from bandsaunter.flags import COLOUR_ORDER
wide = len(COLOUR_ORDER)
return bool(((frame >= fm.FLAG) & (frame < fm.FLAG + wide)).any()
or ((frame >= fm.FLAG_FADED)
& (frame < fm.FLAG_FADED + 3 * wide)).any())
def test_a_crowded_frame_goes_back_to_the_short_label():
"""Five lines beside each of three hundred aircraft is not more
information, it is a page of overlapping text with a map behind it."""
@ -877,7 +911,7 @@ def test_a_crowded_frame_goes_back_to_the_short_label():
known = {t.icao: _Entry() for t in many}
frame = fm.render_frame(base, view, many, many[0].first_seen + 60,
known=known)
assert not (frame >= fm.FLAG).any(), "still drawing flags when crowded"
assert not _has_flag(frame), "still drawing flags when crowded"
assert not _has_text(frame, "B739")
@ -949,12 +983,18 @@ def test_the_address_block_stands_in_when_a_register_says_nothing():
def test_a_country_nobody_named_gets_no_flag():
track = straight()
"""An address outside every block anybody has published, and a register
that did not say either: no flag rather than a guessed one."""
from bandsaunter.flights import describe_address
assert describe_address("0F0000") == "", "pick an unallocated address"
track = straight(icao="0F0000")
entry = _Entry()
entry.owner_country = ""
entry.country = ""
rows = dict(fm.label_lines(track, track.fixes[0], "knots", entry))
assert rows["B739 N904DN"] == ""
rows = fm.label_lines(track, track.fixes[0], "knots", entry)
assert not any(flag for _text, flag in rows if _text == "B739 N904DN")
assert dict(rows)["B739 N904DN"] == ""
# ---------------------------------------------------------------------------
@ -1209,3 +1249,314 @@ def test_a_route_it_could_be_flying_is_drawn():
said = [text for text, _flag in
fm.label_lines(track, track.fixes[0], "knots", entry)]
assert "KLAX" in said and "KDFW" in said
# ---------------------------------------------------------------------------
# What sort of aircraft it is
# ---------------------------------------------------------------------------
def test_the_label_says_what_sort_of_aircraft_it_is():
"""It comes off the air: the three bits under an identification
message's type code, which every aircraft sends with its callsign."""
track = straight()
track.category = "heavy"
said = [text for text, _flag in fm.label_lines(track, track.fixes[0],
"knots", None)]
assert "heavy" in said
def test_a_military_address_says_so_beside_the_aircraft():
"""No aircraft broadcasts that it is military -- a tanker calls itself
"heavy" exactly as an airliner does -- so it is read off the address."""
track = straight(icao="AE07D3") # a United States military block
track.category = "heavy"
said = [text for text, _flag in fm.label_lines(track, track.fixes[0],
"knots", None)]
assert "military heavy" in said
plain = straight(icao="A12345") # the civil part of the same range
plain.category = "heavy"
assert "heavy" in [t for t, _f in fm.label_lines(plain, plain.fixes[0],
"knots", None)]
assert "military heavy" not in [t for t, _f in
fm.label_lines(plain, plain.fixes[0],
"knots", None)]
def test_an_aircraft_that_says_nothing_about_itself_is_not_given_a_class():
track = straight()
assert not any(t in ("heavy", "large", "light") for t, _f in
fm.label_lines(track, track.fixes[0], "knots", None))
def test_the_class_carries_the_flag_so_the_type_line_need_not():
"""One flag per aircraft, on the first row that says what it is."""
track = straight()
track.category = "large"
rows = fm.label_lines(track, track.fixes[0], "knots", _Entry())
flags = [(text, flag) for text, flag in rows if flag]
assert ("large", "IE") in flags
assert dict(rows)["B739 N904DN"] == ""
# ---------------------------------------------------------------------------
# A label that has to move swings there
# ---------------------------------------------------------------------------
def test_the_label_glide_moves_towards_the_target_and_arrives():
here = (0.0, 0.0)
for _ in range(40):
here = fm._glide(here, (120.0, -80.0), 0.05, fm.LABEL_GLIDE)
assert 0.0 <= here[0] <= 120.0 and -80.0 <= here[1] <= 0.0
assert here == (120.0, -80.0)
def test_the_label_glide_is_the_same_swing_at_any_frame_rate():
fast = slow = (0.0, 0.0)
for _ in range(8):
fast = fm._glide(fast, (200.0, 0.0), 0.025, fm.LABEL_GLIDE)
for _ in range(2):
slow = fm._glide(slow, (200.0, 0.0), 0.1, fm.LABEL_GLIDE)
assert abs(fast[0] - slow[0]) < 1.0
def test_a_label_keeps_the_place_it_has():
"""The reason labels stay still: one is only moved when its own place
has actually been taken, never because the placer would now prefer a
different one."""
places = fm.LabelPlaces()
places.settle("ABC123", 100, 100, (160, 90))
kept = places.kept("ABC123", 104, 100, lambda bx, by: (int(bx), int(by)))
assert kept == (164, 90), "it did not travel with its aircraft"
def test_a_label_whose_place_is_taken_is_sent_looking():
places = fm.LabelPlaces()
places.settle("ABC123", 100, 100, (160, 90))
assert places.kept("ABC123", 100, 100, lambda bx, by: None) is None
def test_a_label_that_has_to_move_swings_rather_than_jumps():
places = fm.LabelPlaces()
places.settle("ABC123", 0, 0, (100, 100))
assert places.drawn("ABC123", 0, 0, (100, 100), 0.08) == (100, 100)
part = places.drawn("ABC123", 0, 0, (300, 240), 0.08)
assert part != (300, 240), "it jumped the whole way in one frame"
assert 100 < part[0] < 300
for _ in range(40):
part = places.drawn("ABC123", 0, 0, (300, 240), 0.08)
assert part == (300, 240)
def test_a_label_is_forgotten_when_its_aircraft_goes():
"""Otherwise one that comes back glides in from wherever it stood half
an hour ago, across the whole picture."""
places = fm.LabelPlaces()
places.begin()
places.settle("ABC123", 0, 0, (100, 100))
places.drawn("ABC123", 0, 0, (100, 100), 0.08)
places.end()
assert "ABC123" in places.at
places.begin()
places.end()
assert places.at == {} and places.want == {}
def test_a_label_swings_across_a_real_frame_rather_than_jumping():
"""The same easing the window does, wired through a drawn frame: the
label is somewhere between where it was and where it now belongs, and
what is spoken for is where it is going."""
track = straight()
# A canvas with room around the aircraft, so that a displaced label is
# displaced rather than pushed off the edge and refused.
view = fm.fit([track], width=800, box=(50.0, -3.0, 52.0, 3.0))
base = fm.background(view, unit="knots")
places = fm.LabelPlaces()
when = track.fixes[0].at
fm.render_frame(base, view, [track], when, labels=True, unit="knots",
places=places, step=1.0 / 12.0)
settled = places.want[track.icao]
assert places.at[track.icao] == (float(settled[0]), float(settled[1]))
# Push its place a long way, as a crowd of aircraft arriving would.
places.want[track.icao] = (settled[0] - 120, settled[1] + 90)
after = fm.render_frame(base, view, [track], when, labels=True,
unit="knots", places=places, step=1.0 / 12.0)
target = places.want[track.icao]
now_at = places.at[track.icao]
assert target != settled, "the test did not displace it"
assert now_at != (float(settled[0]), float(settled[1])), "it did not move"
assert now_at != (float(target[0]), float(target[1])), \
"it jumped the whole way in one frame"
part = (now_at[0] - settled[0]) / (target[0] - settled[0])
assert 0.05 < part < 0.60, f"one frame carried it {part:.0%} of the way"
# And it gets there, given the frames.
for _ in range(30):
fm.render_frame(base, view, [track], when, labels=True, unit="knots",
places=places, step=1.0 / 12.0)
assert places.at[track.icao] == (float(places.want[track.icao][0]),
float(places.want[track.icao][1]))
assert after.shape == base.shape
def test_a_still_picture_places_its_labels_exactly_as_it_always_did():
"""There is no frame before a still, so there is nothing to keep and
nothing to swing: the placing has to be untouched."""
track = straight()
view = fm.fit([track], width=800)
base = fm.background(view, unit="knots")
when = track.fixes[0].at
plain = fm.render_frame(base, view, [track], when, labels=True,
unit="knots", project=False)
again = fm.render_frame(base, view, [track], when, labels=True,
unit="knots", project=False)
assert np.array_equal(plain, again)
def test_the_height_does_not_claim_to_know_a_foot_it_was_not_told():
"""Most moments in an animation are between two reports and the height
at them is interpolated. Mode S reports altitude in twenty-five foot
steps, so a real reading survives untouched and an invented one stops
pretending to be exact."""
track = straight(altitude=37_675)
fix = track.fixes[0]
assert fm.label_lines(track, fix, "knots", None)[0][0] \
.startswith("37,675 ft")
from dataclasses import replace
between = replace(fix, altitude_ft=37_699)
assert fm.label_lines(track, between, "knots", None)[0][0] \
.startswith("37,700 ft")
# ---------------------------------------------------------------------------
# The box fades with the aircraft
# ---------------------------------------------------------------------------
def test_the_fade_level_follows_the_strength():
assert fm.fade_level(1.0) == 0
assert fm.fade_level(0.5) == 1
assert fm.fade_level(0.3) == 2
assert fm.fade_level(0.05) == 3
def test_each_fade_step_of_the_row_grey_is_darker_than_the_last():
greys = [fm.PALETTE[fm.LABEL_INK + i].astype(int).sum() for i in range(4)]
assert greys == sorted(greys, reverse=True)
assert greys[0] > greys[-1] * 3, "the last step is barely dimmer"
def test_each_fade_step_of_a_flag_colour_is_darker_than_the_last():
for letter in ("r", "w", "b"):
shades = [fm.PALETTE[fm.flag_index(letter, level)].astype(int).sum()
for level in range(4)]
assert shades == sorted(shades, reverse=True), letter
def test_a_fading_label_is_drawn_fainter_than_a_full_one():
"""The name already faded, because it is drawn in the aircraft's own
colour. The rows and the flag were fixed colours, so the brightest
thing left on that part of the picture was the one aeroplane nothing
had been heard from."""
track = straight()
view = fm.fit([track], width=800, box=(50.0, -3.0, 52.0, 3.0))
base = fm.background(view, unit="knots")
entry = _Entry()
def rows_of(strength):
img = base.copy()
fm._label(img, 300, 200, track, track.fixes[0], fm.RAMP, [], "knots",
entry=entry, strength=strength)
drawn = img != base
return fm.PALETTE[img[drawn]].astype(int).sum()
full = rows_of(1.0)
half = rows_of(0.5)
nearly_gone = rows_of(0.05)
assert half < full, "a fading label was as bright as a full one"
assert nearly_gone < half
def _label_pixels(strength, entry=None):
"""One label drawn at a strength, as the palette indices it used."""
track = straight()
track.category = "large"
view = fm.fit([track], width=800, box=(50.0, -3.0, 52.0, 3.0))
base = fm.background(view, unit="knots")
img = base.copy()
fm._label(img, 300, 200, track, track.fixes[0], fm.RAMP, [], "knots",
entry=entry if entry is not None else _Entry(),
strength=strength)
return set(np.unique(img[img != base]).tolist())
def test_the_rows_are_drawn_in_the_grey_for_the_strength_they_are_at():
"""Not merely dimmer on average -- the label has a name in it that
fades on its own -- but each row written in the grey that belongs to
how far the aircraft has faded."""
full = _label_pixels(1.0)
assert fm.LABEL_INK + 0 in full
for strength, level in ((0.5, 1), (0.3, 2), (0.05, 3)):
used = _label_pixels(strength)
assert fm.LABEL_INK + level in used, strength
assert not any(fm.LABEL_INK + other in used
for other in range(4) if other != level), strength
def test_the_flag_on_a_label_is_drawn_at_the_labels_own_fade_step():
from bandsaunter.flags import COLOUR_ORDER
wide = len(COLOUR_ORDER)
full = _label_pixels(1.0)
assert any(fm.FLAG <= i < fm.FLAG + wide for i in full), "no flag drawn"
for strength, level in ((0.5, 1), (0.3, 2), (0.05, 3)):
used = _label_pixels(strength)
assert not any(fm.FLAG <= i < fm.FLAG + wide for i in used), \
f"a full-strength flag on a label faded to {strength}"
want = fm.FLAG_FADED + (level - 1) * wide
assert any(want <= i < want + wide for i in used), strength
def test_a_flag_on_a_fading_label_fades_with_it():
from bandsaunter.flags import FLAG_H, FLAG_W
bright = np.full((40, 60), fm.BG, dtype=np.uint8)
faint = np.full((40, 60), fm.BG, dtype=np.uint8)
fm.draw_flag(bright, 5, 5, "US", 0)
fm.draw_flag(faint, 5, 5, "US", 3)
patch = (slice(5, 5 + FLAG_H), slice(5, 5 + FLAG_W))
assert fm.PALETTE[faint[patch]].astype(int).sum() < \
fm.PALETTE[bright[patch]].astype(int).sum()
def test_a_named_country_with_no_flag_fades_too():
faint = np.full((40, 60), fm.BG, dtype=np.uint8)
bright = np.full((40, 60), fm.BG, dtype=np.uint8)
fm.draw_flag(bright, 5, 5, "ZZ", 0)
fm.draw_flag(faint, 5, 5, "ZZ", 3)
assert fm.PALETTE[faint].astype(int).sum() < \
fm.PALETTE[bright].astype(int).sum()
def test_an_airport_cannot_be_mistaken_for_an_aircraft():
"""The old amber sat sixteen units of CIELAB from the ramp's yellow,
which is to say it was the same colour: an aeroplane low over a field
was drawn in the field's own colour and neither could be picked out.
Stated as the property rather than as the colour, so that changing the
altitude ramp cannot quietly walk an aircraft back into the airports.
"""
def lab(rgb):
c = np.asarray(rgb, float) / 255.0
c = np.where(c > 0.04045, ((c + 0.055) / 1.055) ** 2.4, c / 12.92)
m = np.array([[0.4124, 0.3576, 0.1805], [0.2126, 0.7152, 0.0722],
[0.0193, 0.1192, 0.9505]])
xyz = (c @ m.T) / np.array([0.9505, 1.0, 1.089])
f = np.where(xyz > 0.008856, np.cbrt(xyz), 7.787 * xyz + 16 / 116)
return np.array([116 * f[1] - 16, 500 * (f[0] - f[1]),
200 * (f[1] - f[2])])
airport = lab(fm.PALETTE[fm.AIRPORT])
apart = min(float(np.linalg.norm(airport - lab(fm.PALETTE[fm.RAMP + i])))
for i in range(fm.RAMP_STEPS))
assert apart > 40, (f"the airport colour is {apart:.0f} units from the "
f"nearest altitude colour; under about 25 they read "
f"as the same colour")