File size: 1,756 Bytes
d624b50 d084ae4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #!/usr/bin/env python3
"""Paint the coarse travel-time preview (from access_pipeline.py) as an equirectangular PNG for the globe overlay."""
import sys, numpy as np
from pathlib import Path
from PIL import Image
BASE=Path(__file__).resolve().parent
STOPS=[(0,'#fff7d6'),(10,'#f9e3a1'),(30,'#f0b25a'),(60,'#d97a35'),(120,'#a9452c'),(240,'#6b2424'),(480,'#3a1414'),(1440,'#1a0a0a')]
def hexrgb(h): return np.array([int(h[i:i+2],16) for i in (1,3,5)],dtype=np.float32)
def colorize(tt):
out=np.zeros(tt.shape+(4,),dtype=np.uint8); valid=np.isfinite(tt)
x=np.log1p(np.clip(np.where(valid,tt,0),0,1440)); xs=np.log1p(np.array([s[0] for s in STOPS],dtype=np.float32)); cols=np.stack([hexrgb(s[1]) for s in STOPS])
for k in range(3): out[...,k]=np.interp(x,xs,cols[:,k]).astype(np.uint8)
out[...,3]=np.where(valid,235,0).astype(np.uint8); return out
for surface in sys.argv[1:] or ['motorized']:
src=BASE/'geo'/f'traveltime_{surface}_coarse.npy'
if not src.exists(): print('missing',src); continue
a=np.load(src) # rows cover lat 85..-60, cols -180..180, 10x aggregated 1 km (0.0833 deg)
rows,cols=a.shape; full=np.full((int(round(rows*180/145)),cols),np.nan,dtype=np.float32)
top=int(round((90-85)/180*full.shape[0])); full[top:top+rows,:]=a
img=Image.fromarray(colorize(full),'RGBA').resize((3072,1536),Image.BILINEAR).quantize(colors=96,method=Image.Quantize.FASTOCTREE)
dest=BASE/'assets'/f'traveltime-{surface}.png'; img.save(dest,optimize=True); print(dest, dest.stat().st_size)
import base64; b64=BASE/'assets'/f'traveltime-{surface}.b64.txt'; b64.write_text(base64.b64encode(dest.read_bytes()).decode()); print(b64, b64.stat().st_size, '(text copy: the Space is deployed through a text-only commit path)')
|