#!/usr/bin/env python3
"""Rebuild a range-only teaching figure from NASA/TP-2001-210801 Figure 24 text."""
from pathlib import Path
import csv

HERE = Path(__file__).resolve().parent
SITE = HERE.parents[1]
DATA = SITE / "dist/hover/inlet/pulse-mhd-energy-range.csv"
OUT = SITE / "dist/hover/inlet/pulse-mhd-energy-range.svg"

with DATA.open(newline="", encoding="utf-8") as stream:
    rows = {row["quantity"]: row for row in csv.DictReader(stream)}
low = float(rows["energy_density_low"]["value"])
high = float(rows["energy_density_high"]["value"])
assert (low, high) == (10.0, 1000.0)

svg = f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1120 540" role="img" aria-labelledby="title desc">
<title id="title">Reported energy-density range of a pulse-detonation MHD generator</title>
<desc id="desc">NASA reports measured electrical energy density from 10 to 1000 joules per cubic metre per detonation across effective magnetic-induction settings from 0.6 to 4.2 tesla. The chart displays only the published range, not individual measurements. Physical applied fields were 0.6 and 0.95 tesla; an active loading circuit simulated higher effective fields.</desc>
<rect width="1120" height="540" rx="20" fill="#f4f7fb"/>
<text x="56" y="57" font-family="Arial,sans-serif" font-size="27" font-weight="700" fill="#132b45">What the single-pulse MHD test reported</text>
<text x="56" y="91" font-family="Arial,sans-serif" font-size="17" fill="#41556d">Published span only — no machine-readable point table was supplied</text>
<text x="68" y="149" font-family="Arial,sans-serif" font-size="18" font-weight="700" fill="#132b45">Electrical energy per active channel volume, per detonation (J/m³)</text>
<line x1="155" y1="262" x2="960" y2="262" stroke="#4b6077" stroke-width="3"/>
<g font-family="Arial,sans-serif" font-size="16" fill="#41556d" text-anchor="middle">
<line x1="155" y1="249" x2="155" y2="277" stroke="#4b6077" stroke-width="2"/><text x="155" y="305">1</text>
<line x1="356" y1="249" x2="356" y2="277" stroke="#4b6077" stroke-width="2"/><text x="356" y="305">10</text>
<line x1="558" y1="249" x2="558" y2="277" stroke="#4b6077" stroke-width="2"/><text x="558" y="305">100</text>
<line x1="759" y1="249" x2="759" y2="277" stroke="#4b6077" stroke-width="2"/><text x="759" y="305">1,000</text>
<line x1="960" y1="249" x2="960" y2="277" stroke="#4b6077" stroke-width="2"/><text x="960" y="305">10,000</text></g>
<rect x="356" y="196" width="403" height="52" rx="12" fill="#7f56d9"/>
<text x="557" y="228" text-anchor="middle" font-family="Arial,sans-serif" font-size="20" font-weight="700" fill="#fff">reported measured range: 10 to 1,000</text>
<text x="155" y="351" font-family="Arial,sans-serif" font-size="17" fill="#41556d">Logarithmic scale · range across multiple settings, not a curve linking each field setting to one value</text>
<rect x="56" y="387" width="1008" height="112" rx="14" fill="#e5edf7"/>
<text x="80" y="424" font-family="Arial,sans-serif" font-size="18" font-weight="700" fill="#132b45">Field boundary</text>
<text x="80" y="457" font-family="Arial,sans-serif" font-size="17" fill="#243b55">Effective settings: 0.6–4.2 T</text>
<text x="450" y="457" font-family="Arial,sans-serif" font-size="17" fill="#243b55">Applied field: 0.6 T and 0.95 T; an active loading circuit simulated higher effective induction.</text>
<text x="56" y="523" font-family="Arial,sans-serif" font-size="14" fill="#5a6878">Source: NASA/TP-2001-210801, printed p. 33, Figure 24. Individual points are not digitized here.</text>
</svg>'''
OUT.write_text(svg, encoding="utf-8")
print(f"Wrote {OUT} from the source-bounded range table.")
