From 8f939e4988f5e30ed5e729c30fdd4b9a97006e2a Mon Sep 17 00:00:00 2001 From: Claudio Satriano Date: Mon, 27 Jan 2025 23:09:48 +0100 Subject: [PATCH] GeoTIFF: handle case when file is not georeferenced --- sourcespec/ssp_plot_stations.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/sourcespec/ssp_plot_stations.py b/sourcespec/ssp_plot_stations.py index 6aecb7ec..918d0735 100644 --- a/sourcespec/ssp_plot_stations.py +++ b/sourcespec/ssp_plot_stations.py @@ -332,14 +332,21 @@ def _add_geotiff(config, ax): 'Basemap will not be plotted.') return # pylint: disable=import-outside-toplevel - from rasterio.errors import RasterioError - try: - tif_raster, tif_bbox = _read_geotiff(tif_file, grayscale) - except (RasterioError, OSError) as msg: - logger.warning( - f'Error reading GeoTIFF file "{tif_file}": {msg}. ' - 'Basemap will not be plotted.') - return + from rasterio.errors import RasterioError, NotGeoreferencedWarning + with warnings.catch_warnings(): + warnings.simplefilter('error', NotGeoreferencedWarning) + try: + tif_raster, tif_bbox = _read_geotiff(tif_file, grayscale) + except (RasterioError, OSError) as msg: + logger.warning( + f'Error reading GeoTIFF file "{tif_file}": {msg}. ' + 'Basemap will not be plotted.') + return + except NotGeoreferencedWarning: + logger.warning( + f'GeoTIFF file "{tif_file}" is not georeferenced. ' + 'Basemap will not be plotted.') + return # Plot the raster if grayscale: ax.imshow(