From bc9539e8017f4fe5a67d10f7f5e7396218b12f2c Mon Sep 17 00:00:00 2001 From: James S Klassen Date: Wed, 29 Jul 2026 15:53:04 -0500 Subject: [PATCH] Fix nodata handling in scenes2strips. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Old behavior: treat -100, 0, ±inf as nodata. New behavior (as per Ian): read nodata value from source raster, and treat ±inf as error. --- lib/scenes2strips.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/scenes2strips.py b/lib/scenes2strips.py index 120bd55..1d271de 100644 --- a/lib/scenes2strips.py +++ b/lib/scenes2strips.py @@ -51,6 +51,10 @@ class RasterDimensionError(Exception): def __init__(self, msg=""): super(Exception, self).__init__(msg) +class RasterValueError(Exception): + def __init__(self, msg=""): + super(Exception, self).__init__(msg) + class MetadataError(Exception): def __init__(self, msg=""): super(Exception, self).__init__(msg) @@ -1035,14 +1039,18 @@ def loadData(demFile, matchFile, orthoFile, ortho2File, maskFile, metaFile, targ demFile_srs = rat.extractRasterData(rat.openRaster(demFile), 'spat_ref') - z, x_dem, y_dem, spat_ref = rat.extractRasterData(rat.openRaster(demFile, target_srs, 'bilinear'), 'array', 'x', 'y', 'spat_ref') + z, x_dem, y_dem, spat_ref, nodata_val = rat.extractRasterData(rat.openRaster(demFile, target_srs, 'bilinear'), 'array', 'x', 'y', 'spat_ref', 'nodata_val') if spat_ref.IsSame(target_srs) != 1: raise SpatialRefError("DEM '{}' spatial reference ({}) mismatch with strip spatial reference ({})".format( demFile, spat_ref.ExportToProj4(), target_srs.ExportToProj4())) + # Fail if any input pixel is infinite + if np.any(np.isinf(z)): + #warnings.warn("DEM '{}' contains infinite values".format(demFile)) + raise RasterValueError("DEM '{}' contains infinite values".format(demFile)) + # A DEM pixel with a value of -9999 is a nodata pixel; interpret it as NaN. - # TODO: Ask Ian about the following interpretation of nodata values. - z[(z < -100) | (z == 0) | (z == -np.inf) | (z == np.inf)] = np.nan + z[(z == nodata_val) | np.isinf(z)] = np.nan check_srs = rat.extractRasterData(rat.openRaster(matchFile), 'spat_ref') if check_srs.IsSame(demFile_srs) != 1: