Something went wrong when adding task Aggregate supply-demand to admin units (single rasters) (17)

What is the issue or question you have?

I am not able to run the InVEST Urban Nature Access model. I am running in to the errors “Something went wrong when adding task Aggregate supply-demand to admin units (single rasters) (17)” and “File “natcap\invest\urban_nature_access.py”, line 2043, in _supply_demand_vector_for_single_raster_modes
ZeroDivisionError: float division by zero” in the InVEST Workbench 3.14.0.

What do you expect to happen?

I expect the model to run.

What have you tried so far?

I have tried to run the Urban Nature Access model both in the InVEST workbench and in Python. In Python, I am getting the error: “ValueError: Could not open …nature_access_workspace/intermediate\tmpifu4wrui\pop_density.tif as a gdal.OF_RASTER” and no pop_density.tif file is being created.

I have tried using the pygeoprocessing align_and_resize_raster_stack function on the LULC and population rasters prior to running the model.

I have also tried replacing all zero and nodata values with a very small number in the rasters. Neither of these changes seem to affect the errors I’m seeing.

Upload the logfile using the :outbox_tray: button

log.txt (6.3 KB)

Hello @libby_kula ,

As far as the ZeroDivisionError goes and looking at the source code, the most likely cause is that you have an admin boundary polygon that doesn’t overlap any people in the population raster. So until we handle this case within the model itself, a good workaround would be to locate the admin polygon that doesn’t overlap any people and remove it from your admin boundaries vector.

For the other behavior, the raster pop_density.tif is created within a temporary folder within your intermediate directory, and the most likely cause of this is that something is preventing write access to your intermediate folder. It is possible that since your workspace is within your OneDrive, that OneDrive is actively scanning that folder and interfering with model execution. Just to be safe, would you try running InVEST with a workspace in a place that isn’t within your OneDrive?

Let us know how this goes!
James

Hello @jdouglass,

Thank you for your response. There was an issue with my administrative boundaries polygon vector, and I am able to run the model in the InVEST workbench after fixing it.

I’m still getting the pop_density.tif error in Python, even after fixing the boundaries and moving the workspace and data files out of my OneDrive.

Thank you,
Libby

Would you please provide your python script here so we can take a look? If you prefer, feel free to email it to me at jdouglass@stanford.edu.

Thanks,
James

For sure, here is the code:

# coding=UTF-8
# -----------------------------------------------
# Generated by InVEST 3.14.0 on Wed Jan 17 12:17:59 2024
# Model: Urban Nature Access

import logging
import sys

import natcap.invest.urban_nature_access
import natcap.invest.utils

LOGGER = logging.getLogger(__name__)
root_logger = logging.getLogger()

handler = logging.StreamHandler(sys.stdout)
formatter = logging.Formatter(
    fmt=natcap.invest.utils.LOG_FMT,
    datefmt='%m/%d/%Y %H:%M:%S ')
handler.setFormatter(formatter)
logging.basicConfig(level=logging.INFO, handlers=[handler])

args = {
    'admin_boundaries_vector_path': 'C:\\Users\\kibby\\Documents\\invest_urban_nature_access_datastack\\data\\admin_boundaries_vector_path_vector\\Abilene, '
                                    'TX_valid_v02.gpkg',
    'aggregate_by_pop_group': False,
    'decay_function': 'dichotomy',
    'lulc_attribute_table': 'C:\\Users\\kibby\\Documents\\invest_urban_nature_access_datastack\\data\\lulc_attribute_table_csv.csv',
    'lulc_raster_path': 'C:\\Users\\kibby\\Documents\\invest_urban_nature_access_datastack\\data\\lulc_raster_path_raster\\nlcd_2001_wgs84_clipped_aligned_Abilene, '
                        'TX_nad83.tif',
    'population_group_radii_table': '',
    'population_raster_path': 'C:\\Users\\kibby\\Documents\\invest_urban_nature_access_datastack\\data\\population_raster_path_raster\\gpw_v4_population_count_rev11_2000_30_sec_clipped_aligned_Abilene, '
                              'TX_nad83.tif',
    'results_suffix': '',
    'search_radius': '1400',
    'search_radius_mode': 'uniform radius',
    'urban_nature_demand': '9',
    'workspace_dir': 'C:\\Users\\kibby\\Documents\\nature_access_workspace',
}

if __name__ == '__main__':
    natcap.invest.urban_nature_access.execute(args)

Here is a more detailed error message as well:

01/22/2024 08:41:53  (natcap.invest.urban_nature_access) urban_nature_access.execute(700) INFO Starting Urban Nature Access Model
01/22/2024 08:41:53  (natcap.invest.urban_nature_access) urban_nature_access.execute(735) INFO Using decay function dichotomy
01/22/2024 08:41:53  (taskgraph.Task) Task.add_task(706) ERROR Something went wrong when adding task Resample population to LULC resolution (1), terminating taskgraph.
Traceback (most recent call last):
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\taskgraph\Task.py", line 674, in add_task
    new_task._call()
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\taskgraph\Task.py", line 1093, in _call
    payload = self._func(*self._args, **self._kwargs)
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\natcap\invest\urban_nature_access.py", line 2374, in _resample_population_raster
    pygeoprocessing.warp_raster(
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\pygeoprocessing\geoprocessing.py", line 2362, in warp_raster
    base_raster_info = get_raster_info(base_raster_path)
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\pygeoprocessing\geoprocessing.py", line 1967, in get_raster_info      
    raise ValueError(
ValueError: Could not open C:\Users\kibby\Documents\nature_access_workspace\intermediate\tmpwk69r_36\pop_density.tif as a gdal.OF_RASTER 
Traceback (most recent call last):
  File "c:\Users\kibby\Documents\invest_urban_nature_access_datastack\execute_invest_urban_nature_access.py", line 41, in <module>       
    natcap.invest.urban_nature_access.execute(args)
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\natcap\invest\urban_nature_access.py", line 764, in execute
    population_alignment_task = graph.add_task(
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\taskgraph\Task.py", line 674, in add_task
    new_task._call()
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\taskgraph\Task.py", line 1093, in _call
    payload = self._func(*self._args, **self._kwargs)
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\natcap\invest\urban_nature_access.py", line 2374, in _resample_population_raster
    pygeoprocessing.warp_raster(
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\pygeoprocessing\geoprocessing.py", line 2362, in warp_raster
    base_raster_info = get_raster_info(base_raster_path)
  File "C:\Users\kibby\mambaforge\envs\investenv\lib\site-packages\pygeoprocessing\geoprocessing.py", line 1967, in get_raster_info      
    raise ValueError(
ValueError: Could not open C:\Users\kibby\Documents\nature_access_workspace\intermediate\tmpwk69r_36\pop_density.tif as a gdal.OF_RASTER

Thank you for providing the tail of your logs and also your python script. I don’t see anything obviously wrong there.

One thing I am wondering though is again about OneDrive. Recently, Windows comes preconfigured to have your desktop, Documents and other folders uploading to OneDrive. I am pretty sure that your user folder C:\Users\kibby should not be managed by OneDrive, so could you try setting your workspace to C:\Users\kibby\workspace or something like that and re-run the model?

Thanks and hopefully this is all that’s needed!
James