Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watershed Analysis - Test and Ducumentation with new names #1537

Merged
merged 5 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ src/Makevars.ucrt.rej
proj_conf_test
.Rproj

proj_conf_test*
*.Rproj
*.tar.gz
*Rcheck/
*.o
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Authors@R: c(
person("Robert J.", "Hijmans", role = c("cre", "aut"),
email = "[email protected]", comment = c(ORCID = "0000-0001-5872-2872")),
person("Roger", "Bivand", role = "ctb", comment = c(ORCID = "0000-0003-2392-6140")),
person("Cordana", "Emanuele", role="ctb"),
person("Emanuele", "Cordano", role="ctb",comment = c(ORCID= "0000-0002-3508-5898")),
person("Krzysztof", "Dyba", role = "ctb", comment = c(ORCID = "0000-0002-8614-3816")),
person("Edzer", "Pebesma", role = "ctb", comment = c(ORCID = "0000-0001-8049-7069")),
person("Michael D.", "Sumner", role = "ctb"))
Expand Down
5 changes: 4 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ exportMethods("[", "[[", "!", "%in%", activeCat, "activeCat<-", "add<-", addCats

## EC 20210702 ecor
exportMethods(watershed, pitfinder, NIDP, flowAccumulation)

## EC 20250606 ecor
###exportMethods(watershed2,pitfinder2,NIDP2,flowAccu2,flowAccu2_weight)
## END EC

S3method(cbind, SpatVector)
S3method(rbind, SpatVector)
Expand All @@ -28,3 +30,4 @@ export(add_box, add_legend, add_grid, focalMat, extractAlong, gdal, getGDALconfi




5 changes: 3 additions & 2 deletions R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -1060,15 +1060,16 @@ setMethod("terrain", signature(x="SpatRaster"),
function(x, v="slope", neighbors=8, unit="degrees", filename="", ...) {

if (v=="flowacc") {
flowAccu2(x,filename=filename,...)
flowAccumulation(x,filename=filename,...)

} else {
unit <- match.arg(unit, c("degrees", "radians"))
opt <- spatOptions(filename, ...)
seed <- ifelse("flowdir" %in% v, .seed(), 0)
x@ptr <- x@ptr$terrain(v, neighbors[1], unit=="degrees", seed, opt)
messages(x, "terrain")

}
messages(x, "terrain")
}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ flowacc0 <- c(001,001,001,001,001,001,


flowdir1 <- terrain(elev,"flowdir")
flowacc1 <- flowAccu2(flowdir1)
flowacc1 <- flowAccumulation(flowdir1)

result <- (flowacc1==flowacc0) & (flowdir1==flowdir0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ flowdir<- terrain(elev,v="flowdir")

## Pit Detect

pits1 <- pitfinder2(flowdir)
pits1 <- pitfinder(flowdir)

xypit <- as.data.frame(pits1,xy=TRUE)
names(xypit) <- c("x","y","pit")
Expand Down
4 changes: 2 additions & 2 deletions man/NIPD.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ plot(flowdir1)
plot(flowdir2)

##
nidp1 <- NIDP2((flowdir1))
nidp2 <- NIDP2((flowdir2))
nidp1 <- NIDP((flowdir1))
nidp2 <- NIDP((flowdir2))

t(array(nidp1[],rev(dim(nidp1)[1:2])))
t(array(nidp2[],rev(dim(nidp2)[1:2])))
Expand Down
20 changes: 10 additions & 10 deletions man/flowAccumulaion.Rd → man/flowAccumulation.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Computes flow accumulation or the total contributing area in terms of numbers of
}

\usage{
\S4method{flowAccu2}{SpatRaster}(x, weight=NULL, filename="", ...)
\S4method{flowAccumulation}{SpatRaster}(x, weight=NULL, filename="", ...)
}

\arguments{
Expand All @@ -30,7 +30,7 @@ SpatRaster
The algorithm is an adaptation of the one proposed by Zhou at al, 2019.
}

\seealso{\code{\link{terrain}},\code{\link{watershed2}},\code{\link{NIDP2}}}
\seealso{\code{\link{terrain}},\code{\link{watershed}},\code{\link{NIDP}}}

\author{
Emanuele Cordano
Expand All @@ -53,7 +53,7 @@ for (r in 1:nrow(elev1)) {

x <- (c-5)*dy
elev1[r,c] <- 5*(x^2+y^2)
elev2[r,c] <- 10+5*(abs(x))-0.001*y ### 5*(x^2+y^2)
elev2[r,c] <- 10+5*(abs(x))-0.001*y
}
}

Expand All @@ -80,10 +80,10 @@ plot(flowdir1)
plot(flowdir2)

##
flow_acc1 <- flowAccu2((flowdir1))
flow_acc2 <- flowAccu2((flowdir2))
flow_acc1 <- flowAccumulation((flowdir1))
flow_acc2 <- flowAccumulation((flowdir2))
## Alternative option
## here the argument of "terrain"functions is not elevation but flow directions.
## here the argument of "terrain" functions is flow directions instead of elevation.

flow_acc2a <- terrain(flowdir2,"flowacc")
t(array(flow_acc1[],rev(dim(flow_acc1)[1:2])))
Expand All @@ -95,8 +95,8 @@ plot(flow_acc2)
weight <- elev1*0+10


flow_acc1w <- flowAccu2_weight(flowdir1,weight)
flow_acc2w <- flowAccu2_weight(flowdir2,weight)
flow_acc1w <- flowAccumulation(flowdir1,weight)
flow_acc2w <- flowAccumulation(flowdir2,weight)

t(array(flow_acc1w[],rev(dim(flow_acc1w)[1:2])))
t(array(flow_acc2w[],rev(dim(flow_acc2w)[1:2])))
Expand All @@ -111,8 +111,8 @@ elev <- rast(system.file('ex/elev.tif',package="terra"))
flowdir <- terrain(elev,"flowdir")

weight <- cellSize(elev,unit="km")
flowacc_weight <- flowAccu2_weight(flowdir,weight)
flowacc <- flowAccu2(flowdir)
flowacc_weight <- flowAccumulation(flowdir,weight)
flowacc <- flowAccumulation(flowdir)


}
Expand Down
8 changes: 4 additions & 4 deletions man/pitfinder.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ find pits (depressions with no outlet )
}

\arguments{
\item{p}{SpatRaster wih flow-direcion. See \code{\link{terrain}}}
\item{x}{SpatRaster wih flow-direcion. See \code{\link{terrain}}}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
}
Expand All @@ -32,7 +32,7 @@ A \code{\link{SpatRaster-class}} (raster) map containing value 1 for the pits a
Emanuele Cordano
}

\seealso{\code{\link{terrain}},\code{\link{watershed2}},\code{\link{flowAccu2}},\code{\link{flowAccu2_weight}},\code{\link{NIDP2}}}
\seealso{\code{\link{terrain}},\code{\link{watershed}},\code{\link{flowAccumulation}},\code{\link{NIDP}}}
\examples{

## Creation of a Digital Elevation Model
Expand Down Expand Up @@ -60,14 +60,14 @@ t(array(flowdir[],rev(dim(flowdir)[1:2])))

## Pit Detect

pits <- pitfinder2(flowdir)
pits <- pitfinder(flowdir)

## Application wth example DEM

elev <- rast(system.file('ex/elev.tif',package="terra"))
flowdir <- terrain(elev,"flowdir")

pits <- pitfinder2(flowdir)
pits <- pitfinder(flowdir)



Expand Down
2 changes: 1 addition & 1 deletion man/watershed.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ delineate the area covered by a catchment from a SpatRaster with flow direction
}

\arguments{
\item{p}{SpatRaster with flow direction. See \code{\link{terrain}}. }
\item{x}{SpatRaster with flow direction. See \code{\link{terrain}}. }
\item{pourpoint}{matrix or SpatVector with the pour point location}
\item{filename}{character. Output filename}
\item{...}{additional arguments for writing files as in \code{\link{writeRaster}}}
Expand Down
Loading