Urban Nature Access: ValueError: Encountered NaN in calculation but `default_nan` is None

What is the issue or question you have?
Hi! I’m trying to run the Urban Nature Access model with information from Ecuador! Unfortunately, I’m not able to find the problem with my data. I’m using the Sentinel-2 data base (10x10m) for the LULC raster. For the population raster I’m using the Meta Population Density raster of my country. For the Urban_Nature value in the .csv file I used 0 for no natural areas and 1-6 values for natural ones.

What do you expect to happen?
Run the Urban Nature Access Model successfully and obtain the nature supply, demand and balance for my study area.

What have you tried so far?
I already checked the NoData values for both rasters (LULC and Population) and they’re already defined (not NaN). All rasters have the same projection (UTM 17S). Maybe there’s a problem with the numbers since my computer has the coma (,) as predetermined decimal symbol for the system and thus for ArcGIS. I hope you could help me find a way out of this problem. Thank you very much in advance!

Upload the logfile using the :outbox_tray: button
InVEST-natcap.invest.urban_nature_access-log-2024-01-02–21_29_07.txt (6.8 KB)

Hi @Dan08 , thanks for posting your logfile and for including all these details.

We may need to get the Population and LULC rasters to debug this. It seems there is some value in the Population raster that is not a valid numeric value. Could you share those data here? Or with a link to a filesharing service?

Thanks,

Hi Dave, thank you very much for your reply. Sure! I will attach the data I used here. BTW the csv table I created looks like this…
lucode;urban_nature;search_radius_m
2;1;150
7;6;250
5;4;250
3;2;250
1;0;0
4;3;250
6;5;250
DENSIDAD_OTA.tif (257.0 KB)
LULC_OTA.tif (29.3 KB)

Thanks for sharing your data. It looks like there are lots of nan values in DENSIDAD_OTA.tif. They are not so easy to find; QGIS seems to treat them the same as the other nodata pixels. But if I interrogate all the raster values in Python using numpy, I see,

>>> import numpy
>>> import pygeoprocessing

>>> filepath = 'DENSIDAD_OTA.tif'
>>> nodata = pygeoprocessing.get_raster_info(filepath)['nodata'][0]
>>> array = pygeoprocessing.raster_to_numpy_array(filepath)

>>> nan_mask = numpy.isnan(array)
>>> nodata_mask = numpy.isclose(array, nodata)

>>> numpy.count_nonzero(nan_mask)
42914  # this many pixels have nan value
>>> numpy.count_nonzero(nodata_mask)
1098  # this many pixels have the defined nodata value

I’m not sure these nan pixels should be classified as nodata, or if something perhaps went wrong when creating this dataset.

Sorry for my late response. In that case I’ll try to run the model with a different population density raster. Are the other rasters right ? Or should I change them as well ?

Sorry for my late response. In that case I’ll try to run the model with a different population density raster. Are the other rasters right ? Or should I change them as well ?

No problem. Your log indicated an error caused by the population raster. Once your resolve that, if other issues arise feel free to create a New Topic. Or if you have further questions about the population raster, please ask them here.

Best,

Ok, so I tried the whole process again with a theoretical population raster that I created just so I can keep going with rest of steps. However, that took me to another error. It seems that something is wrong with the float values. I attached you the log here
InVEST-natcap.invest.urban_nature_access-log-2024-01-22–19_32_38.txt (5.5 KB)

Hi @Dan08 -

The current error might because you’ve specified “uniform” radius, but haven’t provided a value for “uniform search radius” in the user interface. I can replicate that behavior. Try providing a “uniform search radius” and see if that fixes the error.

The model really should catch this in the user interface, I’ll file an issue about it.

~ Stacie

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