This forum is shutting down! Please post new discussions at community.naturalcapitalproject.org

Water Yield model run KeyError in _add_zonal_stats_dict_to_shape

husu_azhuhusu_azhu Member
edited January 15 in Freshwater Models
I have orgnised the data as the user's guide required. After I run the Water Yield in InVEST, an error occurred as below. Can someone kindly help me with this problem. Thanks a lot.

01/13/2019 17:00:20  natcap.invest.utils INFO     Writing log messages to D:\gengshoubao\Eservice\4InVEST2\InVEST-Hydropower-Water-Yield-log-2019-01-13--17_00_20.txt
01/13/2019 17:00:20  natcap.invest.ui.model Level 100 Starting model with parameters:
Arguments for InVEST natcap.invest.hydropower.hydropower_water_yield 3.5.0:
biophysical_table_uri        D:/gengshoubao/Eservice/3data/biophysical_table.csv
calculate_valuation          False
calculate_water_scarcity     False
depth_to_root_rest_layer_uri D:/gengshoubao/Eservice/3data/pdep_3/w001001.adf
eto_uri                      D:/gengshoubao/Eservice/3data/eto_3/w001001.adf
lulc_uri                     D:/gengshoubao/Eservice/3data/lucc2015_3/w001001.adf
pawc_uri                     D:/gengshoubao/Eservice/3data/pawc_3/w001001.adf
precipitation_uri            D:/gengshoubao/Eservice/3data/precip_3/w001001.adf
results_suffix              
seasonality_constant         9.05
sub_watersheds_uri          
watersheds_uri               D:/gengshoubao/Eservice/3data/watersheds_3.shp
workspace_dir                D:\gengshoubao\Eservice\4InVEST2

01/13/2019 17:00:20  natcap.invest.hydropower.hydropower_water_yield INFO     Validating arguments
01/13/2019 17:00:20  natcap.invest.validation DEBUG    Validation warnings: []
01/13/2019 17:00:20  pygeoprocessing.geoprocessing INFO     n_workers > 1 (2) so starting a processes pool.
01/13/2019 17:00:21  pygeoprocessing.geoprocessing INFO     1 of 5 aligned: eto.tif
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     2 of 5 aligned: precip.tif
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     3 of 5 aligned: depth_to_root_rest_layer.tif
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     4 of 5 aligned: pawc.tif
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     5 of 5 aligned: clipped_lulc.tif
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     aligned all 5 rasters.
01/13/2019 17:00:22  natcap.invest.hydropower.hydropower_water_yield INFO     Reclassifying temp_Kc raster
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:22  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-6, started daemon 5024)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield INFO     Reclassifying tmp_root raster
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-7, started daemon 5180)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield INFO     Reclassifying tmp_veg raster
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-8, started daemon 5384)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield INFO     Calculate PET from Ref Evap times Kc
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-9, started daemon 2756)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield DEBUG    Performing fractp operation
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-10, started daemon 2104)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield INFO     Performing wyield operation
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-11, started daemon 6152)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  natcap.invest.hydropower.hydropower_water_yield DEBUG    Performing aet operation
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     starting stats_worker
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     started stats_worker <Thread(Thread-12, started daemon 4980)>
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     100.0%% complete
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     signaling stats worker to terminate
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     Waiting for raster stats worker result.
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     n_workers == 1 so a threadpool is sufficient
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     1 of 1 aligned: clipped_rasterbxalls
01/13/2019 17:00:23  pygeoprocessing.geoprocessing INFO     aligned all 1 rasters.
01/13/2019 17:00:34  natcap.invest.ui.model ERROR    Exception while executing <function execute at 0x1590E570>
Traceback (most recent call last):
  File "C:\Users\natcap-servers\jenkins-home\workspace\natcap.invest\label\GCE-windows-1\env\lib\site-packages\natcap\invest\ui\model.py", line 1541, in _logged_target
  File "C:\Users\natcap-servers\jenkins-home\workspace\natcap.invest\label\GCE-windows-1\env\lib\site-packages\natcap\invest\hydropower\hydropower_water_yield.py", line 462, in execute
  File "C:\Users\natcap-servers\jenkins-home\workspace\natcap.invest\label\GCE-windows-1\env\lib\site-packages\natcap\invest\hydropower\hydropower_water_yield.py", line 906, in _add_zonal_stats_dict_to_shape
KeyError: 2
01/13/2019 17:00:34  natcap.invest.ui.model INFO     Execution finished
01/13/2019 17:00:34  natcap.invest.utils INFO     Elapsed time: 13.27s


Post edited by Dave on

Comments

  • swolnyswolny Member, NatCap Staff

    Thank you for posting the log file. A lot of other people have had KeyErrors, and you can find several solutions if you search the Forum. Have you tried any of those solutions yet? If so, let us know what didn't work for you.

    ~ Stacie
  • Thank you for your response,
    Actually, I have searched all the 'water yield' related themes in the Forum, but unfortunately I found no KeyErrors same to mine. So I posted my problem for help to see if others have met the same problem before and how they solved it.

  • I prepared my data with the InVEST 3.2.0 User's Guide and I have unified the spatial reference of all the Rasters and Vectors. However, after I ran the model, an error of 'natcap.invest.ui.model ERROR    Exception while executing <function execute at 0x1590E570>' occurred.

    Then I checked the outputs, I found the tif files (aet.tif, fractp.tif and wyield.tif) in the per_pixel folder could be generated, but I am not sure if they were generated correctly in the face of error occurrence.

    In addition, for the shapefile of watershed_results_wyield, the attribute table did not have PET_mn, AET_mn, wyield_mn, and so on. It only had one new column of precip_mn, but only had the right value for the first watershed, and 0 for all the other watersheds.
  • DaveDave Member, Administrator, NatCap Staff
    This could be related to an issue we fixed recently. Would you mind trying this development version of InVEST? 


    Also, your raster outputs should be okay, since the error was raised at the point of aggregating those raster results to your watershed boundaries. That also explains why the attribute table was incomplete. 
  • Finally, I found it is a problem of software version. My friend performed this model with another version of InVEST, the issue did not occur.
Sign In or Register to comment.