# SDR model error

Member
Hello,

I am encountering the following error continuously. I request you to please help me with the mentioned error.

Thanks
Sumit

ValueError: The following 1 raster values [0]

Initializing...

Showing messages with level INFO and higher

05/28/2018 12:11:15 natcap.invest.utils INFO Writing log messages to C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Dudhwa\Sediment\output\InVEST-Sediment-Delivery-Ratio-Model-(SDR)-log-2018-05-28--12_11_15.txt

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.model Level 100 Starting model with parameters:

Arguments for InVEST natcap.invest.sdr 3.4.4:

biophysical_table_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/lulc4.csv

dem_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/Projected/Dem.tif

drainage_path

erodibility_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/Projected/soil_ero.tif

erosivity_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/Projected/rain_ero.tif

ic_0_param 0.5

k_param 2

lulc_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/Projected/lulc.tif

results_suffix _s

sdr_max 0.8

threshold_flow_accumulation 1000

watersheds_path C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Dudhwa/Sediment/Input/Watershed.shp

workspace_dir C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Dudhwa\Sediment\output

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:15 natcap.invest.ui.usage ERROR Error when transforming coordinates: local variable 'spatial_ref' referenced before assignment

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\usage.py", line 176, in _merge_local_bounding_boxes

UnboundLocalError: local variable 'spatial_ref' referenced before assignment

05/28/2018 12:11:16 natcap.invest.sdr INFO calculating slope

05/28/2018 12:11:16 natcap.invest.sdr INFO calculating flow direction

05/28/2018 12:11:16 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO labeling flats

05/28/2018 12:11:16 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO draining away from higher

05/28/2018 12:11:17 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO draining towards lower

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO labeling flats

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO draining away from higher

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO draining towards lower

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing INFO flats exist on second pass, must be flat areas that abut the raster edge

05/28/2018 12:11:18 natcap.invest.sdr INFO calculating flow accumulation

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.pygeoprocessing_0_3_3.routing.routing_core WARNING no flow direction found for 0 0

05/28/2018 12:11:18 natcap.invest.sdr INFO calculate ls term

05/28/2018 12:11:18 natcap.invest.sdr INFO classifying streams from flow accumulation raster

05/28/2018 12:11:19 natcap.invest.sdr INFO calculate per pixel W

05/28/2018 12:11:19 natcap.invest.ui.model ERROR Exception while executing <function execute at 0x11C6AB70>

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\model.py", line 1505, in _logged_target

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\sdr.py", line 205, in execute

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\sdr.py", line 554, in _calculate_w

File "site-packages\pygeoprocessing\geoprocessing.py", line 1207, in reclassify_raster

File "site-packages\pygeoprocessing\geoprocessing.py", line 198, in raster_calculator

File "site-packages\pygeoprocessing\geoprocessing.py", line 1201, in _map_dataset_to_value_op

ValueError: The following 1 raster values [0] from "C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Dudhwa\Sediment\output\aligned_lulc_s.tif" do not have corresponding entries in the value_map: {1.0: 0.8, 2.0: 0.1, 7.0: 0.06, 9.0: 0.004, 10.0: 0.01, 12.0: 0.054, 14.0: 0.4, 16.0: 0.001}

05/28/2018 12:11:19 natcap.invest.ui.model INFO Execution finished

05/28/2018 12:11:19 natcap.invest.utils INFO Elapsed time: 3.26s

05/28/2018 12:11:19 natcap.invest.ui.execution ERROR Target <function _logged_target at 0x04B9D0F0> failed with exception

Traceback (most recent call last):

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\execution.py", line 68, in run

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\ui\model.py", line 1505, in _logged_target

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\sdr.py", line 205, in execute

File "c:\users\natcap-servers\jenkins-home\workspace\natcap.invest\label\gce-windows-1\release_env\lib\site-packages\natcap\invest\sdr.py", line 554, in _calculate_w

File "site-packages\pygeoprocessing\geoprocessing.py", line 1207, in reclassify_raster

File "site-packages\pygeoprocessing\geoprocessing.py", line 198, in raster_calculator

File "site-packages\pygeoprocessing\geoprocessing.py", line 1201, in _map_dataset_to_value_op

ValueError: The following 1 raster values [0] from "C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Dudhwa\Sediment\output\aligned_lulc_s.tif" do not have corresponding entries in the value_map: {1.0: 0.8, 2.0: 0.1, 7.0: 0.06, 9.0: 0.004, 10.0: 0.01, 12.0: 0.054, 14.0: 0.4, 16.0: 0.001}

05/28/2018 12:11:19 natcap.invest.ui.execution INFO Execution finished

Tagged:

• Member, NatCap Staff
Hi Sumit -

That error suggests that there is a value of 0 in your LULC raster that is not included in your biophysical table. Sometimes the value of 0 is not obvious, it's a background value, so look closely at your LULC raster and see if that's the problem.

~ Stacie

• Member
Hi Stacie,

I have thoroughly looked into the LULC raster and couldn't find any value of 0 in LULC. I have tried to run on two different locations and still finding the same error. Please help me with the error.

Thanks
Sumit
• Member
Hello Stacie,

I am able to run the same model (SDR) with same data successfully with InVEST 3.4.2 version. But facing the problem with 3.4.4 version.
I would really be grateful if you could explain this problem.

Thank you
Sumit

• Member, NatCap Staff
Hi Sumit -

I don't know why it is working with one version but not the other - that's a good question for our software developers. To help them/us answer this, can you send your input data for us to try? You can put it up on Google Drive or Dropbox or any place that works for you that we can access - thanks!

~ Stacie

• Member
Hi Stacie

Sure, I will upload and share the data by this weekend. Please provide me the mail id to share via google drive.

Thanks
Sumit Anand
• Member, NatCap Staff
Thanks for providing your data, Sumit. I have tested and verified the issue with 3.4.4, and it looks rather like a bug to me, so I have forwarded the information to our software team, and we'll follow up soon.

Meanwhile, I think that you should be fine using 3.4.2 for SDR to continue your work.

~ Stacie
• Member
edited June 2018
Hello Stacie

Thank you for the information.

Although, I have successfully run the SDR model. I am wondering whether the output of the model is correct or not, as there are holes/no data values in the output results. I have corrected(fill) the DEM. Also, all other input layers don't have holes(no data values). I request you to kindly help with your advice on the same.

Thanks
Sumit
Post edited by sumitanand27 on
• Member, NatCap Staff
Hello Sumit -

Look at the stream.tif output and see if the streams that are defined look correct, or if they are discontinuous around the places that you see holes in your output data. If the streams do not look correct, then try doing another fill on your DEM. We recommend using the QGIS Wang and Liu tool, as it seems to work well in producing a DEM that works with InVEST.

~ Stacie
edited June 2018
Hi @sumitanand27, we've patched the bug you're experincing in a development version of InVEST. If you'd like to try that you can download it here: http://data.naturalcapitalproject.org/nightly-build/invest-forks/richsharp/InVEST_3.4.4.post176+h7f375bb61d1c_x86_Setup.exe

I was able to run the model on the data you provided, but I did notice that your DEM has hydrological pits in it. This leads to a broken stream layer and will yield invalid outputs from this model (see image below of the broken flow accumulation raster from your data). Before you use these results for anything, make sure you fill your DEM with ArcHydro or SAGA GIS's Wang & Liu fill algorithm.

Post edited by Rich on
P.S. see attached for a screenshot of the broken flow accumulation layer from your DEM.
• Member
Hello Rich, this is very helpful. Thank you for the information.  The data(DEM) that I have shared earlier was fill using ArcHydro and I have also fill the DEM using QGIS & ArcGIS, but still getting the same results. The result is same and streams are still broken. Could you please advice me in correcting the DEM.

Thank you,
Sumit
Hi Sumit, I filled your dem for you. Can you try this one instead?

• Member
Thank you so much for your help. The results look good and valid. Streams are now connected.  Now, which software or method should I use to fill dem? Please guide me on the same. Thanks
• Member
Dear Rich,  please ignore my above query. I have figured out the way to correct dem. I am now able to generate the valid outputs.

It would be very helpful if you could guide on the validation & presentation of results. I don't have observed data or secondary data/literature to validate the results of SDR & water yield model. In that case, how should I validate or present the unvalidated results to the audience?
• Member, NatCap Staff
Hi Sumit -

If you don't have observed data for validating the absolute values, we recommend reporting relative values instead. For example, for a single scenario map, you can show the legend values as "Low" to "High" instead of using the actual pixel values. If you are looking at change between scenarios, you can report the percent change, instead of the absolute change. Just make sure to let your audience know that the results are uncalibrated/unvalidated.

~ Stacie
• Member
Hello Stacie

Thanks a bunch for the support. These validation/presentation inputs are very helpful for me.

Thanks again,
Sumit