Rendu: zones NaN transparentes au lieu d'interpolation DTM

L'interpolation fillnodata du DTM générait des artefacts visuels
(zones lissées artificielles). Revenu au DTM avec NaN conservés.

Nouvelle approche pour le rendu:
- NaN remplacés par la médiane des valeurs valides (valeur neutre)
- Après application de la colormap, un masque alpha rend les zones
  NaN transparentes au lieu de les afficher
- interpolation='bilinear' sur imshow pour un rendu lisse
- Figure adaptative: 20-40 pouces selon la taille des données
- DPI 200 pour les images > 3000px

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jacquin Antoine
2026-05-10 11:56:11 +02:00
parent 8e4b4bb10b
commit fd965e512c
2 changed files with 29 additions and 19 deletions

View File

@ -323,13 +323,36 @@ def tif_to_png(tif_file, vis_dir, resolution):
valid_data = np.asarray(data.compressed() if hasattr(data, 'compressed') else data.flatten())
valid_data = valid_data[~np.isnan(valid_data)]
# Convert MaskedArray to plain ndarray (NaN-filled) to avoid numpy warnings
if isinstance(data, np.ma.MaskedArray):
data = np.ma.filled(data, np.nan)
# Track NaN mask before converting to plain ndarray
nan_mask = None
if not is_rgb:
if isinstance(data, np.ma.MaskedArray):
nan_mask = data.mask.copy()
data = np.ma.filled(data, np.nan)
elif np.any(np.isnan(data)):
nan_mask = np.isnan(data)
# For rendering: replace NaN with neutral value to avoid interpolation halos
if nan_mask is not None and np.any(nan_mask) and len(valid_data) > 0:
fill_value = float(np.median(valid_data))
data[nan_mask] = fill_value
nan_mask = nan_mask # keep for later
# Apply colormap
data, cmap, title, legend_label, description, is_rgb_result = _apply_colormap(data, tif_file)
# Apply NaN mask: make zones without data transparent
has_nan_mask = nan_mask is not None and not is_rgb_result
if has_nan_mask:
# data is normalized 0-1 from _apply_colormap; apply cmap to get RGBA
cmap_obj = plt.get_cmap(cmap) if isinstance(cmap, str) else cmap
rgba = cmap_obj(data) # (H, W, 4) float RGBA
rgba[nan_mask, 3] = 0.0 # transparent where no data
data = rgba
is_rgba = True
else:
is_rgba = False
# Create figure — adapt width to data resolution for sharp rendering
# At high res (5000+px wide), we need a larger figure to avoid downsampling artifacts
fig_width = max(20, width / 150)
@ -342,7 +365,7 @@ def tif_to_png(tif_file, vis_dir, resolution):
left=0.06, right=0.88, top=0.93, bottom=0.08)
ax = fig.add_subplot(gs[0])
if is_rgb:
if is_rgba or is_rgb:
im = ax.imshow(data, aspect='equal', origin='upper',
interpolation='bilinear')
else: