#188 use assert_allclose for all approximate comparisons
This commit is contained in:
parent
f8954b189f
commit
a80ea73448
|
@ -64,7 +64,7 @@ def assert_raster_equal_value(base_raster_path, val_to_compare):
|
|||
|
||||
array_to_compare = numpy.empty(base_array.shape)
|
||||
array_to_compare.fill(val_to_compare)
|
||||
numpy.testing.assert_almost_equal(base_array, array_to_compare)
|
||||
numpy.testing.assert_allclose(base_array, array_to_compare, rtol=0, atol=1e-6)
|
||||
|
||||
|
||||
def make_pools_csv(pools_csv_path):
|
||||
|
|
|
@ -619,10 +619,10 @@ class TestModel(unittest.TestCase):
|
|||
# will properly propagate across the model. the npv raster was chosen
|
||||
# because the values are determined by multiple inputs, and any changes
|
||||
# in those inputs would propagate to this raster.
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
netseq_array, netseq_test, decimal=4)
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
npv_array, npv_test, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
netseq_array, netseq_test, rtol=0, atol=1e-6)
|
||||
numpy.testing.assert_allclose(
|
||||
npv_array, npv_test, rtol=0, atol=1e-6)
|
||||
|
||||
def test_model_run_2(self):
|
||||
"""Coastal Blue Carbon: Test CBC without analysis year."""
|
||||
|
@ -651,8 +651,8 @@ class TestModel(unittest.TestCase):
|
|||
# will properly propagate across the model. the npv raster was chosen
|
||||
# because the values are determined by multiple inputs, and any changes
|
||||
# in those inputs would propagate to this raster.
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
netseq_array, netseq_test, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
netseq_array, netseq_test, rtol=0, atol=1e-6)
|
||||
|
||||
def test_model_no_valuation(self):
|
||||
"""Coastal Blue Carbon: Test main model without valuation."""
|
||||
|
@ -682,8 +682,8 @@ class TestModel(unittest.TestCase):
|
|||
# will properly propagate across the model. the npv raster was chosen
|
||||
# because the values are determined by multiple inputs, and any changes
|
||||
# in those inputs would propagate to this raster.
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
netseq_array, netseq_test, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
netseq_array, netseq_test, rtol=0, atol=1e-6)
|
||||
|
||||
def test_binary(self):
|
||||
"""Coastal Blue Carbon: Test CBC model against InVEST-Data."""
|
||||
|
@ -738,7 +738,7 @@ class TestModel(unittest.TestCase):
|
|||
dtype=numpy.float32)
|
||||
|
||||
a.sort()
|
||||
numpy.testing.assert_array_almost_equal(u, a, decimal=2)
|
||||
numpy.testing.assert_allclose(u, a, rtol=1.5e-2, atol=0)
|
||||
|
||||
# walk through all files in the workspace and assert that outputs have
|
||||
# the file suffix.
|
||||
|
@ -962,7 +962,7 @@ class CBCRefactorTest(unittest.TestCase):
|
|||
lulc_matrix, reclass_map, out_dtype=numpy.float32,
|
||||
nodata_mask=lulc_nodata)
|
||||
|
||||
numpy.testing.assert_almost_equal(reclassified_array, expected_array)
|
||||
numpy.testing.assert_allclose(reclassified_array, expected_array, rtol=0, atol=1e-6)
|
||||
|
||||
|
||||
class CBCValidationTests(unittest.TestCase):
|
||||
|
|
|
@ -237,8 +237,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
D = -20.0 # fetch depth (meters)
|
||||
height = coastal_vulnerability.compute_wave_height(U, F, D)
|
||||
period = coastal_vulnerability.compute_wave_period(U, F, D)
|
||||
numpy.testing.assert_almost_equal(height, 1.0260516)
|
||||
numpy.testing.assert_almost_equal(period, 3.6288811)
|
||||
numpy.testing.assert_allclose(height, 1.0260516, rtol=0, atol=1e-6)
|
||||
numpy.testing.assert_allclose(period, 3.6288811, rtol=0, atol=1e-6)
|
||||
|
||||
# Test with U < 1 and expect U to be forced to 1.0
|
||||
F = 10000 # fetch distance (meters)
|
||||
|
@ -247,8 +247,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
heightB = coastal_vulnerability.compute_wave_height(1.0, F, D)
|
||||
periodA = coastal_vulnerability.compute_wave_period(0.0, F, D)
|
||||
periodB = coastal_vulnerability.compute_wave_period(1.0, F, D)
|
||||
numpy.testing.assert_almost_equal(heightA, heightB)
|
||||
numpy.testing.assert_almost_equal(periodA, periodB)
|
||||
numpy.testing.assert_allclose(heightA, heightB, rtol=0, atol=1e-6)
|
||||
numpy.testing.assert_allclose(periodA, periodB, rtol=0, atol=1e-6)
|
||||
|
||||
def test_habitat_rank(self):
|
||||
"""CV: regression test for habitat ranks."""
|
||||
|
@ -575,8 +575,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
actual_values = pickle.load(file)
|
||||
expected_values = numpy.array([numpy.nan])
|
||||
|
||||
numpy.testing.assert_almost_equal(
|
||||
list(actual_values.values()), expected_values, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
list(actual_values.values()), expected_values, rtol=0, atol=1.5e-4)
|
||||
|
||||
def test_slr_missing_field(self):
|
||||
"""CV: test KeyError raised if slr field is not present in vector."""
|
||||
|
@ -654,8 +654,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
|
||||
expected_values = numpy.array([6.5454, 12.0, 17.4545])
|
||||
|
||||
numpy.testing.assert_almost_equal(
|
||||
list(actual_values.values()), expected_values, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
list(actual_values.values()), expected_values, rtol=0, atol=1.5e-4)
|
||||
|
||||
def test_complete_run(self):
|
||||
"""CV: regression test for a complete run with all optional arguments."""
|
||||
|
@ -822,8 +822,8 @@ class CoastalVulnerabilityTests(unittest.TestCase):
|
|||
actual_values = pickle.load(file)
|
||||
|
||||
expected_values = numpy.array([numpy.nan])
|
||||
numpy.testing.assert_almost_equal(
|
||||
list(actual_values.values()), expected_values, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
list(actual_values.values()), expected_values, rtol=0, atol=1.5e-4)
|
||||
|
||||
def test_positive_dem_with_nodata_floats(self):
|
||||
"""CV: test coercing negative DEM values to zero.
|
||||
|
@ -1316,8 +1316,8 @@ def assert_pickled_arrays_almost_equal(
|
|||
expected_fids = [x[0] for x in sorted(expected_values_dict.items())]
|
||||
expected_values = [x[1] for x in sorted(expected_values_dict.items())]
|
||||
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
actual_values, expected_values, decimal=2)
|
||||
numpy.testing.assert_allclose(
|
||||
actual_values, expected_values, rtol=1.5e-2, atol=0)
|
||||
numpy.testing.assert_array_equal(actual_fids, expected_fids)
|
||||
|
||||
|
||||
|
|
|
@ -277,10 +277,10 @@ class GLOBIOTests(unittest.TestCase):
|
|||
fid = feature.GetFID()
|
||||
result_value = feature.GetField('msa_mean')
|
||||
if result_value is not None:
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
result_value,
|
||||
float(expected_results[fid]['msa_mean']),
|
||||
decimal=tolerance_places)
|
||||
rtol=0, atol=1.5 * 10**-tolerance_places)
|
||||
else:
|
||||
# the out-of-bounds polygon will have no result_value
|
||||
assert(expected_results[fid]['msa_mean'] == '')
|
||||
|
|
|
@ -234,7 +234,7 @@ def assert_array_sum(base_raster_path, desired_sum, include_nodata=True):
|
|||
base_array = base_array[~numpy.isclose(base_array, nodata)]
|
||||
|
||||
raster_sum = numpy.sum(base_array)
|
||||
numpy.testing.assert_almost_equal(raster_sum, desired_sum, decimal=3)
|
||||
numpy.testing.assert_allclose(raster_sum, desired_sum, rtol=0, atol=1.5e-3)
|
||||
|
||||
|
||||
class HabitatQualityTests(unittest.TestCase):
|
||||
|
@ -351,8 +351,8 @@ class HabitatQualityTests(unittest.TestCase):
|
|||
# LULC rasters.
|
||||
raster_info = pygeoprocessing.get_raster_info(raster_path)
|
||||
raster_bbox = raster_info['bounding_box']
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
raster_bbox, base_lulc_bbox)
|
||||
numpy.testing.assert_allclose(
|
||||
raster_bbox, base_lulc_bbox, rtol=0, atol=1e-6)
|
||||
|
||||
def test_habitat_quality_numeric_threats(self):
|
||||
"""Habitat Quality: regression test on numeric threat names."""
|
||||
|
|
|
@ -1180,8 +1180,8 @@ class HraRegressionTests(unittest.TestCase):
|
|||
b_geom_list = [float(x) for x in b_geom_list]
|
||||
|
||||
try:
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
a_geom_list, b_geom_list, decimal=precision)
|
||||
numpy.testing.assert_allclose(
|
||||
a_geom_list, b_geom_list, rtol=0, atol=1 * 10**-precision)
|
||||
except AssertionError:
|
||||
a_feature_fid = a_feat.GetFID()
|
||||
b_feature_fid = b_feat.GetFID()
|
||||
|
|
|
@ -101,8 +101,8 @@ class NDRTests(unittest.TestCase):
|
|||
numpy.count_nonzero(numpy.isclose(normalized_array,
|
||||
normalized_raster_nodata)))
|
||||
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
normalized_array, expected_array)
|
||||
numpy.testing.assert_allclose(
|
||||
normalized_array, expected_array, rtol=0, atol=1e-6)
|
||||
|
||||
def test_missing_headers(self):
|
||||
"""NDR biphysical headers missing should raise a ValueError."""
|
||||
|
|
|
@ -735,7 +735,8 @@ class RecreationRegressionTests(unittest.TestCase):
|
|||
with open(target_path, 'r') as file:
|
||||
predictor_results = json.load(file)
|
||||
# These constants were calculated by hand by Dave.
|
||||
numpy.testing.assert_almost_equal(predictor_results['0'], 13.0)
|
||||
numpy.testing.assert_allclose(
|
||||
predictor_results['0'], 13.0, rtol=0, atol=1e-6)
|
||||
|
||||
def test_raster_sum_mean_nodata(self):
|
||||
"""Recreation test sum/mean if raster has no valid pixels.
|
||||
|
@ -1211,8 +1212,8 @@ def _assert_vector_attributes_eq(
|
|||
|
||||
for av, ev in zip(actual_values, expected_values):
|
||||
if av is not None:
|
||||
numpy.testing.assert_almost_equal(
|
||||
av, ev, decimal=tolerance_places)
|
||||
numpy.testing.assert_allclose(
|
||||
av, ev, rtol=0, atol=1.5 * 10**-tolerance_places)
|
||||
else:
|
||||
# Could happen when a raster predictor is only nodata
|
||||
assert(ev is None)
|
||||
|
@ -1268,8 +1269,8 @@ def _assert_regression_results_eq(
|
|||
expected_values = list(expected_results.iloc[fid])
|
||||
for v, ev in zip(values, expected_values):
|
||||
if v is not None:
|
||||
numpy.testing.assert_almost_equal(
|
||||
v, ev, decimal=tolerance_places)
|
||||
numpy.testing.assert_allclose(
|
||||
v, ev, rtol=0, atol=1.5 * 10**-tolerance_places)
|
||||
else:
|
||||
# Could happen when a raster predictor is only nodata
|
||||
assert(numpy.isnan(ev))
|
||||
|
|
|
@ -98,9 +98,10 @@ class RouteDEMTests(unittest.TestCase):
|
|||
# So, the filled band should match the source band.
|
||||
expected_filled_array = gdal.OpenEx(args['dem_path']).ReadAsArray()[0]
|
||||
filled_array = gdal.OpenEx(filled_raster_path).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_filled_array,
|
||||
filled_array)
|
||||
filled_array,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_routedem_no_options(self):
|
||||
"""RouteDEM: assert pitfilling when no other options given."""
|
||||
|
@ -127,9 +128,10 @@ class RouteDEMTests(unittest.TestCase):
|
|||
# Filled rasters are copies of only the desired band of the input DEM,
|
||||
# and then with pixels filled.
|
||||
filled_array = gdal.OpenEx(filled_raster_path).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_filled_array,
|
||||
filled_array)
|
||||
filled_array,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_routedem_slope(self):
|
||||
"""RouteDEM: assert slope option."""
|
||||
|
@ -158,10 +160,12 @@ class RouteDEMTests(unittest.TestCase):
|
|||
13.235317, 45.017357, 48.226353, 48.75, 49.56845,
|
||||
50.249374, 50.24938, 50.249382, 55.17727, 63.18101],
|
||||
dtype=numpy.float32).reshape((15,))
|
||||
numpy.testing.assert_almost_equal(
|
||||
expected_unique_values,
|
||||
numpy.unique(slope_array))
|
||||
numpy.testing.assert_almost_equal(numpy.sum(slope_array), 4088.7358, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
expected_unique_values,
|
||||
numpy.unique(slope_array),
|
||||
rtol=0, atol=1e-6)
|
||||
numpy.testing.assert_allclose(
|
||||
numpy.sum(slope_array), 4088.7358, rtol=0, atol=1.5e-4)
|
||||
|
||||
def test_routedem_d8(self):
|
||||
"""RouteDEM: test d8 routing."""
|
||||
|
@ -207,10 +211,11 @@ class RouteDEMTests(unittest.TestCase):
|
|||
[0, 0, 0, 0, 1, 0, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0, 0, 0],
|
||||
])
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_stream_mask,
|
||||
gdal.OpenEx(os.path.join(
|
||||
args['workspace_dir'], 'stream_mask_foo.tif')).ReadAsArray())
|
||||
args['workspace_dir'], 'stream_mask_foo.tif')).ReadAsArray(),
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
expected_flow_accum = numpy.empty((10, 9), dtype=numpy.float64)
|
||||
expected_flow_accum[:, 0:4] = numpy.arange(1, 5)
|
||||
|
@ -220,10 +225,11 @@ class RouteDEMTests(unittest.TestCase):
|
|||
expected_flow_accum[1, 5] = 1
|
||||
expected_flow_accum[0, 5] = 8
|
||||
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_flow_accum,
|
||||
gdal.OpenEx(os.path.join(
|
||||
args['workspace_dir'], 'flow_accumulation_foo.tif')).ReadAsArray())
|
||||
args['workspace_dir'], 'flow_accumulation_foo.tif')).ReadAsArray(),
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
expected_flow_direction = numpy.empty((10, 9), dtype=numpy.uint8)
|
||||
expected_flow_direction[:, 0:4] = 0
|
||||
|
@ -232,10 +238,11 @@ class RouteDEMTests(unittest.TestCase):
|
|||
expected_flow_direction[0:2, 5] = 2
|
||||
expected_flow_direction[1, 6] = 3
|
||||
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_flow_direction,
|
||||
gdal.OpenEx(os.path.join(
|
||||
args['workspace_dir'], 'flow_direction_foo.tif')).ReadAsArray())
|
||||
args['workspace_dir'], 'flow_direction_foo.tif')).ReadAsArray(),
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
expected_downstream_distance = numpy.empty((10, 9), dtype=numpy.float64)
|
||||
expected_downstream_distance[:, 0:5] = numpy.flipud(numpy.arange(5))
|
||||
|
@ -244,10 +251,11 @@ class RouteDEMTests(unittest.TestCase):
|
|||
expected_downstream_distance[1, 5] = 1
|
||||
expected_downstream_distance[1, 6:] = numpy.arange(1, 4) + 0.41421356
|
||||
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_downstream_distance,
|
||||
gdal.OpenEx(os.path.join(
|
||||
args['workspace_dir'], 'downstream_distance_foo.tif')).ReadAsArray())
|
||||
args['workspace_dir'], 'downstream_distance_foo.tif')).ReadAsArray(),
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_routedem_mfd(self):
|
||||
"""RouteDEM: test mfd routing."""
|
||||
|
@ -281,10 +289,11 @@ class RouteDEMTests(unittest.TestCase):
|
|||
[0, 0, 0, 1, 1, 1, 0, 0, 0],
|
||||
[0, 0, 0, 0, 1, 0, 0, 0, 0],
|
||||
])
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
expected_stream_mask,
|
||||
gdal.OpenEx(os.path.join(
|
||||
args['workspace_dir'], 'stream_mask_foo.tif')).ReadAsArray())
|
||||
args['workspace_dir'], 'stream_mask_foo.tif')).ReadAsArray(),
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
# Raster sums are from manually-inspected outputs.
|
||||
for filename, expected_sum in (
|
||||
|
@ -300,7 +309,8 @@ class RouteDEMTests(unittest.TestCase):
|
|||
self.assertEqual(raster.RasterXSize, expected_stream_mask.shape[1])
|
||||
|
||||
raster_sum = numpy.sum(raster.ReadAsArray(), dtype=numpy.float64)
|
||||
numpy.testing.assert_almost_equal(raster_sum, expected_sum)
|
||||
numpy.testing.assert_allclose(
|
||||
raster_sum, expected_sum, rtol=0, atol=1e-6)
|
||||
|
||||
def test_validation_required_args(self):
|
||||
"""RouteDEM: test required args in validation."""
|
||||
|
|
|
@ -202,8 +202,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
args['workspace_dir'], 'output', 'vshed_qual.tif')
|
||||
quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_invalid_valuation_function(self):
|
||||
"""SQ: model raises exception with invalid valuation function."""
|
||||
|
@ -355,7 +356,8 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
value_band = value_raster.GetRasterBand(1)
|
||||
value_matrix = value_band.ReadAsArray()
|
||||
|
||||
numpy.testing.assert_almost_equal(expected_value, value_matrix)
|
||||
numpy.testing.assert_allclose(
|
||||
expected_value, value_matrix, rtol=0, atol=1e-6)
|
||||
|
||||
# verify that the correct number of viewpoints has been tallied.
|
||||
vshed_raster = gdal.OpenEx(
|
||||
|
@ -366,7 +368,8 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
|
||||
# Because our B coefficient is 0, the vshed matrix should match the
|
||||
# value matrix.
|
||||
numpy.testing.assert_almost_equal(expected_value, vshed_matrix)
|
||||
numpy.testing.assert_allclose(
|
||||
expected_value, vshed_matrix, rtol=0, atol=1e-6)
|
||||
|
||||
# Test the visual quality raster.
|
||||
expected_visual_quality = numpy.array(
|
||||
|
@ -379,8 +382,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
args['workspace_dir'], 'output', 'vshed_qual_foo.tif')
|
||||
quality_matrix = gdal.OpenEx(visual_quality_raster,
|
||||
gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_viewshed_with_fields(self):
|
||||
"""SQ: verify that we can specify viewpoint fields."""
|
||||
|
@ -437,7 +441,8 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
value_band = value_raster.GetRasterBand(1)
|
||||
value_matrix = value_band.ReadAsArray()
|
||||
|
||||
numpy.testing.assert_almost_equal(expected_value, value_matrix)
|
||||
numpy.testing.assert_allclose(
|
||||
expected_value, value_matrix, rtol=0, atol=1e-6)
|
||||
|
||||
# Verify that the sum of the viewsheds (which is weighted) is correct.
|
||||
expected_weighted_vshed = numpy.array(
|
||||
|
@ -450,8 +455,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
'vshed.tif')
|
||||
weighted_vshed_matrix = gdal.OpenEx(
|
||||
vshed_raster_path, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_weighted_vshed,
|
||||
weighted_vshed_matrix)
|
||||
numpy.testing.assert_allclose(expected_weighted_vshed,
|
||||
weighted_vshed_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
# Test the visual quality raster since this run is weighted.
|
||||
expected_visual_quality = numpy.array(
|
||||
|
@ -464,8 +470,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
args['workspace_dir'], 'output', 'vshed_qual.tif')
|
||||
quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_exponential_valuation(self):
|
||||
"""SQ: verify values on exponential valuation."""
|
||||
|
@ -512,7 +519,7 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
value_band = value_raster.GetRasterBand(1)
|
||||
value_matrix = value_band.ReadAsArray()
|
||||
|
||||
numpy.testing.assert_almost_equal(expected_value, value_matrix)
|
||||
numpy.testing.assert_allclose(expected_value, value_matrix, rtol=0, atol=1e-6)
|
||||
|
||||
def test_logarithmic_valuation(self):
|
||||
"""SQ: verify values on logarithmic valuation."""
|
||||
|
@ -559,7 +566,8 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
value_band = value_raster.GetRasterBand(1)
|
||||
value_matrix = value_band.ReadAsArray()
|
||||
|
||||
numpy.testing.assert_almost_equal(expected_value, value_matrix)
|
||||
numpy.testing.assert_allclose(
|
||||
expected_value, value_matrix, rtol=0, atol=1e-6)
|
||||
|
||||
def test_visual_quality(self):
|
||||
"""SQ: verify visual quality calculations."""
|
||||
|
@ -587,8 +595,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
|
||||
visual_quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
visual_quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
visual_quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_visual_quality_large_blocks(self):
|
||||
"""SQ: verify visual quality on large blocks."""
|
||||
|
@ -623,8 +632,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
|
||||
visual_quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
visual_quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
visual_quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_visual_quality_low_count(self):
|
||||
"""SQ: verify visual quality calculations for low pixel counts."""
|
||||
|
@ -650,8 +660,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
|
||||
visual_quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
visual_quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
visual_quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
def test_visual_quality_floats(self):
|
||||
"""SQ: verify visual quality calculations for floating-point vshed."""
|
||||
|
@ -678,8 +689,9 @@ class ScenicQualityTests(unittest.TestCase):
|
|||
|
||||
visual_quality_matrix = gdal.OpenEx(
|
||||
visual_quality_raster, gdal.OF_RASTER).ReadAsArray()
|
||||
numpy.testing.assert_almost_equal(expected_visual_quality,
|
||||
visual_quality_matrix)
|
||||
numpy.testing.assert_allclose(expected_visual_quality,
|
||||
visual_quality_matrix,
|
||||
rtol=0, atol=1e-6)
|
||||
|
||||
|
||||
class ScenicQualityValidationTests(unittest.TestCase):
|
||||
|
|
|
@ -36,8 +36,13 @@ def assert_expected_results_in_vector(expected_results, vector_path):
|
|||
# pixel values when also using a smoothing interpolation method.
|
||||
# Surprisingly, these differences are not washed out by an
|
||||
# aggregation such as zonal statistics.
|
||||
numpy.testing.assert_approx_equal(
|
||||
actual_results[key], expected_results[key], significant=2)
|
||||
|
||||
# Following numpy recommendation to use alternatives to
|
||||
# assert_approx_equal, this has been replaced with assert_allclose
|
||||
# using an absolute tolerance of 1e-5,
|
||||
# which is similar to (the same as?) 5 significant figures
|
||||
numpy.testing.assert_allclose(
|
||||
actual_results[key], expected_results[key], rtol=0, atol=1e-5)
|
||||
|
||||
|
||||
class SDRTests(unittest.TestCase):
|
||||
|
|
|
@ -809,10 +809,10 @@ class SeasonalWaterYieldRegressionTests(unittest.TestCase):
|
|||
fid, vri_sum, qb_val = [float(x) for x in line.split(',')]
|
||||
feature = result_layer.GetFeature(int(fid))
|
||||
for field, value in [('vri_sum', vri_sum), ('qb', qb_val)]:
|
||||
numpy.testing.assert_almost_equal(
|
||||
numpy.testing.assert_allclose(
|
||||
feature.GetField(field),
|
||||
value,
|
||||
decimal=tolerance_places)
|
||||
rtol=0, atol=1.5 * 10**-tolerance_places)
|
||||
ogr.Feature.__swig_destroy__(feature)
|
||||
feature = None
|
||||
|
||||
|
|
|
@ -561,8 +561,8 @@ class WaveEnergyRegressionTests(unittest.TestCase):
|
|||
b_geom_list = [float(x) for x in b_geom_list]
|
||||
|
||||
try:
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
a_geom_list, b_geom_list)
|
||||
numpy.testing.assert_allclose(
|
||||
a_geom_list, b_geom_list, rtol=0, atol=1e-6)
|
||||
except AssertionError:
|
||||
a_feature_fid = a_feat.GetFID()
|
||||
b_feature_fid = b_feat.GetFID()
|
||||
|
|
|
@ -731,8 +731,8 @@ class WindEnergyRegressionTests(unittest.TestCase):
|
|||
b_geom_list = [float(x) for x in b_geom_list]
|
||||
|
||||
try:
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
a_geom_list, b_geom_list, decimal=4)
|
||||
numpy.testing.assert_allclose(
|
||||
a_geom_list, b_geom_list, rtol=0, atol=1.5e-4)
|
||||
except AssertionError:
|
||||
a_feature_fid = a_feat.GetFID()
|
||||
b_feature_fid = b_feat.GetFID()
|
||||
|
@ -752,7 +752,7 @@ class WindEnergyRegressionTests(unittest.TestCase):
|
|||
'Field %s in feature %s does not exist in regression'
|
||||
'feature %s.' % (a_field, a_feature_fid, b_feature_fid))
|
||||
try:
|
||||
numpy.testing.assert_almost_equal(a_value, b_value)
|
||||
numpy.testing.assert_allclose(a_value, b_value, rtol=0, atol=1e-6)
|
||||
except AssertionError:
|
||||
raise AssertionError(
|
||||
'Values in %s field are not equal in feature %s: %s, '
|
||||
|
|
Loading…
Reference in New Issue