Skip to content

Commit

Permalink
Merge pull request #1513 from phargogh/bugfix/1512-una-over-and-under…
Browse files Browse the repository at this point in the history
…supply-sums-missing

Fix issue with over- and under-supply values missing from UNA administrative vector
  • Loading branch information
dcdenu4 authored Jan 26, 2024
2 parents 9e50106 + 42421ca commit 581cfb2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
7 changes: 7 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ Unreleased Changes
* Fixed an issue where Urban Nature Access would crash if an administrative
boundary geometry did not overlap any people in the population raster.
https://github.com/natcap/invest/issues/1503
* Fixed an issue where the output administrative units vector's
``Pund_adm`` and ``Povr_adm`` fields representing undersupplied and
oversupplied populations, respectively, had values of 0 when running the
model with search radii defined per population group. The output
administrative units vector now has the correct values for these fields,
consistent with the user's guide chapter.
https://github.com/natcap/invest/issues/1512

3.14.1 (2023-12-18)
-------------------
Expand Down
20 changes: 16 additions & 4 deletions src/natcap/invest/urban_nature_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,23 @@
"about": (
"The total population within the "
"administrative unit that is undersupplied "
"with urban nature.")
"with urban nature. If aggregating by "
"population groups, this will be the sum "
"of undersupplied populations across all "
"population groups within this administrative "
"unit.")
},
"Povr_adm": {
"type": "number",
"units": u.people,
"about": (
"The total population within the "
"administrative unit that is oversupplied "
"with urban nature.")
"with urban nature. If aggregating by "
"population groups, this will be the sum "
"of oversupplied populations across all "
"population groups within this administrative "
"unit.")
},
"SUP_DEMadm_cap_[POP_GROUP]": {
"type": "number",
Expand Down Expand Up @@ -1978,14 +1986,18 @@ def _get_zonal_stats(raster_path):
feature_id]['sum']
group_sup_dem_in_region = urban_nature_sup_dem_stats[
feature_id]['sum']
group_oversupply_in_region = oversupply_stats[feature_id]['sum']
group_undersupply_in_region = undersupply_stats[feature_id]['sum']
stats_by_feature[feature_id][f'SUP_DEMadm_cap_{groupname}'] = (
group_sup_dem_in_region / group_population_in_region)
stats_by_feature[feature_id][f'Pund_adm_{groupname}'] = (
undersupply_stats[feature_id]['sum'])
group_undersupply_in_region)
stats_by_feature[feature_id][f'Povr_adm_{groupname}'] = (
oversupply_stats[feature_id]['sum'])
group_oversupply_in_region)
sums['supply-demand'][feature_id] += group_sup_dem_in_region
sums['population'][feature_id] += group_population_in_region
sums['oversupply'][feature_id] += group_oversupply_in_region
sums['undersupply'][feature_id] += group_undersupply_in_region

for feature_id in feature_ids:
stats_by_feature[feature_id]['SUP_DEMadm_cap'] = (
Expand Down
8 changes: 4 additions & 4 deletions tests/test_urban_nature_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,10 @@ def test_radii_by_pop_group(self):
'pop_female': attributes[0]['pop_female'],
'pop_male': attributes[0]['pop_male'],
'adm_unit_id': 0,
'Pund_adm': 0,
'Pund_adm': 3991.8271484375,
'Pund_adm_female': 2235.423095703125,
'Pund_adm_male': 1756.404052734375,
'Povr_adm': 0,
'Povr_adm': 1084.1727294921875,
'Povr_adm_female': 607.13671875,
'Povr_adm_male': 477.0360107421875,
'SUP_DEMadm_cap': -17.907799109781322,
Expand Down Expand Up @@ -645,10 +645,10 @@ def test_radii_by_pop_group_exponential_kernal(self):
'pop_female': attributes[0]['pop_female'],
'pop_male': attributes[0]['pop_male'],
'adm_unit_id': 0,
'Pund_adm': 0,
'Pund_adm': 4801.7900390625,
'Pund_adm_female': 2689.00244140625,
'Pund_adm_male': 2112.78759765625,
'Povr_adm': 0,
'Povr_adm': 274.2098693847656,
'Povr_adm_female': 153.55752563476562,
'Povr_adm_male': 120.65234375,
'SUP_DEMadm_cap': -17.907799109781322,
Expand Down

0 comments on commit 581cfb2

Please sign in to comment.