Skip to content

Commit

Permalink
ENH: optionally use "w"-flag in r.watershed to enable disk swap for l…
Browse files Browse the repository at this point in the history
…arge grids

- updated docu
closes #41
  • Loading branch information
TillF committed Jun 18, 2018
1 parent 1f23161 commit 7e9f1b5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
9 changes: 6 additions & 3 deletions R/subbasin.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#' If \code{drainage_dir} or \code{flowaccum} is set to \code{NULL} (default value), both will be calculated by GRASS function \emph{r.watershed}.
#' @param drainage_dir (optional) Existing raster map of drainage direction in GRASS location. Must correspond to map generated by \code{r.watershed}.
#' If \code{flowaccum} or \code{flowaccum} is set to \code{NULL} (default value), both will be calculated by GRASS function \emph{r.watershed}.
#' @param disk_swap (optional) Only needed if memory requirements exceed available RAM (large DEMs): If set to \code{TRUE}, \code{r.watershed} uses the "-m"-flag (slow)
#' @param basin_out Output: Name of subbasins raster map exported into GRASS location.
#' @param stream Output: Prefix of calculated stream segments vector (<stream>_vect) and
#' raster (<stream>_rast) maps exported into GRASS location. Only generated if
Expand Down Expand Up @@ -108,6 +109,7 @@ calc_subbas <- function(
river=NULL,
flowaccum=NULL,
drainage_dir=NULL,
disk_swap=FALSE,

### OUTPUT ###
basin_out=NULL,
Expand Down Expand Up @@ -204,8 +206,9 @@ calc_subbas <- function(
if(is.null(river)) {
message("\nCalculate drainage and river network...\n")
# GRASS watershed calculation #
ws_flags = ifelse(disk_swap,c("overwrite","w"),"overwrite") #flags to use for r.watershed
if(is.null(flowaccum) )
execGRASS("r.watershed", elevation=dem, accumulation="accum_t", drainage="drain_t", flags = "overwrite")
execGRASS("r.watershed", elevation=dem, accumulation="accum_t", drainage="drain_t", flags = ws_flags)
# check thresh_stream parameter
cmd_out <- execGRASS("r.univar", map="accum_t", fs="comma", flags=c("t"), intern=TRUE, ignore.stderr = TRUE)
cmd_out <- strsplit(cmd_out, ",")
Expand All @@ -226,7 +229,7 @@ calc_subbas <- function(
if(is.null(flowaccum) )
{
message("\nCalculate drainage...\n")
execGRASS("r.watershed", elevation=dem, drainage="drain_t")
execGRASS("r.watershed", elevation=dem, drainage="drain_t", flags = ws_flags)
}
}

Expand All @@ -237,7 +240,7 @@ calc_subbas <- function(
message("\nCalculate subbasins based on given area threshold...\n")

# calculate subbasins
execGRASS("r.watershed", elevation=dem, basin="basin_calc_t", threshold=thresh_sub)
execGRASS("r.watershed", elevation=dem, basin="basin_calc_t", threshold=thresh_sub, flags = ws_flags)
}


Expand Down
15 changes: 13 additions & 2 deletions man/calc_subbas.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7e9f1b5

Please sign in to comment.