KeyError InVEST 3.8.0 Carbon Storage Model

I got the following error running the InVEST Carbon Storage Model: KeyError encountered ‘4101.0’.
Please see the attached logfile for more details.
The problem seems to be that the LU-Code of the carbon pool table is converted to a decimal number. I have already made sure that it is stored as an integer in the csv file. I have also checked that the csv file is comma separated and that there are no blank lines at the bottom. Do you have any other suggestion how I can solve this problem?
Thank you very much in advance and kind regards,

InVEST-InVEST-Carbon-Model-log-2020-03-02–13_44_48.txt (2.3 KB)


Thanks for using InVEST and posting to the forums. It does seem like the model is taking the LU-Codes and casting them to a float somewhere down the line. Is it possible you could attach your carbon pools csv so I can see if I get the same response on our end?



Hi Doug, thanks a lot for the quick reply! Please find attached the csv file.

Many thanks,

pools.csv (214 Bytes)


Looks like there is a side-effect in how that CSV file is being read. Because the column values have floating point numbers the ‘lucode’ column is being cast to a floating point as well. At least that is the response I am seeing in testing. So, for now, setting those column values to the nearest integer should work around the issue. I’ve attached a version of your pools.csv with the modification. Note that there was a NA lucode row that I removed. Let me know if this work around works for you.

pools.csv (97 Bytes)


Hi @anne,

After further looking into the KeyError issue, it looks like the real problem was the NA,0,0,0,0 row in the pool csv. The error reported doesn’t really help reflect that and this is something we are looking to address in the future as it relates to mapping values from a raster to a CSV input.

So, you can keep those floating point values in there that you had for the columns, but will need to remove the row with NA .

Please let us know if this doesn’t solve the issue for you!


Hi Doug,
thanks a lot for your help - deleting the NA row worked out!