SDR model Key error

Hello, this is Sumit a researcher from IIFM, India.

I am facing Key error 1 while running the SDR model. Also using latest InVEST version 3.4.4 Please help me with the mentioned error.

Kindly find the details of log file for your reference:

05/23/2018 17:01:48  natcap.invest.utils INFO     Writing log messages to C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Anamalai\Sediment model\Run1\InVEST-Sediment-Delivery-Ratio-Model-(SDR)-log-2018-05-23--17_01_48.txt
05/23/2018 17:01:48  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/Anamalai/Sediment model/lulc_table.csv
dem_path                    C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Anamalai/Sediment model/Dem1.tif
drainage_path               
erodibility_path            C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Anamalai/Sediment model/soil_ero1.tif
erosivity_path              C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Anamalai/Sediment model/rain_eros1.tif
ic_0_param                  0.4
k_param                     1.4
lulc_path                   C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Anamalai/Sediment model/lulcp1.tif
results_suffix              _s2
sdr_max                     0.8
threshold_flow_accumulation 2000
watersheds_path             C:/Users/hp/Documents/IIFM/NTCA Phase II/InVEST Modelling/InVEST_analysis_TGR/Anamalai/Sediment model/watershd.shp
workspace_dir               C:\Users\hp\Documents\IIFM\NTCA Phase II\InVEST Modelling\InVEST_analysis_TGR\Anamalai\Sediment model\Run1

05/23/2018 17:01:48  natcap.invest.sdr  INFO     calculating slope
05/23/2018 17:01:48  natcap.invest.sdr  INFO     calculating flow direction
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     labeling flats
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     draining away from higher
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     draining towards lower
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing DEBUG    flats exist, calculating flow direction for them
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     labeling flats
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     draining away from higher
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing.routing_core INFO     draining towards lower
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing INFO     flats exist on second pass, must be flat areas that abut the raster edge
05/23/2018 17:01:48  natcap.invest.sdr  INFO     calculating flow accumulation
05/23/2018 17:01:48  natcap.invest.pygeoprocessing_0_3_3.routing DEBUG    starting flow accumulation
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate ls term
05/23/2018 17:01:49  natcap.invest.sdr  INFO     classifying streams from flow accumulation raster
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate per pixel W
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate CP raster
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating RKLS
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating USLE
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating w_bar
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating d_up
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate WS factor
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating d_dn
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate ic
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate sdr
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate sed export
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate sediment retention index
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate sediment retention
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculate S factor
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating d_dn bare soil
05/23/2018 17:01:49  natcap.invest.sdr  INFO     calculating d_up bare soil
05/23/2018 17:01:50  natcap.invest.sdr  INFO     calculate ic
05/23/2018 17:01:50  natcap.invest.sdr  INFO     generating report
05/23/2018 17:01:50  pygeoprocessing.geoprocessing WARNING  Stats not calculated for c:\users\hp\appdata\local\temp\clipped_rasterfgvzoi band 1 since no non-nodata pixels were found.
05/23/2018 17:01:50  pygeoprocessing.geoprocessing WARNING  Stats not calculated for c:\users\hp\appdata\local\temp\clipped_rastere61xmp band 1 since no non-nodata pixels were found.
05/23/2018 17:01:50  natcap.invest.ui.model ERROR    Exception while executing <function execute at 0x12ECAB70>
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 302, 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 926, in _generate_report
KeyError: 1
05/23/2018 17:01:50  natcap.invest.ui.model INFO     Execution finished
05/23/2018 17:01:50  natcap.invest.utils INFO     Elapsed time: 2.12s


Thanks
Sumit

Comments

  • swolnyswolny Member, NatCap Staff
    Hi Sumit -

    Since this error is happening while generating the report, I wonder if there's an issue with the watershd.shp input. Do all of your watersheds (in particular, the one with ws_id = 1) overlap the area covered by the input rasters? If a watershed is outside of that area, or even just partially outside of that area, I've seen that kind of error occur.

    ~ Stacie
  • Thank you Stacie for your prompt reply. I was banging my head since morning in figuring out the error. This is very helpful and it works. 

    It would be very helpful if you could also help me with the results. I am not able to see sed_export raster file, since the values are zero in the watershed_result file for both sediment_retent and sediment_export. Please advice me on the same.

    Thanks again,
    Sumit


  • swolnyswolny Member, NatCap Staff
    When you look at the sed_export.tif output in a GIS, are all of the values zero, or some other value?

    One thing to look at is the stream.tif raster output by SDR. It should have values of 1 where streams are defined. If there are no streams defined, then the model cannot calculate sed_export, since it routes sediment until it reaches a stream, and if this happens you can get an output that's all 0. If streams are not defined, then you'll need to change your threshold flow accumulation value so that realistic streams do get defined. If you do have a good-looking stream network defined, then we'll need to think about other causes.

    ~ Stacie

  • Thanks a ton Stacie for the help.
  • Hello Stacie,

    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


  • Hi Sumit!

    I hope this is not too late, it could be useful for others going through all he SDR error messages though... that error is because of your biophysical table is not matching with your lucode from the lulc raster. Check it out and maybe you are not including all lucodes in there.

    Good luck! :)

  • RichRich Administrator, NatCap Staff
    @sumitanand27 specifically the error message is saying there's a "0" landcover code in the landcover raster but no corresponding entry in your biophysical table. Can you check to see if this is the case and if so add an entry in your biophysical table?
Sign In or Register to comment.