Adding a test for normalized dichotomous kernel.

RE:#722
This commit is contained in:
James Douglass 2023-01-21 10:35:37 -08:00
parent bc721523f6
commit ead918d63f
1 changed files with 19 additions and 1 deletions

View File

@ -253,7 +253,7 @@ class UNATests(unittest.TestCase):
n_1_pixels, expected_n_1_pixels, rtol=1e-5)
self.assertEqual(kernel_info['raster_size'], expected_shape)
def test_density_decay(self):
def test_density_decay_simple(self):
"""UNA: Test density decay."""
from natcap.invest import urban_nature_access
@ -273,6 +273,24 @@ class UNATests(unittest.TestCase):
self.assertEqual(0.75, kernel_array.max())
self.assertEqual(0, kernel_array.min())
def test_density_decay_normalized(self):
"""UNA: Test normalized density decay."""
from natcap.invest import urban_nature_access
expected_distance = 200
kernel_filepath = os.path.join(self.workspace_dir, 'kernel.tif')
urban_nature_access.density_decay_kernel_raster(
expected_distance, kernel_filepath, normalize=True)
expected_shape = (expected_distance*2+1,) * 2
kernel_info = pygeoprocessing.get_raster_info(kernel_filepath)
kernel_array = pygeoprocessing.raster_to_numpy_array(kernel_filepath)
self.assertEqual(kernel_info['raster_size'], expected_shape)
numpy.testing.assert_allclose(1, kernel_array.sum())
self.assertAlmostEqual(1.5915502e-05, kernel_array.max())
self.assertEqual(0, kernel_array.min())
def test_greenspace_budgets(self):
"""UNA: Test the per-capita greenspace budgets functions."""
from natcap.invest import urban_nature_access