Adding a test for exponential decay.
Also fixes a bug revealed by the test. RE:#722
This commit is contained in:
parent
c91eaa6064
commit
238b070d59
|
@ -2063,7 +2063,8 @@ def _kernel_exponential(distance, max_distance):
|
|||
"""
|
||||
kernel = numpy.zeros(distance.shape, dtype=numpy.float32)
|
||||
pixels_in_radius = (distance <= max_distance)
|
||||
kernel[pixels_in_radius] = numpy.exp(-distance / max_distance)
|
||||
kernel[pixels_in_radius] = numpy.exp(
|
||||
-distance[pixels_in_radius] / max_distance)
|
||||
return kernel
|
||||
|
||||
|
||||
|
|
|
@ -309,6 +309,20 @@ class UNATests(unittest.TestCase):
|
|||
numpy.testing.assert_allclose(
|
||||
expected_array, kernel)
|
||||
|
||||
def test_exponential_kernel(self):
|
||||
"""UNA: Test the exponential decay kernel."""
|
||||
from natcap.invest import urban_nature_access
|
||||
|
||||
max_distance = 3
|
||||
distance = numpy.array([0, 1, 2, 3, 4])
|
||||
kernel = urban_nature_access._kernel_exponential(
|
||||
distance, max_distance)
|
||||
# Regression values are calculated by hand
|
||||
expected_array = numpy.array(
|
||||
[1, 0.71653134, 0.5134171, 0.36787945, 0])
|
||||
numpy.testing.assert_allclose(
|
||||
expected_array, kernel)
|
||||
|
||||
def test_greenspace_budgets(self):
|
||||
"""UNA: Test the per-capita greenspace budgets functions."""
|
||||
from natcap.invest import urban_nature_access
|
||||
|
|
Loading…
Reference in New Issue