# InVEST 3.9.0 NDR model: KeyError for lucode of land use and biophysical table

**URL:** <https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906>\
**Category:** Software Support\
**Tags:** ndr\
**Created:** [May 12, 2021, 8:10am UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906 "2021-05-12T08:10:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiaying](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@Jiaying](https://community.naturalcapitalalliance.org/u/Jiaying)\
**Post date:** [May 12, 2021, 8:10am UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/1 "2021-05-12T08:10:32Z")

</div>

Hello!

When I use the NDR model, I have a problem with the log file saying as follows:  
KeyError: ‘lucode: -339999995214436424907732413799364296704 is present in the landuse raster but missing from the biophysical table’

However, I have checked my land use raster (landuse2009.tif) and biophysical table, all the lucodes are matched. Also, I have considered about the no data value and use ArcGIS raster calculator to convert all the nodata value into 0 (test41.tif), then I add 0 row in the biophysical table. There is still the same problem. In addition, all my lucode is from 112 to 512, so the lucode reported in the error is rather strange.

I would appreciated it if you could provide some help! I have attached my data and the whole input folder is shared through google drive.

[InVEST-Nutrient-Delivery-Ratio-Model-(NDR)-log-2021-05-12–15\_29\_24.txt](https://community.naturalcapitalalliance.org/uploads/short-url/yMVwTSwzNwjar8uxZhkqjnpOco9.txt) (9.5 KB)

---

<div class="post-metadata">

**Author:** ![dave](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.naturalcapitalalliance.org/dave/32/70_2.png) [@dave](https://community.naturalcapitalalliance.org/u/dave)\
**Post date:** [May 12, 2021, 1:36pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/3 "2021-05-12T13:36:18Z")

</div>

Hi @Jiaying , thanks for posting. Since that value is very, very small, you could try using the raster calculator to convert all pixels \< 0 to 0.

---

<div class="post-metadata">

**Author:** ![Jiaying](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@Jiaying](https://community.naturalcapitalalliance.org/u/Jiaying)\
**Post date:** [May 12, 2021, 3:39pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/4 "2021-05-12T15:39:34Z")

</div>

Thank you for your reply and it works! However, I am facing another problem ValueError: cannot convert float NaN to integer. I suppose the problem should be with biophysical table but have no clue. I attached my updated log file and the biophysical table.  
[biophysical\_table1.csv](https://community.naturalcapitalalliance.org/uploads/short-url/smB1lbUcFTSOAEeJbJH4FXqiQYH.csv) (965 Bytes)  
[InVEST-Nutrient-Delivery-Ratio-Model-(NDR)-log-2021-05-12–23\_36\_11.txt](https://community.naturalcapitalalliance.org/uploads/short-url/g3cVtO3qny2SvHkVIas3mbCZUAF.txt) (3.5 KB)

---

<div class="post-metadata">

**Author:** ![dave](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.naturalcapitalalliance.org/dave/32/70_2.png) [@dave](https://community.naturalcapitalalliance.org/u/dave)\
**Post date:** [May 12, 2021, 4:41pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/6 "2021-05-12T16:41:51Z")

</div>

@Jiaying , I’m glad that worked. This error is basically the same as the last one, a raster value is not present in the table. But now the problematic raster value is `nan`.

There are no `nan` values in your input lulc, but there are `nan` values in `intermediate_outputs/cache_dir/aligned_lulc.tif` which is the intermediate dataset after the model aligns and projects all the input layers.

So, I’m concerned about the coordinate reference system of all the input layers. It may be missing some crucial information that breaks things. The CRS reads, in part

```auto
PROJCRS["Bessel_1841_Hotine_Oblique_Mercator_Azimuth_Center",
    BASEGEOGCRS["Unknown datum based upon the Bessel 1841 ellipsoid",
        DATUM["D_unknown",
            ELLIPSOID["Bessel 1841",6377397.155,299.1528128,
                LENGTHUNIT["metre",1,
                    ID["EPSG",9001]]]],

```

I’m concerned about that unknown datum. Could you try projecting your input data (lulc, watershed, dem, etc) to a different CRS? A UTM system is usually a good choice.

Thanks for sharing your data.

---

<div class="post-metadata">

**Author:** ![Jiaying](https://avatars.discourse-cdn.com/v4/letter/j/2acd7d/32.png) [@Jiaying](https://community.naturalcapitalalliance.org/u/Jiaying)\
**Post date:** [May 13, 2021, 4:54pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/7 "2021-05-13T16:54:53Z")

</div>

Thank you for your suggestion!  
Finally I worked it out and the error is because there is a small patch within the study area in the LU file with no data. After converting it to 0 the model is running successfully!

---

<div class="post-metadata">

**Author:** ![dave](https://yyz1.discourse-cdn.com/flex031/user_avatar/community.naturalcapitalalliance.org/dave/32/70_2.png) [@dave](https://community.naturalcapitalalliance.org/u/dave)\
**Post date:** [May 13, 2021, 6:26pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/8 "2021-05-13T18:26:17Z")

</div>

> [@Jiaying](#):
>
> Finally I worked it out and the error is because there is a small patch within the study area in the LU file with no data. After converting it to 0 the model is running successfully!

Great! It’s strange that the prior raster calculator operations did not convert these last nodata pixels. Maybe they had some other strange non-numeric value.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex031/uploads/naturalcapitalproject/original/2X/8/8d95591aa074da87ea0fdd61ca47c1c3c0588aa7.png) [@system](https://community.naturalcapitalalliance.org/u/system)\
**Post date:** [May 20, 2021, 6:26pm UTC](https://community.naturalcapitalalliance.org/t/invest-3-9-0-ndr-model-keyerror-for-lucode-of-land-use-and-biophysical-table/1906/9 "2021-05-20T18:26:58Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
