Skip to content

Commit

Permalink
all terra now
Browse files Browse the repository at this point in the history
  • Loading branch information
gisler committed Nov 18, 2023
1 parent d76f392 commit f7ac0f5
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
2 changes: 0 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Imports:
checkmate,
graphics,
methods,
raster (>= 3.6.3),
Rcpp,
stats,
terra,
Expand All @@ -36,7 +35,6 @@ Imports:
Suggests:
knitr,
rmarkdown,
sp,
tinytest,
whitebox (>= 2.0.0)
LinkingTo:
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ exportMethods(transportCalcOrder)
exportMethods(transportPrerequisites)
import(checkmate)
import(methods)
import(raster)
import(terra)
importFrom(Rcpp,sourceCpp)
importFrom(graphics,abline)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# RPhosFate v1.0.4.9000

* Switched to utilising the `SpatRaster` class from the `terra` package instead of the `RasterLayer` class from the `raster` package. However, the transition from `raster` to `terra` encompasses only the core and not `DEMrelatedInput()` yet.
* Switched to utilising the `SpatRaster` and `SpatVector` classes from the `terra` package instead of the `RasterLayer` class from the `raster` and the `Spatial*DataFrame` classes from the `sp` packages.
* Added `is_ths` argument to `RPhosFate()` and `catchment()` constructors: allows for specifying the number of threads to use for processing.
* Ceased support for _ERDAS IMAGINE_ (\*.img) raster files. `img2tif()` can be used to convert all _ERDAS IMAGINE_ raster files in a directory and its subdirectories into _GeoTIFF_ raster files.
* Dropped backward compatibility to major version zero.
Expand Down
1 change: 0 additions & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#' @import checkmate
#' @import methods
#' @import raster
#' @import terra
#' @importFrom graphics abline clip par
#' @importFrom Rcpp sourceCpp
Expand Down
40 changes: 19 additions & 21 deletions R/input.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ demoProject <- function(cs_dir = tempdir(TRUE)) {
#' raster digital elevation model.
#' @param cs_cha A character string specifying a path to a potentially large
#' raster providing channels.
#' @param sp_msk An [`sp::SpatialPolygonsDataFrame-class`] providing a somewhat
#' oversized catchment mask used to clip the potentially large input rasters
#' for further processing.
#' @param sp_olp An [`sp::SpatialPointsDataFrame-class`] providing the desired
#' catchment outlet(s).
#' @param sp_sds An [`sp::SpatialPointsDataFrame-class`] providing channel
#' sources.
#' @param sp_msk A [`terra::SpatVector-class`] providing a somewhat oversized
#' catchment polygon mask used to clip the potentially large input rasters for
#' further processing.
#' @param sp_olp A [`terra::SpatVector-class`] providing the desired catchment
#' outlet point(s).
#' @param sp_sds A [`terra::SpatVector-class`] providing channel source points.
#' @param cs_rds An optional character string specifying a path to a potentially
#' large raster providing roads.
#' @param cs_wgs An optional character string specifying a path to a potentially
Expand Down Expand Up @@ -189,8 +188,11 @@ DEMrelatedInput <- function(
qassert(cs_dem, "S1")
qassert(cs_cha, "S1")
assertClass(sp_msk, "SpatVector")
assertTRUE(is.polygons(sp_msk))
assertClass(sp_olp, "SpatVector")
assertTRUE(is.points(sp_olp))
assertClass(sp_sds, "SpatVector")
assertTRUE(is.points(sp_sds))
if (!is.null(cs_rds)) {
qassert(cs_rds, "S1")
}
Expand Down Expand Up @@ -491,10 +493,7 @@ DEMrelatedInput <- function(

rl_dem_brd <- rast("dem_bnt_brd.tif")
rl_dem_brd <- lapp(
c(
x = rl_dem_brd,
y = rl_cha_map_cha
),
c(x = rl_dem_brd, y = rl_cha_map_cha),
fun = function(x, y) {
ifelse(is.na(y), x, x + ns_brn)
},
Expand All @@ -507,13 +506,10 @@ DEMrelatedInput <- function(
cells(rl_cha_map),
directions = "queen",
include = TRUE
)), cells(rl_cha_map_cha == 1L))] <- 1L
)), unlist(cells(rl_cha_map_cha, 1L)))] <- 1L

rl_dem_brd <- lapp(
c(
x = rl_dem_brd,
y = rl_cha_map
),
c(x = rl_dem_brd, y = rl_cha_map),
fun = function(x, y) {
ifelse(is.na(y), x, x + ns_brn)
},
Expand Down Expand Up @@ -562,11 +558,13 @@ DEMrelatedInput <- function(
slp = rl_slp ,
wsh = rl_wsh
)
for (i in seq_along(toInput)) {
for (item in names(toInput)) {
set.names(toInput[[item]], item)

writeRaster(
toInput[[i]],
filename = file.path("..", paste0(names(toInput)[i], ".tif")),
datatype = datatype(toInput[[i]]),
toInput[[item]],
filename = file.path("..", paste0(item, ".tif")),
datatype = datatype(toInput[[item]]),
overwrite = TRUE
)
}
Expand All @@ -587,7 +585,7 @@ DEMrelatedInput <- function(

nm_olc <- xyFromCell(
rl_acc,
cells(is.na(rl_slp) & !is.na(rl_cha))
unlist(cells(is.na(rl_slp) & !is.na(rl_cha), 1L))
)

# Clean up temporary files
Expand Down
19 changes: 9 additions & 10 deletions man/DEMrelatedInput.Rd

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

0 comments on commit f7ac0f5

Please sign in to comment.