Skip to content

Commit

Permalink
Upload from main
Browse files Browse the repository at this point in the history
Pull changes from camtraptor 0.27, see #344
  • Loading branch information
damianooldoni committed Dec 24, 2024
1 parent d5e46a2 commit acf06d7
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ BugReports: https://github.com/inbo/camtraptor/issues
Depends:
R (>= 3.5.0)
Imports:
activity,
assertthat,
camtrapdp,
dplyr (>= 1.1.0),
Expand All @@ -45,6 +46,7 @@ Imports:
leaflet,
lifecycle,
lubridate,
overlap,
purrr,
RColorBrewer,
readr,
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ This is a major release that updates the internal data model to Camtrap DP 1.0 a
- Function `filter_out_timelapse()` allows to filter out timelapse observations (#306). See [`camtrapdp::filter_out_timelapse()`](https://inbo.github.io/camtrapdp/reference/filter_out_timelapse.html).
- File `CITATION.cff` added to the package (#345).

# camtraptor 0.27.0

- `get_record_table()` returns now 4 new columns: `longitude`, `latitude` (deployment coordinates), `clock` (clock time of the observation in radians) and `solar` (sun time of the observation in radians) (#341).

# camtraptor 0.26.0

- `get_custom_effort()` returns now the effort for each deployment separately (#333). The returned data frame has two new columns: `deploymentID` and `locationName`.
Expand Down
20 changes: 20 additions & 0 deletions R/camtrapR_recordTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#' as defined in column `filePath` of `media`.
#' - `Filename`: List, file names of the images linked to the given record,
#' as defined in column `fileName` of `media`.
#' - `Latitude`: Numeric, latitude of the station, based on `deploymentID` of the observations.
#' - `Longitude`: Numeric, longitude of the station, based on `deploymentID` of the observations.
#' - `clock`: Numeric, clock time in radians.
#' - `solar`: Numeric, solar time in radians. Calculated using `overlap::sunTime`, which essentially uses the approach described in [Nouvellet et al. (2012)](https://doi.org/10.1111/j.1469-7998.2011.00864.x).
#' @inheritParams n_species
#' @family camtrapR-derived functions
#' @export
Expand Down Expand Up @@ -172,6 +176,10 @@ camtrapR_recordTable <- function(x,
)

# remove observations of unidentified individuals
# Add coordinates to observations
x <- add_coordinates(x)

# Remove observations of unidentified individuals
obs <- observations(x) %>%
dplyr::filter(!is.na(.data$scientificName))

Expand Down Expand Up @@ -277,6 +285,18 @@ camtrapR_recordTable <- function(x,
)) %>%
dplyr::ungroup()

# Add clock time in radians
record_table <- record_table %>%
dplyr::mutate(clock = activity::gettime(.data$timestamp))
# Add solar time in radians
matrix_coords <- matrix(c(record_table$longitude, record_table$latitude),
ncol = 2)
record_table <- record_table %>%
dplyr::mutate(solar = overlap::sunTime(.data$clock,
.data$timestamp,
matrix_coords))

# Finalize `record_table`
record_table <- record_table %>%
dplyr::rename(Station := !!stationCol,
Species = "scientificName",
Expand Down
37 changes: 30 additions & 7 deletions tests/testthat/test-camtrapR_recordTable.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ test_that("input of camtrapR_recordTable, removeDuplicateRecords, is checked pro
removeDuplicateRecords = NA
))
})
test_that("warning is returned if some observations have no timestamp", {
mica_no_timestamp <- mica
mica_no_timestamp$data$observations$timestamp[3:5] <- NA
expect_warning(
get_record_table(mica_no_timestamp),
"Some observations have no timestamp and will be removed."
)
})

test_that("right columns are returned", {
skip_if_offline()
Expand All @@ -88,7 +96,11 @@ test_that("right columns are returned", {
"delta.time.hours",
"delta.time.days",
"Directory",
"FileName"
"FileName",
"latitude",
"longitude",
"clock",
"solar"
)
)
})
Expand Down Expand Up @@ -201,8 +213,7 @@ test_that(
by = "sequenceID"
)
expect_equal(output$len, output$n_media)
}
)
})

test_that(paste(
"removeDuplicateRecords allows removing duplicates,",
Expand Down Expand Up @@ -250,19 +261,31 @@ test_that(paste(
)
})

test_that("clock is always in the range [0, 2*pi]", {
clock_values <- get_record_table(mica) %>%
dplyr::pull(clock)
expect_true(all(clock_values >= 0))
expect_true(all(clock_values <= 2 * pi))
})

test_that("solar is always in the range [0, 2*pi]", {
solar_values <- get_record_table(mica) %>%
dplyr::pull(solar)
expect_true(all(solar_values >= 0))
expect_true(all(solar_values <= 2 * pi))
})

test_that("get_record_table() is deprecated and calls camtrapR_recordTable()", {
skip_if_offline()
x <- example_dataset()
lifecycle::expect_deprecated(get_record_table(x))
})

test_that(
"output of get_record_table() is the same as camtrapR_recordTable()",
{
"output of get_record_table() is the same as camtrapR_recordTable()", {
skip_if_offline()
x <- example_dataset()
expect_identical(
suppressWarnings(get_record_table(x)),
camtrapR_recordTable(x))
}
)
})

0 comments on commit acf06d7

Please sign in to comment.