Testing limiting of lucodes. RE:#1180
This commit is contained in:
parent
e1e1a711a7
commit
14e91871cd
|
@ -997,25 +997,31 @@ class UNATests(unittest.TestCase):
|
|||
|
||||
urban_nature_area_path = os.path.join(
|
||||
self.workspace_dir, 'urban_nature_area.tif')
|
||||
urban_nature_access._reclassify_urban_nature_area(
|
||||
args['lulc_raster_path'], args['lulc_attribute_table'],
|
||||
urban_nature_area_path)
|
||||
|
||||
# The source lulc is randomized, so need to programmatically build up
|
||||
# the expected array.
|
||||
source_lulc_array = pygeoprocessing.raster_to_numpy_array(
|
||||
args['lulc_raster_path'])
|
||||
pixel_area = abs(_DEFAULT_PIXEL_SIZE[0] * _DEFAULT_PIXEL_SIZE[1])
|
||||
expected_array = numpy.zeros(source_lulc_array.shape,
|
||||
dtype=numpy.float32)
|
||||
for i in range(1, 10, 2):
|
||||
factor = float(f"0.{i}")
|
||||
expected_array[source_lulc_array == i] = factor * pixel_area
|
||||
for limit_to_lucodes in (None, set([1, 3])):
|
||||
urban_nature_access._reclassify_urban_nature_area(
|
||||
args['lulc_raster_path'], args['lulc_attribute_table'],
|
||||
urban_nature_area_path,
|
||||
only_these_urban_nature_codes=limit_to_lucodes)
|
||||
|
||||
reclassified_array = pygeoprocessing.raster_to_numpy_array(
|
||||
urban_nature_area_path)
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
reclassified_array, expected_array)
|
||||
# The source lulc is randomized, so need to programmatically build
|
||||
# up the expected array.
|
||||
source_lulc_array = pygeoprocessing.raster_to_numpy_array(
|
||||
args['lulc_raster_path'])
|
||||
pixel_area = abs(_DEFAULT_PIXEL_SIZE[0] * _DEFAULT_PIXEL_SIZE[1])
|
||||
expected_array = numpy.zeros(source_lulc_array.shape,
|
||||
dtype=numpy.float32)
|
||||
for i in range(1, 10, 2):
|
||||
if limit_to_lucodes is not None:
|
||||
if i not in limit_to_lucodes:
|
||||
continue
|
||||
factor = float(f"0.{i}")
|
||||
expected_array[source_lulc_array == i] = factor * pixel_area
|
||||
|
||||
reclassified_array = pygeoprocessing.raster_to_numpy_array(
|
||||
urban_nature_area_path)
|
||||
numpy.testing.assert_array_almost_equal(
|
||||
reclassified_array, expected_array)
|
||||
|
||||
def test_validate(self):
|
||||
"""UNA: Basic test for validation."""
|
||||
|
|
Loading…
Reference in New Issue