import copy
import functools
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
BASE_CFG = {
"planet": {"radius_km": 12742.0, "gravity_g": 1.05, "day_hours": 31.149, "year_days": 216,
"tilt_deg": 20.0, "sea_level_pressure_bar": 1.0, "scale_height_km": 8.0, "o2_fraction": 0.21},
"build": {"seed": 7, "res_dev": 2, "res_final": 2, "raster_width": 256, "preview_width": 128,
"land_fraction": 0.22},
}
@functools.lru_cache(maxsize=4)
def small_grid(res: int = 2):
from mapgen.grid import build_grid
return build_grid(res, 12742.0)
def make_ctx(res=2, data=None, cfg=None, tect=None, root=None):
from mapgen.pipeline import Ctx
c = copy.deepcopy(BASE_CFG)
for sec, vals in (cfg or {}).items():
c.setdefault(sec, {}).update(vals)
ctx = Ctx(root or ROOT, c, tect or {"plate": []}, res)
ctx.grid = small_grid(res)
ctx.data = dict(data or {})
return ctx
def big_river(a) -> int:
"""The cell of the biggest river that flows on over land (not into a lake at its own level, which cuts no
valley, nor off a coast, like a basin lake's spillway): the fixtures' river."""
import numpy as np
river, lake = np.asarray(a["river"]).astype(bool), np.asarray(a["lake"]).astype(bool)
recv = np.asarray(a["recv"])
wet = lake | np.asarray(a["ocean"]).astype(bool)
return int(np.argmax(np.asarray(a["discharge_km3_yr"]) * (river & ~wet & ~wet[recv])))