Skip to content

Commit

Permalink
Merge pull request #150 from birdflow-science/147-additional-testing
Browse files Browse the repository at this point in the history
147 spelling, additional testing, and drop ability to import pre-dynamic-mask models
  • Loading branch information
ethanplunkett committed Dec 13, 2023
2 parents 13a2697 + 1f2ef20 commit 2a67c90
Show file tree
Hide file tree
Showing 46 changed files with 534 additions and 419 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: BirdFlowR
Title: Predict and Visualize Bird Movement
Version: 0.1.0.9040
Version: 0.1.0.9041
Authors@R:
c(person("Ethan", "Plunkett", email = "plunkett@umass.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4405-2251")),
Expand Down
65 changes: 48 additions & 17 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@

# BirdFlowR 0.1.0.9041
2023-12-12

* Dropped the ability to import pre-dynamic-mask models. This was announced
in 0.1.0.9040 but not done.
* Fix spelling and minor documentation edits
* Fix bug in `n_parameters()` for fitted models.
* `birdflow_options()` now accepts a list with option names and their
new values, as well as all the previously accepted argument forms.
* Improve `validate_BirdFlowR()` error reporting.
* Add tests for:
* Date lookup on preprocessed but not fitted models. Closes #147.
* `n_paramaters()`
* `load_model()`
* `load_collection_index()`
* `route_migration()`
* `marginal_stats()`, `calc_pct_zero()`, and `sum_marginals()`
* `find_threshold()`
* `print()` for `BirdFlow` and `BirdFlowRoutes` objects.
* `cache_path()`
* `compare_geom()`
* `birdflow_options()`
* `build_transitions()`, `drop_transitions()`

* Expand testing for:
* `preprocess_species()`
* `validate_BirdFlow()`

# BirdFlowR 0.1.0.9040
2023-12-05
2023-12-11

## Support for **ebirdst** 3.2002.0 added.
## Support for **ebirdst** 3.2022.0 added.
**BirdFlowR** can now fit models based on eBird 2022 data or 2021 data and
will preprocess using whichever version of **ebirdst** is loaded.
Both types of fitted models can be used with BirdFlowR.
Expand All @@ -12,14 +41,15 @@ don't exist in the old version.
## Breaking
* `get_dates()`
* Models fit using **ebirdst** 2.2021 have `$dates` columns:
"interval", "date", "midpoint", "start", "end", "doy", and "week".
`"interval"`, `"date"`, `"midpoint"`, `"start"`, `"end"`, `"doy"`, and
`"week"`.
* Models fit with **ebirdst** 3.2022 have `$dates` columns:
"timestep", "date", "label", "julian", "week".
`"timestep"`, `"date"`, `"label"`, `"julian"`, and `"week"`.
* Regardless of the `$dates` format in the model object `get_dates()`
returns the newer columns: "timestep", "date", "label", "julian", "week".
Previously it returned the older columns.
* Replacing `bf$dates` with `get_dates()` and adapting to the new column
names is recommended.
returns the newer columns: `"timestep"`, `"date"`, `"label"`, `"julian"`,
and `"week"`. Previously it returned the older columns.
* Users should replace `bf$dates` with `get_dates()` and use new column
names.

* Inconsistent weeks. **eBird** changed the way dates are assigned to weeks
in the 2022 version. See notes in `get_dates()` for details.
Expand Down Expand Up @@ -48,7 +78,7 @@ don't exist in the old version.

## Updates

* A number of interal changes were made to "`preprocess_species()`
* A number of internal changes were made to `preprocess_species()`
to work with **ebirdst** v. 3.2022
* `species` can be set to either `"example_date"` or `"yeseb-example"` to
triggering using **ebirdst** example data. **BirdFlowR** will silently
Expand All @@ -63,15 +93,15 @@ don't exist in the old version.
`species_info()` (and `$species`) is unchanged.
* A new `dates` format is now used with 2022 models.

* Date lookup code was overhauled througout the package.
* Date lookup code was overhauled throughout the package.
* Most use of `$dates` was dropped in favor of `get_dates()` to handle the
two date formats in use.

* `preprocess_species()` snapshot tests were updated to use eBird 2022 derived
snapshots and are skipped if older versions of **eBirdst** are loaded, but
snapshots and are skipped if older versions of **ebirdst** are loaded, but
most `preprocess_species()` tests are still run.

* Several internal functions documented in `ebirdst-compatability` help
* Several internal functions documented in `ebirdst-compatibility` help
insulate **BirdFlowR** from the changes in the **ebirdst** API and facilitate
working with both versions.

Expand All @@ -83,11 +113,12 @@ Updated tests to work with new example data and ebirdst 3.2022.0
* Updated tests for new `amewoo` model in **BirdFlowModels**
(R package) v. 0.0.2.9002
* Added formal dependency on BirdFlowModels >= 0.0.2.9002.
* Updates to pass CRAN checks but not preproces with ebirdst 3.2022.0
* Added ebird/ebirdst to remotes (to force installing dev version)
Revert this after changes in ebirdst 47bbdfc87 are on CRAN
* Updates to pass CRAN checks but not preprocess with **ebirdst** 3.2022.0
* Added `ebird/ebirdst` to remotes (to force installing development
version). Revert this after changes in **ebirdst**
47bbdfc87 are on CRAN
* Add skip_if_unsupported_ebirdst_version() to preprocess species tests
as it currently does for ebirdst 3.2022.0.
as it currently does for **ebirdst** 3.2022.0.
* Add copy of `ebirdst_weeks` to BirdFlowR as internal data.

# BirdFlowR 0.1.0.9038
Expand All @@ -109,7 +140,7 @@ Trying to pass all CI checks while still using ebirdst 2.2021

* Spelling
* Checked spelling on package documentation and vignettes.
* Added wordlist (extending dictionary of valid words).
* Added `inst\WORDLIST` (extending dictionary of valid words).
* To check package spelling use `devtools::spell_check()`
* Added section on spelling to `./.github/CONTRIBUTING.html`

Expand Down
25 changes: 15 additions & 10 deletions R/birdflow_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@
#'}
#'
#'
#' @param ... One of: (1) one or more named arguments where the name is a
#' an option and the value its new setting e.g. `verbose = FALSE` ; (2) a
#' single unnamed argument stating an option to retrieve e.g. `"verbose"`
#' with an option to retrieve; or (3) No arguments, indicating that all
#' options and their current settings should be returned in a list.
#' @param ... One of:
#' (1) one or more named arguments where the name is a
#' an option and the value its new setting e.g. `verbose = FALSE` ;
#' (2) a single unnamed argument stating an option to retrieve e.g.
#' `"verbose"` with an option to retrieve.
#' (3) No arguments, indicating that all options and their current settings
#' should be returned in a list; or
#' (4) a single list argument with named items and their new values.
#'
#' @return If no arguments are used than all options will be returned as a list.
#' If there is a single, unnamed argument with a character value indicating an
Expand All @@ -89,7 +92,7 @@ birdflow_options <- function(...) {
}

# Process single unnamed arguments by returning the relevant option(s)
if (length(args) == 1 && is.null(names(args))) {
if (length(args) == 1 && is.null(names(args)) && !is.list(args[[1]])) {
if (length(args[[1]]) > 1) {
stop("You can only retrieve one option by name. Use birdflow_options() ",
"(no arguments) to retrieve all options.")
Expand All @@ -103,10 +106,14 @@ birdflow_options <- function(...) {
}
}

# Special case where first argument is a list of arguments to set
if (length(args) == 1 && is.list(args[[1]])) {
args <- args[[1]]
}

if (any(is.null(names(args))))
stop("You can not set and retrieve options in the same call;",
" an unamed argument must be the only argument.")
stop('Use "all" or a single argument name to retreive arguments.",
"If setting multiple arguments all arguments must be named.')

if (!all(names(args) %in% names(.birdflow_config))) {
missing <- setdiff(names(args), names(.birdflow_config))
Expand Down Expand Up @@ -159,8 +166,6 @@ birdflow_options <- function(...) {
length(lc) == 1 && !is.na(lc))) {
stop("Invalid cache")
}
lc <- gsub("(/|\\\\)*$", base::.Platform$file.sep, lc) # force end slash

.birdflow_config$cache <- lc
}
}
4 changes: 1 addition & 3 deletions R/determine_resolution.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# nolint start: cyclocomp_linter.
#' Determine BirdFlow model resolution ####
#'
#' Internal function to determine the resolution to use when creating a
Expand Down Expand Up @@ -40,7 +39,7 @@
#' @param sp_path The species path used with \pkg{ebirdst} to download and load
#' data
#' @param download_species The species code used with \pkg{ebirdst} this might
#' be "example_data" or "yebsap-example" but otherwise will be a real
#' be `"example_data"` or `"yebsap-example"` but otherwise will be a real
#' species code.
#' @param project_method This is the method used to reproject it is a local
#' variable set within `preprocess_species`.
Expand Down Expand Up @@ -216,4 +215,3 @@ determine_resolution <- function(sp_path,
return(res)

}
# nolint end
25 changes: 12 additions & 13 deletions R/ebirdst_compatibility.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#' @title ebirdst version compatability functions:
#' @title ebirdst version compatibility functions:
#'
#' @description
#' Internal functions to facilitate working with both the 2021 and 2022
#' versions of pkg{ebirdst} despite the significant changes to the API.
#'
#' @name ebirdst-compatability
#' @name ebirdst-compatibility
NULL

#' @section ebirdst_pkg_ver:
#' @section `ebirdst_pkg_ver()`:
#' `ebirdst_pkg_ver()` Look up the version of the currently installed
#' \pkg{ebirdst}.
#' @return `ebirdst_pkg_ver()`: The installed \pkg{ebirdst} package version or
#' `NA` if none.
#' @keywords internal
#' @rdname ebirdst-compatability
#' @rdname ebirdst-compatibility
ebirdst_pkg_ver <- function() {
res <- tryCatch(utils::packageVersion("ebirdst"), error = identity)
if (inherits(res, "error"))
Expand All @@ -22,7 +22,7 @@ ebirdst_pkg_ver <- function() {
}


#' @section res_label():
#' @section `res_label()`:
#' Convert resolution labels so they are appropriate for the
#' installed \pkg{ebirdst}
#'
Expand All @@ -38,7 +38,7 @@ ebirdst_pkg_ver <- function() {
#'
#' @return `res_label()`: resolution labels appropriate for installed version
#' of \pkg{ebirdst}.
#' @rdname ebirdst-compatability
#' @rdname ebirdst-compatibility
#' @keywords internal
res_label <- function(res) {
crosswalk <- data.frame("v2021" = c("lr", "mr", "hr"),
Expand All @@ -60,7 +60,7 @@ res_label <- function(res) {
res
}

#' @section date_to_week():
#' @section `date_to_week()`:
#'
#' This is a slightly modified copy of `ebirdst::date_to_st_week()` that
#' allows calculating weeks from dates without depending on \pkg{ebirdst}.
Expand All @@ -71,7 +71,7 @@ res_label <- function(res) {
#' the closest of those two. The output of
#' `ebirdst::ebirdst_version()$version_year` or
#' `get_metadata(bf, "ebird_version_year")` is appropriate.
#' @rdname ebirdst-compatability
#' @rdname ebirdst-compatibility
#' @return `date_to_week()`: A vector of week numbers associated with `dates`
#' @keywords internal
date_to_week <- function(dates, version = 2022) {
Expand All @@ -92,17 +92,16 @@ date_to_week <- function(dates, version = 2022) {
return(findInterval(jd, breaks))
}

#' @section ebirdst_example_species():
#' @section `ebirdst_example_species()`:
#' Lookup the example species name that is appropriate for the
#' installed \pkg{ebirdst}. The example species changed
#' from "example_data" to "yebsap-example" in version 3.2022.0.
#' from `"example_data"` to `"yebsap-example"` in version 3.2022.0.
#' @return `ebirdst_example_species()`: The example species name for
#' \pkg{ebirdst}
#' @keywords internal
#' @rdname ebirdst-compatability
ebirdst_example_species <- function(){
#' @rdname ebirdst-compatibility
ebirdst_example_species <- function() {
ifelse(ebirdst_pkg_ver() < "3.2022.0",
"example_data",
"yebsap-example")
}

10 changes: 5 additions & 5 deletions R/get_dates.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
#' of whether it is a leap year. The label on leap years will thus be one
#' day off the date of the week center for most of the year.
#'
#' ### Retreiving dates
#' ### Retrieving dates
#' The date columns stored within a birdflow model changes depending on the
#' ebirdst version year, so do NOT use `bf$dates` in your code. Instead use
#' `get_dates()` which will always return the same (newer) column names.
#' \pkg{ebirdst} version year, so do NOT use `bf$dates` in your code. Instead
#' use`get_dates()` which will always return the same (newer) column names.
#'
#' @note
#' * [truncate_birdflow()] creates models with a subset of the intervals
Expand All @@ -59,8 +59,8 @@
#' offset}
#' \item{julian}{The Julian date (day of year) associated with the timestep
#' center}
#' \item{week}{The eBirdst week number associated with the date. For full year
#' models this is identical to `timestep` but after
#' \item{week}{The \pkg{ebirdst} week number associated with the date. For full
#' year models this is identical to `timestep` but after
#' [truncation](truncate_birdflow) they will differ.}
#'
#' Prior to \pkg{BirdFlowR} v. 0.1.0.9040 it returned columns:
Expand Down
2 changes: 2 additions & 0 deletions R/ignore_unused_imports.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ ignore_unused_imports <- function() {
# TLDS Although in theory BirdFlowR only directly depends on
# rnaturalearth it imports rnaturalearthdata to streamline
# installation and avoid relying on rnaturalearth::install_rnaturalearthdata.

NULL
}
20 changes: 13 additions & 7 deletions R/import_birdflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,17 @@ import_birdflow <- function(hdf5, ..., version) {
}

version <- as.character(version)
return(switch(as.character(version),
"1" = stop("Importing Version 1 BirdFlow models is no longer",
"supported."),
"2" = import_birdflow_v2(hdf5 = hdf5, ...),
"3" = import_birdflow_v3(hdf5 = hdf5, ...),
stop("Unrecognized version. ",
"Was this model fit with a newer version of BirdFlowR?")))



if (version == 1)
stop("Importing this version ", version,
" BirdFlow model is no longer supported")

if (version == 2)
stop("Importing this version ", version,
" BirdFlow model is no longer supported. ",
"Use BirdFlowR version 0.1.0.9039 to import it.")

return(import_birdflow_v3(hdf5 = hdf5, ...))
}
Loading

0 comments on commit 2a67c90

Please sign in to comment.