- collecte : collecter_meteofrance, extraire_infoclimat, extraire_vp2, archiver_historique, importer_opendata ; WeatherLink allégé (alleger) - tests : meteofrance, infoclimat, vp2, archive, opendata (tous verts) - maquettes/accueil-carte : sources de la maquette (générateurs de tuiles, page, À propos, CGU, confidentialité) - forum : noyau local (rôles, droits, SQLite, serveur de test, 18 tests) - deploy : Caddyfile.vercors.me.v2 (non appliqué) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
61 lignes
2.6 KiB
Python
61 lignes
2.6 KiB
Python
# Fond large et léger autour du massif (flouté sur la page) : même projection que carte.json.
|
|
import json, math
|
|
import numpy as np
|
|
import contourpy
|
|
from pnr import rdp, f
|
|
|
|
c = json.load(open('carte.json', encoding='utf-8'))
|
|
K, M, LON0, LAT1 = c['k'], c['m'], c['lon0'], c['lat1']
|
|
proj = lambda lon, lat: ((lon - LON0) * K * M, (LAT1 - lat) * M)
|
|
|
|
GLAT0, GLAT1, GLON0, GLON1 = 44.00, 46.00, 4.10, 6.80
|
|
H, W = 1150, 1100
|
|
z = np.fromfile('large.bil', '<f4').reshape(H, W).astype(np.float64)
|
|
z[z < -100] = 0 # hors couverture (hors France) : plaine
|
|
|
|
def blur(a, s):
|
|
r = int(3 * s)
|
|
k = np.exp(-0.5 * (np.arange(-r, r + 1) / s) ** 2); k /= k.sum()
|
|
p = np.pad(a, r, mode='edge')
|
|
p = np.apply_along_axis(lambda v: np.convolve(v, k, 'valid'), 0, p)
|
|
return np.apply_along_axis(lambda v: np.convolve(v, k, 'valid'), 1, p)
|
|
|
|
zs = blur(z, 1.8)
|
|
X = np.array([proj(GLON0 + (j + 0.5) / W * (GLON1 - GLON0), 0)[0] for j in range(W)])
|
|
Y = np.array([proj(0, GLAT1 - (i + 0.5) / H * (GLAT1 - GLAT0))[1] for i in range(H)])
|
|
|
|
def path(lines, eps, closed=False, minlen=3):
|
|
out = []
|
|
for p in lines:
|
|
if len(p) < minlen:
|
|
continue
|
|
s = rdp(np.asarray(p), eps)
|
|
if len(s) < 2 or (closed and len(s) < 4):
|
|
continue
|
|
out.append('M' + 'L'.join(f'{f(x)} {f(y)}' for x, y in s) + ('Z' if closed else ''))
|
|
return ''.join(out)
|
|
|
|
gen = contourpy.contour_generator(X, Y, zs, fill_type='OuterOffset', line_type='Separate')
|
|
teintes = []
|
|
for t in (500, 900, 1300, 1700, 2000, 2200):
|
|
polys, offs = gen.filled(t, 1e5)
|
|
rings = [pts[a:b] for pts, off in zip(polys, offs) for a, b in zip(off[:-1], off[1:]) if b - a >= 6]
|
|
teintes.append([t, path(rings, 2.2, closed=True, minlen=6)])
|
|
courbes = path([l for t in range(400, 4800, 400) for l in gen.lines(t) if len(l) >= 8], 2.0)
|
|
|
|
# fleuves : tronçons du réseau IGN (BD TOPO), plus de 50 m de large puis 15 à 50 m
|
|
def troncons(fichier):
|
|
out = []
|
|
for ft in json.load(open(fichier, encoding='utf-8'))['features']:
|
|
g = ft['geometry']
|
|
for ligne in (g['coordinates'] if g['type'] == 'MultiLineString' else [g['coordinates']]):
|
|
out.append(np.array([proj(lo, la) for lo, la, *_ in ligne]))
|
|
return out
|
|
rivieres = path(troncons('th2.json'), 0.6, minlen=2)
|
|
moyennes = path(troncons('th.json'), 1.4, minlen=2)
|
|
|
|
x0, y0 = proj(GLON0, GLAT1); x1, y1 = proj(GLON1, GLAT0)
|
|
json.dump({'cadre': [round(x0), round(y0), round(x1 - x0), round(y1 - y0)], 'teintes': teintes,
|
|
'courbes': courbes, 'rivieres': rivieres, 'moyennes': moyennes}, open('large.json', 'w', encoding='utf-8'))
|
|
print('large', [len(d) for _, d in teintes], len(courbes), len(rivieres), len(moyennes))
|