Skip to content

Commit

Permalink
version 0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JanCaha authored and cran-robot committed Apr 16, 2020
1 parent bdc2666 commit b54d500
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 87 deletions.
10 changes: 5 additions & 5 deletions DESCRIPTION
@@ -1,7 +1,7 @@
Package: SpatialKDE
Type: Package
Title: Kernel Density Estimation for Spatial Data
Version: 0.5.0
Version: 0.6.1
URL: https://jancaha.github.io/SpatialKDE/index.html,
https://github.com/JanCaha/SpatialKDE
Authors@R:
Expand All @@ -18,14 +18,14 @@ Description: Calculate Kernel Density Estimation (KDE) for spatial data.
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.0.2
RoxygenNote: 7.1.0
VignetteBuilder: knitr
LinkingTo: Rcpp
Imports: Rcpp, sf, dplyr, glue, magrittr, rlang, methods, raster
Suggests: tmap, sp, knitr, testthat (>= 2.1.0)
Suggests: tmap, sp, knitr, rgdal, testthat (>= 2.1.0)
NeedsCompilation: yes
Packaged: 2019-12-16 08:14:56 UTC; Caha
Packaged: 2020-04-16 12:09:30 UTC; Cahik
Author: Jan Caha [aut, cre] (<https://orcid.org/0000-0003-0165-0606>)
Maintainer: Jan Caha <jan.caha@outlook.com>
Repository: CRAN
Date/Publication: 2019-12-16 11:40:06 UTC
Date/Publication: 2020-04-16 12:30:02 UTC
22 changes: 11 additions & 11 deletions MD5
@@ -1,26 +1,26 @@
45dac6d9b8643dcc67e022fdc27f2026 *DESCRIPTION
c75c9c1416bbd11badabcf0c3bc5e112 *DESCRIPTION
82179e94a9c57510eeb0dfa196cd97cb *LICENSE
f9384b67978f362e89b618ef0b1b5a48 *NAMESPACE
156fd5b034e4172f87effa1677d5cc1b *NEWS.md
46ff90eda42db6d37a5a20a97cecc8d1 *R/RcppExports.R
09594a0a342b8d125bd90783bd40fc58 *NAMESPACE
bc1288350d26e12bc7c34f4deb461799 *NEWS.md
261b4ed94b2c65db40b1346ea1b5f8b8 *R/RcppExports.R
e11ac6cfc676e4a3d0ebc35c4492e8de *R/create_grid.R
bb39c117653c3bf19fcde4d7aea1dd6c *R/create_raster.R
eefb7801ac5594fea1f9bad03ccfc4a8 *R/kde.R
ce451a459864bb5ee71ba1e215d3c8a6 *R/kde.R
ad3f3c64fcdb96e66b1859bd35c48478 *R/utils-pipe.R
ea034c24e4e96a741e65721835b733cf *R/utils.R
6e0dc28feda82e7c39bb6b1638ad036b *R/zzz.R
fc09e35d33437d635f6361e42c35696e *README.md
0e95615d823df27d4b2a94e7be3a749a *build/vignette.rds
ec9a9453d1de23a3d825296f5a447668 *build/vignette.rds
512913a6d2935ccb9dc5d5dc73640404 *inst/doc/SpatialKDE.R
abf6cca3ed36a52d85d0c50a4c33a8d2 *inst/doc/SpatialKDE.Rmd
f70b055123458caa7ef0afa06fc47d4b *inst/doc/SpatialKDE.html
f36f8bece0e36a12e5db5be9951bf64f *inst/doc/SpatialKDE.html
fc333f44de04b8cb7aec0ce9c2d3ff15 *man/create_grid.Rd
89e5d758105098f7ca26068280fd22ad *man/create_raster.Rd
00277ed05f610057238f0007553ded4e *man/kde.Rd
bb5149c39556450a9a8b53c1a39bf04a *man/kde.Rd
1f7896a1b866ff9ae89ba35be7c7b6f1 *man/pipe.Rd
c8e651984bf03903e92a85a54f4e79b4 *src/RcppExports.cpp
746686d03189a416b9c16fb0536c1489 *src/kde.cpp
a5a0dbeb761d861d47a0af14d890dcf3 *src/RcppExports.cpp
8cb810d2b3ca2f4a7f7dd7a2a11707a3 *src/kde.cpp
70b197edb62a1a7250b6a1aa009a5ecd *tests/testthat.R
78b8bef43e80f100e302e047fabaa9af *tests/testthat/test-create_grids_raster.R
9ba68f18046da3b5bd6f4474671a677b *tests/testthat/test-kde.R
2fda00f85833aad168b7a1bc926f1f49 *tests/testthat/test-kde.R
abf6cca3ed36a52d85d0c50a4c33a8d2 *vignettes/SpatialKDE.Rmd
3 changes: 2 additions & 1 deletion NAMESPACE
@@ -1,4 +1,4 @@
# Generated by roxygen2: do not edit by hand
# Generated by roxygen2: do not edit by hand

export("%>%")
export(create_grid_hexagonal)
Expand All @@ -20,6 +20,7 @@ importFrom(raster,values)
importFrom(raster,xyFromCell)
importFrom(rlang,.data)
importFrom(rlang,enquo)
importFrom(rlang,is_double)
importFrom(rlang,quo_text)
importFrom(sf,st_as_sf)
importFrom(sf,st_bbox)
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
@@ -1,3 +1,8 @@
# SpatialKDE 0.6.0

* added `weights` parameter to `kde()`


# SpatialKDE 0.4.0

* rename of `create_raster_rectangular()` to `create_grid_rectangular()` and `create_raster_hexagonal()` to `create_grid_hexagonal()` to avoid confusion about the type of outcome.
Expand Down
4 changes: 2 additions & 2 deletions R/RcppExports.R
@@ -1,7 +1,7 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

kde_estimate <- function(fishnet, points, bw, kernel, scaled = FALSE, decay = 1) {
.Call('_SpatialKDE_kde_estimate', PACKAGE = 'SpatialKDE', fishnet, points, bw, kernel, scaled, decay)
kde_estimate <- function(fishnet, points, bw, kernel, scaled = FALSE, decay = 1, weights = numeric(0)) {
.Call('_SpatialKDE_kde_estimate', PACKAGE = 'SpatialKDE', fishnet, points, bw, kernel, scaled, decay, weights)
}

32 changes: 25 additions & 7 deletions R/kde.R
Expand Up @@ -20,6 +20,7 @@
#' uknown kernel name is used it falls back to the default value.
#' @param scaled \code{logical} specifing if the output values should be scaled. Default value is
#' \code{FALSE}.
#' @param weights \code{numeric} vector of weights for individual \code{points}.
#' @param grid either \code{\link[sf]{sf}} \code{data.frame} (outcome of function
#' \code{\link{create_grid_rectangular}} or \code{\link{create_grid_hexagonal}}) or
#' \code{\link[raster]{Raster-class}} (outcome of function \code{\link{create_raster}}).
Expand All @@ -37,7 +38,7 @@
#' @importFrom dplyr mutate
#' @importFrom glue glue glue_collapse
#' @importFrom Rcpp evalCpp
#' @importFrom rlang .data
#' @importFrom rlang .data is_double
#'
#' @useDynLib SpatialKDE
#'
Expand All @@ -55,6 +56,7 @@ kde <- function(points,
decay = 1,
kernel = "quartic",
scaled = FALSE,
weights = c(),
grid,
cell_size){

Expand All @@ -66,6 +68,16 @@ kde <- function(points,

.validate_points(points)

if (length(weights) == 0) {
weights = rep(1, nrow(points))
}

if (!is_double(weights, n = nrow(points), finite = TRUE)) {
stop(glue::glue("All values of `weights` must be numerical and finite vector (no `NA`s, `Inf` or `-Inf`).",
"The length of the vector must be equal to number of rows in `points`.",
"Length weights is `{length(weights)}` and number of rows in poitns is `{nrow(points)}`."))
}

if (missing(grid) & missing(cell_size)) {
stop("Both variables `grid` and `cellsize` are not specified. Don't know how to create grid for KDE estimation.")
}
Expand Down Expand Up @@ -95,7 +107,8 @@ kde <- function(points,
band_width = band_width,
decay = decay,
kernel = kernel,
scaled = scaled)
scaled = scaled,
weights = weights)

return(kde_calculated)
}
Expand All @@ -106,7 +119,8 @@ kde <- function(points,
band_width,
decay,
kernel,
scaled) {
scaled,
weights) {
UseMethod(".kde")
}

Expand All @@ -117,7 +131,8 @@ kde <- function(points,
band_width,
decay,
kernel,
scaled) {
scaled,
weights) {

.validate_sf(grid)

Expand All @@ -142,7 +157,8 @@ kde <- function(points,
bw = band_width,
kernel = kernel,
scaled = scaled,
decay = decay)
decay = decay,
weights = weights)

grid <- grid %>%
dplyr::mutate(kde_value = kde_values)
Expand All @@ -160,7 +176,8 @@ setMethod(".kde",
band_width,
decay,
kernel,
scaled) {
scaled,
weights) {

.validate_raster_projected(grid)

Expand All @@ -173,7 +190,8 @@ setMethod(".kde",
bw = band_width,
kernel = kernel,
scaled = scaled,
decay = decay)
decay = decay,
weights = weights)

raster::values(grid) <- kde_values

Expand Down
Binary file modified build/vignette.rds
Binary file not shown.

0 comments on commit b54d500

Please sign in to comment.