From e8b48fcddd7b161cee99e013f70302bfa82eb628 Mon Sep 17 00:00:00 2001 From: Alex Matulich Date: Mon, 12 May 2025 07:28:06 -0700 Subject: [PATCH] Added checks for necessary python libraries --- scripts/geotiff2scad.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/scripts/geotiff2scad.py b/scripts/geotiff2scad.py index a36d553e..e9098da5 100644 --- a/scripts/geotiff2scad.py +++ b/scripts/geotiff2scad.py @@ -24,10 +24,29 @@ # Some planetary datasets use planetocentric or planetographic projections — still usable for 2D mapping. +import sys + +def require_module(name, alias=None, install_hint=None): + try: + module = __import__(name) + if alias: + globals()[alias] = module + else: + globals()[name] = module + except ImportError: + print(f"Error: This script requires the '{name}' package.") + if install_hint: + print(f"Install it using: {install_hint}") + else: + print(f"Try: pip install {name}") + sys.exit(1) + +# Require necessary modules +require_module('rasterio', install_hint='pip install rasterio') +require_module('numpy', alias='np', install_hint='pip install numpy') + +# Standard, should always be available: import argparse -import numpy as np -import rasterio -from rasterio.enums import Resampling import json # ----------------------------