From 326130271fe3fb2a80a8374c454491b2444bf603 Mon Sep 17 00:00:00 2001 From: Scott Staniewicz Date: Wed, 30 Aug 2023 11:29:05 -0400 Subject: [PATCH] set `gdal.UseExceptions` so that `open_raster` throws `RuntimeError` Right now an attribute error gets thrown only if no code has called `UseExceptions`. closes #206 --- src/compass/utils/helpers.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compass/utils/helpers.py b/src/compass/utils/helpers.py index cefef985..ab7e62dc 100644 --- a/src/compass/utils/helpers.py +++ b/src/compass/utils/helpers.py @@ -15,6 +15,7 @@ import compass +gdal.UseExceptions() WORKFLOW_SCRIPTS_DIR = os.path.dirname(compass.__file__) OPERA_OPERATION_CONTACT_EMAIL = 'opera-sds-ops@jpl.nasa.gov' @@ -351,7 +352,7 @@ def open_raster(filename, band=1): ds = gdal.Open(filename, gdal.GA_ReadOnly) arr = ds.GetRasterBand(band).ReadAsArray() return arr - except AttributeError: + except RuntimeError: # GDAL reads 1st 2 bytes of ENVI binary to determine file type. If 1st # bytes of flat binary is that of a jpeg but the binary is not then # GDAL throws a libjpeg runtime error. Follow specifically tries to