lucarraro / rivnet

An R-package allowing seamless extraction of river networks from Digital Elevation Models data
https://lucarraro.github.io/rivnet/
Other
13 stars 1 forks source link

Using extract_river in a for loop does not always work #4

Closed andrew-caudillo closed 7 months ago

andrew-caudillo commented 8 months ago

Hello, I was working on getting the catchments for a set of 5 points in Oregon, USA using extract_river() in a for loop, but it did not complete.

For the first 4 sets of points, it worked wonderfully. After the 5th iteration began, the function broke with: Error: z[[i]] subscript out of bounds. I ran the same loop with an iteration of 2, 3, and 4-- the code worked well. I forced the loop to just focus on the last point and it broke again.

I also saw that a single outlet took over 2 hours to process, but it froze my R and never finished. The river and catchment should have both been fairly small with respect to hydrology.

I am wondering if you have seen either of these errors before or know about their cause. I looked in the extract_river() source code, but z was never called outside of defining the zoom factor if the user does not provide a DEM.

for more information on my R ression/machine: I am using the latest version of R (4.3) The DEM that I feed extract_river is valid and the point falls within its extent All of hte necessary software (TauDEM and its exes, MPI, GDAL) are installed successfully and recognized by traudem::sitrep I am using 64 bit Windows 10 machine with 8Gb of RAM

Any help is appreciated.

Thank you,

lucarraro commented 8 months ago

Dear Andrew,

First of all, thank you very much for your interest in my package.

Could you please send me a minimal working example reproducing the error? I did see that error from time to time, but right now I don't have a univocal explanation about why it occurs. But I'd be happy to look at your code and help you with that. You can find my e-mail in the DESCRIPTION file of the package.

Unexpectedly long runtime could be due to computation of flow direction across flat areas. This is performed by TauDEM's AreaD8 and doesn't depend on rivnet. You might want to set displayUpdates = TRUE in order to see where the function gets stuck.

By the way, which version of rivnet are you running?

andrew-caudillo commented 7 months ago

Thank you for your help, Luca. To let anyone else know who may be facing the same issue as I was: it was not the loop that was the issue, but the DEM. The error implied the the watershed exceeded the boundaries of the DEM I provided it. It is much better to provide the extent of a DEM to extract via elvatr than to provide a DEM directly because of the size of the watershed and/or the boundaries of the DEM the user provides. There may be some trial and error when defining the extent with certain watersheds, since they can vary widely based on geography.