Running into error in seasonal water yield model

Hi there,

I'm still working on running the seasonal water yield model since my last thread. My partner and I are running the model and after a couple hours of geoprocessing we get this error:
  • Nonetype error: invalid value encountered in divide
I'm not sure what this means and have tried altering some of the data with no luck. I'd be happy to drop someone the log file or data if you have time to help.

Thank you!



  • RichRich Administrator, NatCap Staff
    Hi Pete, that's a frustrating error.  Looks like a divide by zero, inf, or NaN, in the Vri calculation.  That can happen for a number of reasons, but a common one might be that your DEM has hydrological pits in it and isn't getting flow paths long enough to calculate streams.  You can get a good sense of that by inspecting the flow accumulation raster in the intermediate output.  If you see flows starting and stopping all over that's a good sign there are pits.  If so, I'd suggest using SAGA's "Terrain Analysis - Preprocessing -> Fill Sinks (Wang & Liu)"; it comes with QGIS these days to fill your DEM and try again.

    If that's not the issue, can you post a follow up here?
  • ptelarolptelarol Member
    Hi Rich,

    I looked at the flow accumulation raster and it did looked like as you said it might, so I used Wang & Liu in QGIS to fill the DEM, but am still running into the same error. After filling the DEM, INVEST ran much quicker, but I still received the same error in the same lines. Log file is attached. 

  • RichRich Administrator, NatCap Staff
    Dang.  Can you dropbox me your data to  I'll try to run it on my end and see if I can recreate your issue.
  • ptelarolptelarol Member
    Just shared the data. Thank you for the help!
  • RichRich Administrator, NatCap Staff
    Hi, sorry I'm not seeing a dropbox invitation from you.  Can you verify that you sent it to
  • ptelarolptelarol Member
    Hi Rich - I just resent it. Let me know if you don't get an invitation. 
  • RichRich Administrator, NatCap Staff
    Hi, I'm getting back to your issue now.  I'm getting the same error on my end, but am also seeing a bunch of nodata holes on the routing step.  Clicking around, I see those are centered on hydrological pits.  So it seems this error is caused by hydrological pits in the DEM.  For the moment, the only way to get around this is to get the DEM filled & routed. I'll try filling w/ Wang & Liu on my end, but wanted to let you know I was in the midst of that since your run takes a few hours to get through.

    Also, when looking at the slope of your DEM I can see a bunch of artifacts that look like stitching artifacts (they're all grid aligned slope lines).  Just an FYI in case you weren't aware of that.

    I'll post again after I do a pit filling pass to see if I can get a complete run going.
  • RichRich Administrator, NatCap Staff
    Oh boy, I see i ran it on your original unfilled DEM.  Anyway, I'll still try what I said above and post back when I know more.
  • RichRich Administrator, NatCap Staff
    Hi, after filling sinks, I can see another problem.  The SWY model, for the moment, requires all the watersheds to drain to a stream.  The model classifies streams by thresholding flow accumulation.  But things break when a watershed is so small that there's not enough flow accumulation to classify a stream.  On the edge of your DEM I see a bunch of what look like truncated watersheds that look like this issue.  Since some of SWY's equations use a "distance to stream" value, we run into problems here. For reference, this also happens when the DEM doesn't route.  Flow accumulation is too short to classify streams in some watersheds.

    I made a zoomed picture of some of these watersheds on your data w/ the calculated stream layer underneath.  I circled two (of many) polygons that don't have streams in them:

    This half a problem w/ InVEST, and another with the data.  We should have a better error here than "invalid value encountered in divide".  But even if we didn't, it's not clear what to do on these areas except discard them.  Likely I'll get to "fixing" this during the summer, you can follow the issue here:  Note I say "fix" because in the end, the best we can do is throw away those data.  In the meantime, you can either clip out those areas of the DEM that don't route streams. Or have a larger DEM that extends beyond those watersheds.  OR  if you're feeling punchy, you can reduce the threshold flow accumulation value to make more streams.  

    At any rate, I'm sorry for the hassle, and long delay on my end.  If I don't otherwise hear back from you, I'll post on this thread when I patch better error handling into the model.
Sign In or Register to comment.