Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
24 changes: 24 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -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"
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,4 +34,4 @@ Suggests:
testthat,
testtools,
Type: Package
Version: 1.1.0
Version: 1.2.0
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
13 changes: 9 additions & 4 deletions R/BL_data_format.R β†’ R/birdlife_data_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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 |>
Expand Down
54 changes: 53 additions & 1 deletion R/cli.R
Original file line number Diff line number Diff line change
@@ -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"]])
Expand All @@ -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")
Expand Down
7 changes: 7 additions & 0 deletions R/seabird.tracking-package.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#' @keywords internal
"_PACKAGE"

## usethis namespace: start
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<a href="https://www.islas.org.mx"><img src="https://www.islas.org.mx/img/logo.svg" align="right" width="256" /></a>

# 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.
10 changes: 5 additions & 5 deletions tests/data/gps-albatros-guadalupe.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-cli.R
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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))
})
})
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test_version.R
Original file line number Diff line number Diff line change
@@ -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)
Expand Down