Performance optimizations and rendering improvements

GPU multi-processing fix:
- gpu.py: revert to CUDA_VISIBLE_DEVICES approach with lazy CuPy init
  (Device.use() caused CUDA_ERROR_NO_BINARY_FOR_GPU on GPU 1)
- CuPy is imported lazily on first to_gpu() call, allowing
  CUDA_VISIBLE_DEVICES to be set before CUDA context creation
- nvidia-smi used for GPU count detection (no CUDA import needed)
- pipeline.py: add tip message suggesting -w N when multiple GPUs detected

Rendering improvements:
- Title: split into bold title (14pt) + italic description (10pt)
- North arrow: moved inside data area (top-right) with transparent
  background — no longer overlaps title
- Colorbar: full height (compass gap removed), ScalarFormatter with
  useOffset=False to prevent scientific notation on small values

Performance:
- rendering.py: save matplotlib figure to BytesIO instead of temp PNG
  file — eliminates disk I/O between matplotlib and PIL
- visualizations.py: cap max_dist at 300 for ray-tracing (SVF,
  openness, aniso_open) — avoids 500+ iterations at 0.2m resolution
- pipeline.py: deduplicate n_gpus calculation in parallel path
This commit is contained in:
Antoine Jacquin
2026-05-15 12:32:51 +02:00
parent a3f7b44874
commit 30122c71ed
3 changed files with 15 additions and 11 deletions

View File

@ -743,21 +743,22 @@ def tif_to_png(tif_file, vis_dir, resolution, keep_tif=False, source_info=None,
fig.patch.set_facecolor('white')
# Save as PNG then convert to final format — fixed layout, no bbox_inches='tight'
# Save figure to in-memory buffer (avoids disk I/O of temp PNG)
save_dpi = 200 if width > 3000 else 150
png_temp = vis_dir / f"{tif_file.stem}_temp.png"
from io import BytesIO
buf = BytesIO()
try:
plt.savefig(png_temp, dpi=save_dpi, facecolor='white', format='png')
plt.savefig(buf, dpi=save_dpi, facecolor='white', format='png')
finally:
plt.close()
buf.seek(0)
img = PILImage.open(str(png_temp))
img = PILImage.open(buf)
pil_format = 'AVIF' if output_format == 'avif' else 'WEBP'
if quality >= 100:
img.save(str(output_file), format=pil_format, lossless=True)
else:
img.save(str(output_file), format=pil_format, quality=quality)
png_temp.unlink(missing_ok=True)
# Delete source TIFF (unless --keep-tif)
if not keep_tif: