diff --git a/CHANGELOG.md b/CHANGELOG.md index 5657064..3caff26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,12 +9,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed -- `classify_breed_stage()` takes into account "breeding fail" option. ### Changed ### Removed +## [1.2.0] - 2025-10-10 +### Added +- Deprecation warning for `write_bl_table()` function. + +### Fixed +- `classify_breed_stage()` takes into account "breeding fail" option. +- `construct_bl_table()` round coordinates to 6 decimal places to avoid floating point issues. + ## [1.1.0] - 2025-09-09 ### Added - `classify_breed_stage()` use the hatching and brood end dates to classify @@ -30,6 +37,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - `clean_gps_from_txt()` deprecated. Use `clean_gps()` with `.txt` file instead. -[unreleased]: https://github.com/IslasGECI/templater/compare/v1.1.0...HEAD +[unreleased]: https://github.com/IslasGECI/templater/compare/v1.2.0...HEAD +[1.2.0]: https://github.com/IslasGECI/templater/compare/v1.1.0...v1.2.0 [1.1.0]: https://github.com/IslasGECI/templater/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/IslasGECI/templater/releases/tag/v1.0.0 diff --git a/CITATION.cff b/CITATION.cff new file mode 100644 index 0000000..9dbc40a --- /dev/null +++ b/CITATION.cff @@ -0,0 +1,24 @@ +cff-version: 1.2.0 +message: "If you use this software, please cite it using the following metadata." +title: "seabird_tracking" +type: software +authors: + - family-names: "Olvera-Guerrero" + given-names: "Guillermo" + github: "MemoOlv" + orcid: "https://orcid.org/0000-0002-6900-5315" + - family-names: "Rojas-Mayoral" + given-names: Evaristo + orcid: "https://orcid.org/0000-0001-6812-9562" + github: devarops + - family-names: "Villasante-Barahona" + given-names: "Mario" + orcid: "https://orcid.org/0009-0001-7867-8570" + github: "mvillasante" +repository-code: "https://github.com/IslasGECI/seabird_tracking" +keywords: + - ecology + - R + - seabird + - tracking +license: "agpl-3.0-only" diff --git a/DESCRIPTION b/DESCRIPTION index 6c6b187..20d56e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -13,12 +13,13 @@ Imports: bycatch, dplyr, geci.optparse, + lifecycle, lubridate, R6, readr, rjson, stringr, - tidyverse, + tidyverse LazyData: true License: AGPL-3.0-or-later Roxygen: list(markdown = TRUE) @@ -33,4 +34,4 @@ Suggests: testthat, testtools, Type: Package -Version: 1.1.0 +Version: 1.2.0 diff --git a/Makefile b/Makefile index e3585ca..4e8433c 100755 --- a/Makefile +++ b/Makefile @@ -65,6 +65,6 @@ green: format refactor: format Rscript -e "devtools::test(stop_on_failure = TRUE)" \ - && (git add R/*.R tests/testthat/*.R && git commit -m "♻️ Refactor") \ + && (git add R/*.R tests/testthat/*.R && git commit -m "♻️ Refactor: ${message}") \ || git restore R/*.R tests/testthat/*.R chmod g+w -R . diff --git a/R/BL_data_format.R b/R/birdlife_data_format.R similarity index 93% rename from R/BL_data_format.R rename to R/birdlife_data_format.R index 5d1d477..5e83779 100644 --- a/R/BL_data_format.R +++ b/R/birdlife_data_format.R @@ -4,6 +4,10 @@ construct_bl_table <- function(breeding_status, tracking_data, config_content) { data_table <- join_seabird_breeding_status_with_tracking_data(breeding_status, tracking_data) |> mutate(track_id = bird_id, age = "adult", equinox = NA, argos_quality = NA) + data_table_with_trips <- data_table |> + classify_breed_stage() |> + bycatch::get_trips(config_content) + ordered_columns <- c( "bird_id", "sex", @@ -17,14 +21,15 @@ construct_bl_table <- function(breeding_status, tracking_data, config_content) { "equinox", "argos_quality" ) - data_table_with_trips <- data_table |> - classify_breed_stage() |> - bycatch::get_trips(config_content) - data_table_with_trips@data |> rename(time_gmt = time, latitude = Latitude, longitude = Longitude, track_id = tripID) |> + round_coordinates(6) |> select(all_of(ordered_columns)) } +round_coordinates <- function(data, digits = 6) { + data |> + mutate(latitude = round(latitude, digits), longitude = round(longitude, digits)) +} join_seabird_breeding_status_with_tracking_data <- function(breeding_status, tracking_data) { tracking_data_with_season <- tracking_data |> diff --git a/R/cli.R b/R/cli.R index fa9cadf..f37d09b 100644 --- a/R/cli.R +++ b/R/cli.R @@ -1,5 +1,30 @@ +#' Write a CSV with the tracking data as Seabird tracking Database requires. +#' +#' Reads breeding status data, tracking data, and configuration data, constructs a BirdLife (BL) table, +#' and writes the resulting table to a CSV file. All input and output paths are provided via the `options` list. +#' +#' @param options A named list of file paths. Must contain: +#' \itemize{ +#' \item \code{breeding-status-path}: Path to the breeding status CSV file. +#' \item \code{tracking-data-path}: Path to the tracking data CSV file. +#' \item \code{config-path}: Path to the configuration JSON file. +#' \item \code{output-path}: Path where the output CSV will be written. +#' } +#' +#' @return Invisibly returns \code{NULL}. Called for its side effect of writing a CSV file. #' @export -write_bl_table <- function(options) { +#' +#' @examples +#' \dontrun{ +#' options <- list( +#' "breeding-status-path" = "breeding_status.csv", +#' "tracking-data-path" = "gps-albatros-guadalupe.csv", +#' "config-path" = "config_file.json", +#' "output-path" = "result.csv" +#' ) +#' write_birdlife_table(options) +#' } +write_birdlife_table <- function(options) { breeding_status <- read_csv(options[["breeding-status-path"]], show_col_types = FALSE) tracking_data <- read_csv(options[["tracking-data-path"]], show_col_types = FALSE) config_content <- read_config(options[["config-path"]]) @@ -8,6 +33,33 @@ write_bl_table <- function(options) { } #' @export +write_bl_table <- function(options) { + lifecycle::deprecate_warn( + when = "1.2.0", + what = "write_bl_table()", + with = "write_birdlife_table()" + ) + write_birdlife_table(options) +} + +#' Get command-line options for domain-specific input files and output +#' +#' Constructs a set of command-line options for specifying file paths relevant to the seabird tracking domain, +#' including breeding status data, tracking data, configuration, and output location. +#' +#' @return A named list of options with file paths for: +#' \itemize{ +#' \item \code{breeding-status-path}: Breeding status CSV file +#' \item \code{tracking-data-path}: Tracking data CSV file +#' \item \code{config-path}: Configuration JSON file +#' \item \code{output-path}: Output CSV file +#' } +#' The returned options are typically used to configure file locations for downstream data processing functions. +#' @export +#' +#' @examples +#' opts <- get_domain_specific_options() +#' opts[["breeding-status-path"]] get_domain_specific_options <- function() { breeding_status_path <- geci.optparse::character_option(c("-b", "--breeding-status-path"), default = "/workdir/breeding_status.csv", help = "File path of the breeding_status_database") tracking_path <- geci.optparse::character_option(c("-t", "--tracking-data-path"), default = "/workdir/gps-albatros-guadalupe.csv", help = "File path of the tracking database") diff --git a/R/seabird.tracking-package.R b/R/seabird.tracking-package.R new file mode 100644 index 0000000..425b3c1 --- /dev/null +++ b/R/seabird.tracking-package.R @@ -0,0 +1,7 @@ +#' @keywords internal +"_PACKAGE" + +## usethis namespace: start +#' @importFrom lifecycle deprecated +## usethis namespace: end +NULL diff --git a/README.md b/README.md index 9606653..9f300a9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -# Template for R projects - -## Step to use +# Seabird Tracking Data Processing +**seabird_tracking** is a set of utilities to process raw seabird tracking data and construct standardized datasets for the Seabird Tracking Database. diff --git a/tests/data/gps-albatros-guadalupe.csv b/tests/data/gps-albatros-guadalupe.csv index 4b631e2..fbf752a 100644 --- a/tests/data/gps-albatros-guadalupe.csv +++ b/tests/data/gps-albatros-guadalupe.csv @@ -16,8 +16,8 @@ date,latitude,longitude,name,time 2014-02-16,28.884113,-118.292143,LAAL05,13:00:00 2014-02-17,28.884217,-118.291543,LAAL05,14:00:00 2017-02-15,29.390127,-118.315544,1,11:00:00 -2017-02-17,32.203983,-118.396667,1,12:00:00 -2017-02-17,32.380726,-118.869003,1,13:00:00 +2017-02-17,32.203983000001,-118.396667,1,12:00:00 +2017-02-17,32.380726000001,-118.869003,1,13:00:00 2017-02-21,28.884108,-118.291504,2,14:00:00 2017-02-21,28.884073,-118.291519,2,15:00:00 2017-02-22,28.884121,-118.291504,2,16:00:00 @@ -28,11 +28,11 @@ date,latitude,longitude,name,time 2018-01-29,42.574684,-139.830383,4E8,12:00:00 2018-01-29,42.460968,-139.748444,4E8,13:00:00 2018-01-29,42.431324,-139.639725,4E8,14:00:00 -2016-01-29,42.168236,-140.09169,4E8,10:00:00 +2016-01-29,42.168236,-140.091690000001,4E8,10:00:00 2016-01-29,42.574684,-139.830383,4E8,11:00:00 -2016-01-29,42.460968,-139.748444,4E8,12:00:00 +2016-01-29,42.460968,-139.74844400000001,4E8,12:00:00 2016-01-29,42.431324,-139.639725,4E8,13:00:00 2017-12-31,42.168236,-140.09169,4E8,22:00:00 2017-12-31,42.574684,-139.830383,4E8,23:00:00 2018-01-01,42.460968,-139.748444,4E8,00:01:00 -2018-01-01,42.431324,-139.639725,4E8,01:00:00 +2018-01-01,42.431324,-139.63972500000001,4E8,01:00:00 diff --git a/tests/testthat/test-BL_data_format.R b/tests/testthat/test-birdlife_data_format.R similarity index 94% rename from tests/testthat/test-BL_data_format.R rename to tests/testthat/test-birdlife_data_format.R index 41377fc..7cc2c2f 100644 --- a/tests/testthat/test-BL_data_format.R +++ b/tests/testthat/test-birdlife_data_format.R @@ -28,6 +28,13 @@ describe("Construct BL table", { obtained_columns <- colnames(obtained_bl_table) expect_true(all(expected_columns %in% obtained_columns)) }) + are_all_rounded <- function(x, digits = 6) { + all(round(x, digits) == x, na.rm = TRUE) + } + it("Round coordinates", { + expect_true(are_all_rounded(obtained_bl_table$latitude, 6)) + expect_true(are_all_rounded(obtained_bl_table$longitude, 6)) + }) it("Classify breed stage from joined data", { expected_breed_stage <- "chick-rearing" obtained_breed_stage <- obtained_bl_table[[1, "breed_stage"]] diff --git a/tests/testthat/test-cli.R b/tests/testthat/test-cli.R index 8ef7cc8..5672367 100644 --- a/tests/testthat/test-cli.R +++ b/tests/testthat/test-cli.R @@ -1,6 +1,6 @@ describe("write_bl_table", { it("construct_bl_table ", { - output_path <- "/workdir/tests/data/bl_albatross_guadalupe.csv" + output_path <- "/workdir/tests/data/birdlife_albatross_guadalupe.csv" config_path <- "/workdir/tests/data/trips_config.json" testtools::if_exist_remove(output_path) options_list <- list( @@ -9,7 +9,7 @@ describe("write_bl_table", { "tracking-data-path" = "/workdir/tests/data/gps-albatros-guadalupe.csv", "output-path" = output_path ) - write_bl_table(options_list) + write_birdlife_table(options_list) expect_true(testtools::exist_output_file(output_path)) }) }) diff --git a/tests/testthat/test_version.R b/tests/testthat/test_version.R index eca9625..e7ecc62 100644 --- a/tests/testthat/test_version.R +++ b/tests/testthat/test_version.R @@ -1,6 +1,6 @@ describe("Get version of the module", { - it("The version is 1.1.0", { - expected_version <- c("1.1.0") + it("The version is 1.2.0", { + expected_version <- c("1.2.0") obtained_version <- packageVersion("seabird.tracking") version_are_equal <- expected_version == obtained_version expect_true(version_are_equal)