Skip to content

Commit

Permalink
Merge pull request #5 from ropensci/allow-geographic-coordinate-systems
Browse files Browse the repository at this point in the history
Allow geographic coordinate systems
  • Loading branch information
katarzynam-165 committed Jun 3, 2024
2 parents 0560121 + b80f625 commit 5b37ed8
Show file tree
Hide file tree
Showing 42 changed files with 1,187 additions and 416 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Suggests:
VignetteBuilder: knitr
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE, roclets = c("namespace", "rd", "srr::srr_stats_roclet"))
Depends:
R (>= 3.5.0)
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ importFrom(assertthat,assert_that)
importFrom(grDevices,colorRampPalette)
importFrom(graphics,abline)
importFrom(methods,formalArgs)
importFrom(parallel,clusterEvalQ)
importFrom(parallel,clusterExport)
importFrom(parallel,parLapply)
importFrom(parallel,parLapplyLB)
importFrom(pbapply,pblapply)
importFrom(pbapply,pboptions)
importFrom(pbapply,pbvapply)
importFrom(stats,approx)
importFrom(stats,getCall)
importFrom(stats,quantile)
Expand All @@ -40,14 +43,17 @@ importFrom(terra,"crs<-")
importFrom(terra,"nlyr<-")
importFrom(terra,"res<-")
importFrom(terra,"values<-")
importFrom(terra,adjacent)
importFrom(terra,app)
importFrom(terra,as.matrix)
importFrom(terra,classify)
importFrom(terra,compareGeom)
importFrom(terra,crs)
importFrom(terra,distance)
importFrom(terra,ext)
importFrom(terra,extend)
importFrom(terra,extract)
importFrom(terra,is.lonlat)
importFrom(terra,ncell)
importFrom(terra,nlyr)
importFrom(terra,plot)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
# rangr 1.0.4 (2024-05-30)

### Major improvements

- Added support for lon/lat rasters as input maps

### Minor improvements

- Default value of `max_dist` in `initialise()` is now equal to 0.99 quantile of `kernel_fun` instead of 0.9

- Added examples of lon/lat rasters to package data

- Input maps (`K_map` and `n1_map`) are now wrapped in `sim_data` object

# rangr 1.0.3 (2024-01-23)

### Minor improvements
Expand Down
18 changes: 11 additions & 7 deletions R/K_get_interpolation.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
#' change, ecological disturbance, etc.) one needs to provide time-varying
#' carrying capacity maps.
#'
#' Either `K_time_points` or `time` parameter are needed to calculate
#' interpolation. If interpolation should be calculated between two carrying
#' Either `K_time_points` or the `time` parameter is needed to calculate
#' interpolation. If interpolation should be calculated between two carrying
#' capacity maps, there is no need to pass the time points, because 1 will
#' be set as a starting time point and `time` will be used as the ending point.
#' On the other hand, in the absence of the `time` argument, the last element of
#' `K_time_points` is considered to be the ending point for the interpolation.
#' be set as the starting time point and `time` will be used as the ending point.
#' On the other hand, in the absence of the `time` argument, the maximum element
#' of `K_time_points` is considered to be the ending point for the interpolation.
#'
#'
#'
Expand Down Expand Up @@ -111,6 +111,10 @@ K_check <- function(K_map, K_time_points, time) {
!is.null(time) || (!is.null(K_time_points)),
msg = "Either \"K_time_points\" or \"time\" must be specified")

assert_that(
!any(duplicated(K_time_points)),
msg = "\"K_time_points\" should contain only unique values")

# number of layers
nls <- nlyr(K_map)

Expand Down Expand Up @@ -157,7 +161,7 @@ K_check <- function(K_map, K_time_points, time) {
"Argument \"time\" is no specified - ",
"last number from \"K_time_points\" is used as \"time\""
)
time <- K_time_points[ntp]
time <- max(K_time_points)

} else {

Expand All @@ -170,7 +174,7 @@ K_check <- function(K_map, K_time_points, time) {
K_time_points <- c(1, time) # default time points for 2-layered K_map
} else {
assert_that(
K_time_points[ntp] == time,
max(K_time_points) == time,
msg = "Last element of \"K_time_points\" should be equal to \"time\"")
}
}
Expand Down
124 changes: 124 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,130 @@ NULL
#' @srrstats {G5.1} dataset used in examples is exported and documented
NULL

#' @name K_small_lon_lat.tif
#' @title Example Of Carrying Capacity Map (Small)
#' @docType data
#'
#' @description
#' [`SpatRaster`][terra::SpatRaster-class] object that represents a carrying
#' capacity map projected to WGS 84 (CRS84) from the original raster `K_small`.
#' This map can be used as a carrying capacity map to initialize data necessary
#' to perform a simulation. It is compatible with the `n1_small_lon_lat.tif` raster.
#'
#' @format [`SpatRaster`][terra::SpatRaster-class] object with 12 rows
#' and 14 columns containing integer values 0-100 and NA's
#' (indicating unsuitable areas).
#'
#' @source Data generated in-house to serve as an example
#' (using spatial autocorrelation)
#'
#' @examples
#' system.file("input_maps/K_small_lon_lat.tif", package = "rangr")
#'
#' @srrstats {G1.4} uses roxygen documentation
#' @srrstats {G5.1} dataset used in examples is exported and documented
NULL


#' @name K_small_changing_lon_lat.tif
#' @title Example Of Changing Carrying Capacity Maps (Small)
#' @docType data
#'
#' @description
#' [`SpatRaster`][terra::SpatRaster-class] object representing changing carrying
#' capacity maps projected to WGS 84 (CRS84) from the original raster
#' `K_small_changing`. These maps can be used as carrying capacity maps to initialize
#' data necessary to perform a simulation. To use these maps in the initialization
#' process, the user first has to use [`K_get_interpolation`] to generate a map for
#' every time step of the simulation. These maps are compatible with the
#' `n1_small_lon_lat.tif` raster.
#'
#' @format [`SpatRaster`][terra::SpatRaster-class] object with 3 layers,
#' each having 12 rows and 14 columns containing integer values 0-170 and NA's
#' (indicating unsuitable areas).
#'
#' @source Data generated in-house to serve as an example
#' (using spatial autocorrelation)
#'
#' @examples
#' system.file("input_maps/K_small_changing_lon_lat.tif", package = "rangr")
#'
#' @srrstats {G1.4} uses roxygen documentation
#' @srrstats {G5.1} dataset used in examples is exported and documented
NULL


#' @name K_big_lon_lat.tif
#' @title Example Of Carrying Capacity Map (Big)
#' @docType data
#'
#' @description
#' [`SpatRaster`][terra::SpatRaster-class] object representing a carrying
#' capacity map projected to WGS 84 (CRS84) from the original raster `K_big`.
#' This map can be used as a carrying capacity map to initialize data necessary
#' to perform a simulation. It is compatible with the `n1_big_lon_lat.tif` raster.
#'
#' @format [`SpatRaster`][terra::SpatRaster-class] object with 74 rows
#' and 125 columns containing integer values 0-25 and NA's
#' (indicating unsuitable areas).
#'
#' @source Data generated in-house to serve as an example
#' (using spatial autocorrelation)
#'
#' @examples
#' system.file("input_maps/K_big_lon_lat.tif", package = "rangr")
#'
#' @srrstats {G1.4} uses roxygen documentation
NULL


#' @name n1_small_lon_lat.tif
#' @title Example Of Abundance Map At First Time Step Of The Simulation (Small)
#' @docType data
#'
#' @description
#' [`SpatRaster`][terra::SpatRaster-class] object representing an abundance map
#' at the first time step of the simulation projected to WGS 84 (CRS84) from the
#' original raster `n1_small`. This map can be used as a simulation starting point
#' to initialize data necessary to perform a simulation. It is compatible with the
#' `K_small_lon_lat.tif` and `K_small_changing_lon_lat.tif` maps.
#'
#' @format [`SpatRaster`][terra::SpatRaster-class] object with 12 rows
#' and 14 columns containing integer values 0-10 and NA's
#' (indicating unsuitable areas).
#'
#' @source Data generated in-house to serve as an example
#'
#' @examples
#' system.file("input_maps/n1_small_lon_lat.tif", package = "rangr")
#'
#' @srrstats {G1.4} uses roxygen documentation
NULL


#' @name n1_big_lon_lat.tif
#' @title Example Of Abundance Map At First Time Step Of The Simulation (Big)
#' @docType data
#'
#' @description
#' [`SpatRaster`][terra::SpatRaster-class] object representing an abundance map
#' at the first time step of the simulation projected to WGS 84 (CRS84) from the
#' original raster `n1_big`. This map can be used as a simulation starting point
#' to initialize data necessary to perform a simulation. It is compatible with the
#' `K_big_lon_lat.tif` map.
#'
#' @format [`SpatRaster`][terra::SpatRaster-class] object with 74 rows
#' and 125 columns containing integer values 0-50 and NA's
#' (indicating unsuitable areas).
#'
#' @source Data generated in-house to serve as an example
#'
#' @examples
#' system.file("input_maps/n1_big_lon_lat.tif", package = "rangr")
#'
#' @srrstats {G1.4} uses roxygen documentation
#' @srrstats {G5.1} dataset used in examples is exported and documented
NULL


#' @title Example Of Observation Points List
Expand Down
Loading

0 comments on commit 5b37ed8

Please sign in to comment.