Skip to content

Commit

Permalink
Merge pull request #22 from robitalec/feat/triplets-case
Browse files Browse the repository at this point in the history
Feat/triplets case
  • Loading branch information
robitalec authored Jan 27, 2024
2 parents 428bf62 + b316ecb commit f2aa025
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 24 deletions.
29 changes: 16 additions & 13 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ message: 'To cite package "camtrapmonitoring" in publications use:'
type: software
license: GPL-3.0-only
title: 'camtrapmonitoring: Camera Trap Monitoring For Estimating Wildlife Density'
version: 0.12.0
version: 0.12.1
abstract: Evaluating potential camera trap locations. Potential locations are evaluated
using relevant spatial layers producing a dataset of selected locations with covariates
that can be used to quantify sampling bias. Soon - density estimation methods.
Expand Down Expand Up @@ -41,7 +41,7 @@ references:
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2023'
year: '2024'
- type: software
title: knitr
abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R'
Expand All @@ -53,7 +53,7 @@ references:
given-names: Yihui
email: [email protected]
orcid: https://orcid.org/0000-0003-0645-5666
year: '2023'
year: '2024'
- type: software
title: rmarkdown
abstract: 'rmarkdown: Dynamic Documents for R'
Expand Down Expand Up @@ -96,7 +96,7 @@ references:
given-names: Richard
email: [email protected]
orcid: https://orcid.org/0000-0003-3925-190X
year: '2023'
year: '2024'
- type: software
title: ggplot2
abstract: 'ggplot2: Create Elegant Data Visualisations Using the Grammar of Graphics'
Expand Down Expand Up @@ -131,7 +131,7 @@ references:
- family-names: Dunnington
given-names: Dewey
orcid: https://orcid.org/0000-0002-9415-4582
year: '2023'
year: '2024'
- type: software
title: usethis
abstract: 'usethis: Automate Package and Project Setup'
Expand All @@ -155,7 +155,7 @@ references:
given-names: Andy
email: [email protected]
orcid: https://orcid.org/0000-0002-7840-692X
year: '2023'
year: '2024'
- type: software
title: osmdata
abstract: 'osmdata: Import ''OpenStreetMap'' Data as Simple Features or Spatial
Expand All @@ -176,7 +176,10 @@ references:
- family-names: Maspons
given-names: Joan
orcid: https://orcid.org/0000-0003-2286-8727
year: '2023'
year: '2024'
identifiers:
- type: url
value: https://github.com/ropensci/osmdata/
- type: software
title: elevatr
abstract: 'elevatr: Access Elevation Data from Various APIs'
Expand All @@ -188,7 +191,7 @@ references:
given-names: Jeffrey
email: [email protected]
orcid: https://orcid.org/0000-0002-9254-9740
year: '2023'
year: '2024'
- type: software
title: sf
abstract: 'sf: Simple Features for R'
Expand All @@ -200,7 +203,7 @@ references:
given-names: Edzer
email: [email protected]
orcid: https://orcid.org/0000-0001-8049-7069
year: '2023'
year: '2024'
version: '>= 0.7-3'
- type: software
title: terra
Expand All @@ -213,19 +216,19 @@ references:
given-names: Robert J.
email: [email protected]
orcid: https://orcid.org/0000-0001-5872-2872
year: '2023'
year: '2024'
- type: software
title: distanceto
abstract: 'distanceto: Calculate Distance to Features'
notes: Imports
url: https://robitalec.github.io/distance-to/
repository: https://CRAN.R-project.org/package=distanceto
repository: https://robitalec.r-universe.dev
authors:
- family-names: Robitaille
given-names: Alec L.
email: [email protected]
orcid: https://orcid.org/0000-0002-4706-1762
year: '2023'
year: '2024'
- type: software
title: 'R: A Language and Environment for Statistical Computing'
notes: Depends
Expand All @@ -234,7 +237,7 @@ references:
- name: R Core Team
location:
name: Vienna, Austria
year: '2023'
year: '2024'
institution:
name: R Foundation for Statistical Computing
version: '>= 4.0'
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: camtrapmonitoring
Title: Camera Trap Monitoring For Estimating Wildlife Density
Version: 0.12.0
Version: 0.12.1
Authors@R:
person(given = "Alec L.",
family = "Robitaille",
Expand All @@ -14,7 +14,7 @@ Description: Evaluating potential camera trap locations.
License: GPL-3 | file LICENSE
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
RoxygenNote: 7.3.0
Roxygen: list(markdown = TRUE)
Suggests:
testthat,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# camtrapmonitoring 0.12.1

* added "triplet" case to `grid_design` and `grid_ct` [#22](https://github.com/robitalec/camtrapmonitoring/pull/22)



# camtrapmonitoring 0.12.0 (2023-07-27)

First release with repo status = active, non-development version numbers
Expand Down
12 changes: 10 additions & 2 deletions R/grid-ct.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#' traps around each.
#'
#' @inheritParams eval_pt
#' @param case "queen", "rook" or "bishop". Ignored if `n` is provided.
#' @param case "queen", "rook", "bishop", or "triplet". Ignored if `n` is provided.
#' @param distance distance between adjacent camera traps. Don't worry about
#' the hypotenuse.
#' @param id default: "id_sample_ct" generated automatically from [sample_ct()]
Expand Down Expand Up @@ -120,7 +120,15 @@ grid_design <- function(distance, case, n) {
data.frame(X = c(0, distance, 0, -distance),
Y = c(distance, 0, -distance, 0))
)
} else if (case == 'triplet') {
denom <- 2 * sqrt(3)
shift <- distance / sqrt(3)
rbind(
list(0, 0),
data.frame(X = c(-distance / 2, distance / 2),
Y = c((-distance / denom) - shift, (-distance / denom) - shift))
)
} else {
stop('case provided must be one of "queen", "rook" or "bishop"')
stop('case provided must be one of "queen", "rook", "bishop" or "triplet"')
}
}
6 changes: 3 additions & 3 deletions codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
"codeRepository": "https://github.com/robitalec/camtrapmonitoring",
"issueTracker": "https://github.com/robitalec/camtrapmonitoring/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.12.0",
"version": "0.12.1",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
"url": "https://r-project.org"
},
"runtimePlatform": "R version 4.3.1 (2023-06-16)",
"runtimePlatform": "R version 4.3.2 (2023-10-31)",
"author": [
{
"@type": "Person",
Expand Down Expand Up @@ -164,7 +164,7 @@
},
"SystemRequirements": null
},
"fileSize": "2956.652KB",
"fileSize": "2995.024KB",
"relatedLink": "https://robitalec.github.io/camtrapmonitoring/",
"releaseNotes": "https://github.com/robitalec/camtrapmonitoring/blob/master/NEWS.md",
"readme": "https://github.com/robitalec/camtrapmonitoring/blob/main/README.md",
Expand Down
3 changes: 2 additions & 1 deletion man/camtrapmonitoring.Rd

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

2 changes: 1 addition & 1 deletion man/grid_ct.Rd

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

2 changes: 1 addition & 1 deletion man/grid_design.Rd

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

20 changes: 19 additions & 1 deletion tests/testthat/test-grid-ct.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ points <- sample_ct(clearwater_lake_density, 15, type = 'random')
queen <- grid_ct(points, case = 'queen', distance = 100)
rook <- grid_ct(points, case = 'rook', distance = 100)
bishop <- grid_ct(points, case = 'bishop', distance = 100)
triplet <- grid_ct(points, case = 'triplet', distance = 100)


# tests
test_that("grid_ct's arguments are checked", {
expect_error(
grid_ct(features = points, distance = 100, case = 'potato'),
'case provided must be one of "queen", "rook" or "bishop"'
'case provided must be one of "queen", "rook", "bishop" or "triplet"'
)

expect_error(
Expand Down Expand Up @@ -67,6 +69,11 @@ test_that("grid_ct returns expected lengths", {
nrow(grid_ct(features = points, distance = 100, case = 'bishop')),
nrow(points) * 5
)

expect_equal(
nrow(grid_ct(features = points, distance = 100, case = 'triplet')),
nrow(points) * 3
)
})


Expand All @@ -83,6 +90,10 @@ test_that("grid_ct returns expected columns... for sf input", {
'id_grid_ct',
colnames(bishop)
)
expect_in(
'id_grid_ct',
colnames(triplet)
)
expect_in(
'focal',
colnames(queen)
Expand All @@ -95,6 +106,10 @@ test_that("grid_ct returns expected columns... for sf input", {
'focal',
colnames(bishop)
)
expect_in(
'focal',
colnames(triplet)
)



Expand All @@ -111,6 +126,9 @@ test_that("grid_ct returns expected columns... for sf input", {
expect_equal(
max(bishop$id_grid_ct), nrow(points) * 5
)
expect_equal(
max(triplet$id_grid_ct), nrow(points) * 3
)
})


Expand Down
6 changes: 6 additions & 0 deletions vignettes/intro-camtrapmonitoring.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ or the 'n' argument.
```{r}
plot(grid_design(distance = 100, case = 'queen'))
plot(grid_design(distance = 100, case = 'bishop'))
plot(grid_design(distance = 100, case = 'rook'))
plot(grid_design(distance = 100, case = 'triplet'))
plot(grid_design(distance = 250, n = 13))
```

Expand Down

0 comments on commit f2aa025

Please sign in to comment.