diff --git a/tests/test_coastal_vulnerability.py b/tests/test_coastal_vulnerability.py index 9f3f7b51d2..8d8a6a37d2 100644 --- a/tests/test_coastal_vulnerability.py +++ b/tests/test_coastal_vulnerability.py @@ -224,27 +224,29 @@ def test_extract_bathymetry(self): projection_wkt = srs.ExportToWkt() geotransform = [0, 1.0, 0.0, 0, 0.0, -1.0] n = 5 - nodata_val = 9999 + band1_nodata = numpy.nan gtiff_driver = gdal.GetDriverByName('GTiff') new_raster = gtiff_driver.Create( - raster_path, n, n, 2, gdal.GDT_Int32, options=[ + raster_path, n, n, 2, gdal.GDT_Float32, options=[ 'TILED=YES', 'BIGTIFF=YES', 'COMPRESS=LZW', 'BLOCKXSIZE=16', 'BLOCKYSIZE=16']) new_raster.SetProjection(projection_wkt) new_raster.SetGeoTransform(geotransform) - array = numpy.array([-1]*n*n).reshape((n, n)) + valid_value = -10.0 + array = numpy.array([valid_value]*n*n).reshape((n, n)) # nodata across the top row for Band 1 new_band = new_raster.GetRasterBand(1) - array[:1] = nodata_val + array[:1] = band1_nodata new_band.WriteArray(array) - new_band.SetNoDataValue(nodata_val) + new_band.SetNoDataValue(band1_nodata) # all nodata for Band 2 + band2_nodata = 999.99 nodata_band = new_raster.GetRasterBand(2) - array[:] = nodata_val + array[:] = band2_nodata nodata_band.WriteArray(array) - nodata_band.SetNoDataValue(nodata_val) + nodata_band.SetNoDataValue(band2_nodata) new_raster.FlushCache() new_band = None @@ -276,25 +278,25 @@ def test_extract_bathymetry(self): band = raster.GetRasterBand(1) # nodata across top row values = coastal_vulnerability.extract_bathymetry_along_ray( - all_valid_ray, geotransform, nodata_val, band) - self.assertTrue(numpy.mean(values) == -1) + all_valid_ray, geotransform, band1_nodata, band) + self.assertEqual(numpy.mean(values), valid_value) values = coastal_vulnerability.extract_bathymetry_along_ray( - some_nodata_ray, geotransform, nodata_val, band) - self.assertTrue(numpy.mean(values) == -1) + some_nodata_ray, geotransform, band1_nodata, band) + self.assertEqual(numpy.mean(values), valid_value) values = coastal_vulnerability.extract_bathymetry_along_ray( - all_nodata_ray, geotransform, nodata_val, band) - self.assertTrue(numpy.mean(values) == -1) + all_nodata_ray, geotransform, band1_nodata, band) + self.assertEqual(numpy.mean(values), valid_value) with self.assertRaises(ValueError): values = coastal_vulnerability.extract_bathymetry_along_ray( - out_of_bounds_ray, geotransform, nodata_val, band) + out_of_bounds_ray, geotransform, band1_nodata, band) nodata_band = raster.GetRasterBand(2) # all nodata band with self.assertRaises(ValueError): values = coastal_vulnerability.extract_bathymetry_along_ray( - all_valid_ray, geotransform, nodata_val, nodata_band) + all_valid_ray, geotransform, band2_nodata, nodata_band) raster = None band = None