NDR - KeyError: 'lucode: 1 is present in the landuse raster but missing from the biophysical table'


I am using InVEST 3.10.2 to run the Nutrient Delivery Ratio model and encountered the following error message: KeyError: ‘lucode: 1 is present in the landuse raster but missing from the biophysical table’

I’ve checked that the values in the LULC raster and biophysical table matched, and also added a row in the biophysical table for null = 0 values, but it still did not work.

I would appreciated it if you could provide some help! I have attached the log and LULC raster for your reference.

InVEST-Nutrient-Delivery-Ratio-log-2022-05-10–10_57_41.txt (5.1 KB)

LULC2019_bioretention and edeck_reprojected.tif (3.2 MB)

Thank you!

Hi @ShLo, and welcome to the forum.

Thanks for posting the log file and LULC raster. Can you also share the biophysical table?

~ Stacie

1 Like

Hi @swolny,

Thanks for replying, here’s the biophysical table:

Biophysical table_NDR.csv (513 Bytes)

Thanks for the table @ShLo.

Looking at the LULC raster, it actually has a lot of floating point values (such as 1.000448346), like you see in the attached image. To see these in the GIS, symbolize the raster with Unique values.

I don’t know why the values are like that, but I suspect that’s the problem. You will need to reclassify those to have unique integer values. Then make sure that all of those integer values are in the biophysical table.

~ Stacie

1 Like

This raster looks like the result of a resample/warp using an interpolation algorithm like “bilinear” rather than using “nearest neighbor” or “mode”, which are better choices for categorical data.

So maybe it’s a good idea to go back to the original raster, if there is one.

1 Like

Hi @swolny, I have reclassified the LULC raster as suggested and it works!

Thank you so much!

Hi @dave, thanks for highlighting that. Indeed the raster has been projected in linear units as required by the NDR model. Do you have any suggestions on how to work around it to avoid similar issues in the future?


Hi @dave, just an update, I tried reprojecting the raster file using the resampling method ‘mode’ and it works fine with the NDR model and do not have the issues of the floating points :+1:


1 Like

Hi @ShLo -

As @dave noted, any time we need to resample or reproject the LULC layer (or any other layer where we don’t want to change the original raster values), it’s best to use something like the Nearest Neighbor resampling method, so that the original codes will be retained. Using Mode seems like it would work just as well for this purpose. It doesn’t matter to the model what the actual codes are, so long as they are unique integers.

I don’t know which GIS you’re using, but if it’s ArcGIS, what I typically do is export the LULC’s raster attribute table to a CSV, and use that CSV as the basis for creating the biophysical table. That way I know that all of the codes in the LULC raster will be in the table. As far as I know, and very unfortunately, QGIS still doesn’t handle raster attribute tables, so you’d need to do something like symbolize the raster by unique values to see which land use codes are present that need to be in the biophysical table.

~ Stacie


Thanks for the advice @swolny, will take note of that!