Using the proportion in urban nature area. RE:#1180

This commit is contained in:
James Douglass 2023-08-24 11:48:07 -07:00
parent d4e34b5f32
commit fcb4011e53
2 changed files with 25 additions and 7 deletions

View File

@ -942,7 +942,7 @@ def execute(args):
if args['search_radius_mode'] == RADIUS_OPT_UNIFORM:
search_radii = set([float(args['search_radius'])])
elif args['search_radius_mode'] == RADIUS_OPT_URBAN_NATURE:
urban_nature_attrs = attr_table[attr_table['urban_nature'] == 1]
urban_nature_attrs = attr_table[attr_table['urban_nature'] > 0]
try:
search_radii = set(urban_nature_attrs['search_radius_m'].unique())
except KeyError as missing_key:
@ -1805,13 +1805,16 @@ def _reclassify_urban_nature_area(
"""Reclassify LULC pixels into the urban nature area they represent.
After execution, urban nature pixels will have values representing the
pixel's area, while pixels that are not urban nature will have a pixel
value of 0. Nodata values will propagate to the output raster.
pixel's area of urban nature (pixel area * proportion of urban nature),
while pixels that are not urban nature will have a pixel value of 0.
Nodata values will propagate to the output raster.
Args:
lulc_raster_path (string): The path to a land-use/land-cover raster.
lulc_attribute_table (string): The path to a CSV table representing
LULC attributes. Must have "lucode" and "urban_nature" columns.
The "urban_nature" column represents a proportion 0-1 of how much
of the pixel's area represents urban nature.
target_raster_path (string): Where the reclassified urban nature raster
should be written.
only_these_urban_nature_codes=None (iterable or None): If ``None``, all
@ -1833,13 +1836,15 @@ def _reclassify_urban_nature_area(
valid_urban_nature_codes = set(only_these_urban_nature_codes)
else:
valid_urban_nature_codes = set(
lulc_attribute_df[lulc_attribute_df['urban_nature'] == 1].index)
lulc_attribute_df[lulc_attribute_df['urban_nature'] > 0].index)
urban_nature_area_map = {}
for lucode in lulc_attribute_df.index:
for row in lulc_attribute_df[['urban_nature']].itertuples():
lucode = row.Index
urban_nature_proportion = row.urban_nature
urban_nature_area = 0
if lucode in valid_urban_nature_codes:
urban_nature_area = squared_pixel_area
urban_nature_area = squared_pixel_area * urban_nature_proportion
urban_nature_area_map[lucode] = urban_nature_area
lulc_raster_info = pygeoprocessing.get_raster_info(lulc_raster_path)

View File

@ -85,7 +85,8 @@ def _build_model_args(workspace):
6,0,100
7,1,100
8,0,100
9,1,100"""))
9,1,100
"""))
admin_geom = [
shapely.geometry.box(
@ -960,6 +961,18 @@ class UNATests(unittest.TestCase):
"""UNA: Run the model with urban nature proportion."""
from natcap.invest import urban_nature_access
args = _build_model_args(self.workspace_dir)
args['search_radius_mode'] = urban_nature_access.RADIUS_OPT_UNIFORM
args['search_radius'] = 1000
with open(args['lulc_attribute_table'], 'a') as attr_table:
attr_table.write("10,0.5,100\n")
# make sure our inputs validate
validation_results = urban_nature_access.validate(args)
self.assertEqual(validation_results, [])
urban_nature_access.execute(args)
def test_validate(self):
"""UNA: Basic test for validation."""
from natcap.invest import urban_nature_access