Files
settled-reach/tooling/domains/atlas/planet/sol_data/venus.py
T
jpmschweitzerandClaude Opus 5.5 668772075c refactor(tooling): T-1288 — planet-gen becomes reach atlas planet
The 30-file tree moves under atlas as its third rung (D-243), ten verbs
fronting it. Each verb restates its module's options so `--help` describes
something; tooling/test_planet_router.py hands every declared option to the
module's own argparse and fails on drift, and now runs in make test-tooling.

The 2026-09-02 half of this move had converted the top-level imports and the
repo roots. Finishing it found what the half-move left:

- Lazy in-function imports, and all of sol_data/, still named siblings bare.
  They resolved only through sys.path.insert hacks, so under reach the first
  globe render in generate, batch or sol-import would have raised
  ModuleNotFoundError. Qualified; the hacks are gone.
- 247 print() calls and a stdout progress writer that fired once per 8 KB
  block. Report verbs (audit, quality) write through console.out, progress
  through console.event, and download progress is throttled to 10% steps
  so a job log is not tens of thousands of lines.
- Every error exit raises ReachError with a fix.

Two checks that could not fail:

- batch --verify-determinism printed a warning and exited 0 on a mismatch.
- import-provinces exited 0 with errors > 0.

Both now raise. The 271-body bake is only safe to re-run because the first
one holds.

sol-import --body is action="append" in the module but the router took one
value, so --body GJ0d --body GJ0e kept one. Now repeatable, and _flags repeats
list options.

test_conformance walked one level, so a nested group was reported as a verb
missing @command and its ten verbs were never checked. It recurses now;
proven by stripping @command from `planet quality` and watching it fail.

Stray PNGs from the 2026-09-03 runaway router-test run are parked in
.cache/t1288-stray-pngs/, not committed. Their reliefmaps differ from HEAD
while the heightmap regenerated byte-identical — filed as T-1291.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-23 16:08:02 +02:00

123 lines
5.3 KiB
Python

"""
Venus (GJ0c) terrain builder.
Data source:
- Elevation: Magellan radar altimetry from USGS Astrogeology
Global topography at ~4.6 km/px, PDS format.
Venus properties:
- Surface: volcanic, extremely hot (~735K), dense CO2 atmosphere
- No liquid water, thick clouds
- Min elevation: ~-2000 m (lowlands)
- Max elevation: ~11000 m (Maxwell Montes on Ishtar Terra)
- planet_class: "volcanic", atmosphere: "toxic"
"""
import numpy as np
from tooling.domains.atlas.planet.sol_data.download import ensure_cached
from tooling.domains.atlas.planet.sol_data.shared import (
GRID_W, GRID_H,
load_tiff_as_array, load_raw_binary, resample_to_grid, normalize_01,
compute_hillshade, assemble_terrain,
temperature_grid_analytical,
)
from tooling.core import console
# Magellan topography — USGS GeoTIFF (reliable, PIL-loadable)
MAGELLAN_TIFF_URL = "https://planetarymaps.usgs.gov/mosaic/Venus_Magellan_Topography_Global_4641m_v02.tif"
MAGELLAN_TIFF_FILE = "Venus_Magellan_Topography_Global_4641m_v02.tif"
# PDS fallback (raw binary, dimensions may vary)
MAGELLAN_PDS_URL = "https://pds-geosciences.wustl.edu/mgn/mgn-v-rdrs-5-dim-v1/mg_3002/gedr/gtdr/gtdr_shtplt.img"
MAGELLAN_PDS_FILE = "venus_magellan_gtdr.img"
VENUS_MIN_ELEV_M = -2000.0
VENUS_MAX_ELEV_M = 11000.0
VENUS_SURFACE_TEMP_K = 735.0 # nearly uniform due to dense atmosphere
def _load_magellan() -> np.ndarray:
"""Load Magellan topography data."""
# Try USGS GeoTIFF first (reliable, well-defined format)
try:
path = ensure_cached(MAGELLAN_TIFF_URL, MAGELLAN_TIFF_FILE)
console.event(f" loading Magellan GeoTIFF: {path}")
arr = load_tiff_as_array(str(path))
# Handle nodata
arr[arr < -20000] = 0.0
arr[arr > 20000] = 0.0
console.event(f" Magellan shape: {arr.shape}, "
f"range: [{arr.min():.0f}, {arr.max():.0f}] m")
return arr
except Exception as e:
console.event(f" GeoTIFF failed ({e}), trying PDS binary...")
# PDS fallback — try common dimension/format combinations
try:
path = ensure_cached(MAGELLAN_PDS_URL, MAGELLAN_PDS_FILE)
console.event(f" loading Magellan PDS: {path}")
for w, h in [(4096, 2048), (2048, 1024), (8192, 4096)]:
try:
arr = load_raw_binary(str(path), w, h, dtype=">i2", offset=0)
arr[arr > 20000] = 0.0
arr[arr < -20000] = 0.0
console.event(f" Magellan PDS: {w}x{h}, range: [{arr.min():.0f}, {arr.max():.0f}]")
return arr
except ValueError:
continue
except Exception as e3:
console.event(f" PDS also failed ({e3})")
# All sources failed — fall through to procedural generation
console.event("all Magellan sources failed, using procedural", level="warn")
return None
def build_terrain(body_def: dict) -> dict:
"""Build Venus terrain dict from Magellan data."""
from tooling.domains.atlas.planet.planet_simulation import compute_biome
console.event(" Venus: loading Magellan data...")
# ── 1. Elevation ────────────────────────────────────────────────────
raw = _load_magellan()
if raw is None:
# Fall back to procedural simulation
from tooling.domains.atlas.planet.planet_simulation import simulate
return simulate(body_def)
from tooling.domains.atlas.planet.sol_data.shared import greenwich_to_dateline
shifted = greenwich_to_dateline(raw)
elevation_m = resample_to_grid(shifted, GRID_H, GRID_W, order=1)
elevation = normalize_01(elevation_m, VENUS_MIN_ELEV_M, VENUS_MAX_ELEV_M)
sea_level = 0.0
surface_water = np.zeros((GRID_H, GRID_W), dtype=bool)
# ── 2. Temperature ──────────────────────────────────────────────────
# Venus has nearly uniform surface temperature due to dense atmosphere
temperature_K = temperature_grid_analytical(
base_T_K=VENUS_SURFACE_TEMP_K,
elevation=elevation,
lapse_rate_K_per_unit=50.0, # slight cooling at altitude
lat_gradient_K=5.0, # almost no lat variation (thick atmo)
)
# ── 3. Moisture ─────────────────────────────────────────────────────
moisture = np.zeros((GRID_H, GRID_W), dtype=np.float32)
# ── 4. Biome ────────────────────────────────────────────────────────
biome = compute_biome(body_def, elevation, sea_level, surface_water,
temperature_K, moisture)
# ── 5. Hillshade ────────────────────────────────────────────────────
hillshade = compute_hillshade(elevation)
return assemble_terrain(
elevation=elevation, temperature_K=temperature_K,
moisture=moisture, biome=biome,
surface_water=surface_water, hillshade=hillshade,
rivers=[], sea_level=sea_level,
)