KeyError encountered: lucode

Hello InVEST users!

I’m trying to run two different NDR scenarios using two different LULC rasters with corresponding biophysical tables. All other input data is the same (watershed boundary, DEM, rainfall). For both runs (so for both LULC rasters), I’ve come across the error “KeyError encountered: lucode 0 is present in the LULC raster but not in the biophysical table”.

I saw a few other people have had this issue, and I’ve tried following those threads, but I am unable to fix the problem. My projections are accurate and the same between all input rasters. I’ve reclassified missing data to be “NoData”, and I believe my pixel types for each raster are what they should be. My best guess is that the issue arises when I export an LULC raster to a .tif.
Here’s the log for the failed run of my 2nd NDR scenario InVEST-Nutrient-Delivery-Ratio-Model-(NDR)-log-2021-11-25–12_39_34.txt (8.6 KB)

PS: When I ran my 1st NDR scenario, I received the message “KeyError encountered: lucode 0 is present in the LULC raster but not in the biophysical table”. I then edited the biophysical table by adding an lucode =0 with null values. The model ran successfully with this log
InVEST-Nutrient-Delivery-Ratio-Model-(NDR)-log-2021-11-25–11_51_24.txt (14.3 KB)

I would appreciate any insight into my dilemma.
Thank you!

Hi @atershy ,

Thanks the detailed post and including what you’ve already tried.

If you look at your LULC raster in ArcGIS or QGIS you should see some 0 values in there. Every LULC code needs to have an entry in the corresponding biophysical table. So as you mentioned, editing the biophysical table to have a 0 entry with 0 values is one way to get around the issue.

The other way is to reclassify those LULC 0 values into NODATA values, or reclassify them into another similar LULC type that you have defined in the biophysical table, if that would make sense.

Let us know if one of those solutions works or if you have any other questions.



If you’d like to share your LULC rasters I can also take a quick look for these mysterious 0 values. You can upload them here, or in a direct message, or share via Google Drive, or email ddenu @ stanford . edu.



1 Like

This was resolved via an email thread. There was some confusion about being able to use ArcGIS raster attribute tables to set multiple LULC pixel values to the same table LULC code. InVEST does not use raster attribute tables to do any processing, but relies on the raster pixel values themselves.

1 Like