Skip to content

Commit

Permalink
Updated tests to work with new example data and ebirdst 3.2022.0 (#145)
Browse files Browse the repository at this point in the history
Update tests for  BirdFlowModels v 0.0.2.9002 and package new ebirdst

Updated tests to work with new amewoo model in BirdFlowModels
Changes to pass tests with ebirdst 3.2022.0
    * Added ebird/ebirdst to remotes (to install dev version) 
      Revert this after changes in ebirdst  47bbdfc87 are on CRAN
    * Add skip_if_unsupported_ebirdst_version() to preprocess species tests
    * Add copy of ebirdst_weeks to BirdFlowR as internal data
  • Loading branch information
ethanplunkett committed Dec 5, 2023
1 parent 715cf88 commit 43beefa
Show file tree
Hide file tree
Showing 24 changed files with 216 additions and 116 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@
^man/figures/BirdFlowR_transparent.png
^man/figures/BirdFlowR_logo.R
^\.lintr
^data-raw$
12 changes: 7 additions & 5 deletions 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.9038
Version: 0.1.0.9039
Authors@R:
c(person("Ethan", "Plunkett", email = "plunkett@umass.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4405-2251")),
Expand All @@ -11,9 +11,8 @@ Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Suggests:
auk,
BirdFlowModels (>= 0.0.2),
ebirdst (<= 2.2021.3),
BirdFlowModels (>= 0.0.2.9002),
ebirdst,
knitr,
ragg,
rmarkdown,
Expand Down Expand Up @@ -47,7 +46,10 @@ Imports:
viridisLite
VignetteBuilder: knitr
Remotes:
birdflow-science/BirdFlowModels
birdflow-science/BirdFlowModels,
ebird/ebirdst
URL: https://birdflow-science.github.io/BirdFlowR/, https://github.com/birdflow-science/BirdFlowR
BugReports: https://github.com/birdflow-science/BirdFlowR/issues
Language: en-US
Depends:
R (>= 3.5)
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# BirdFlowR 0.1.0.9039
2023-11-21*

* Updated tests for new `amewoo` model in **BirdFlowModels** (R package)* 0.0.2.9002
* Now depends on

# BirdFlowR 0.1.0.9038
2023-11-16

Expand Down
34 changes: 27 additions & 7 deletions R/get_dates.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
#' Retrieve dates component of a BirdFlow model
#'
#' `get_dates()` retrieves the dates component of a BirdFlow model. Most of
#' the resulting data is derived from [ebirdst::ebirdst_weeks] and added
#' to the model object by [preprocess_species()]. [truncate_birdflow()]
#' creates models with a subset of the intervals and renames them
#' `1:[n_timesteps()]` of the truncated model so if it has been used the
#' data may differ from [ebirdst::ebirdst_weeks()].
#' `get_dates()` retrieves the dates component of a BirdFlow model.
#'
#' \pkg{BirdFlowR} uses the same conventions for assigning dates to
#' eBird "weeks" as \pkg{ebirdst}. This changed with the 2022 release.
#'
#' \pkg{ebirdst} version <= 2.2021.3
#'
#' * Date table is derived from `ebirdst::ebirdst_weeks` and added
#' to the model object by [preprocess_species()].
#' * Julian date is converted to a proportion with `(jd - 0.5)/366`.
#' * 52 even ranges are assigned to 0 to 1 and the proportional date is then
#' compared to these thresholds.
#' * In a non-leap year two weeks have 8 days and the last week has 6.
#' * In a leap-year two weeks have 8 days.
#' * All other weeks have 7 days.
#'
#' \pkg{ebirdst} version >= 3.2022.0
#' * \pkg{ebirdst} dropped `ebirdst_weeks` and `ebirdst::date_to_st_week()`
#' * Dates are assigned to weeks by finding which evenly spaced Julian date of
#' a week center Julian date of the input is closest to.
#' * All weeks but the last have 7 days.
#' * On non-leap-years the last week has 8 days, on leap years it has 9.
#'
#' [truncate_birdflow()] creates models with a subset of the intervals
#' and renames them `1:[n_timesteps()]` of the truncated model so if it
#' has been used the data may differ from `ebirdst::ebirdst_weeks`.
#'
#' @param bf A BirdFlow object to retrieve dates from.
#'
Expand All @@ -16,7 +36,7 @@
#' equivalent to the week of the year but with truncated models may
#' not be.}
#' \item{date}{The date associated with the interval's midpoint.}
#' \item{midpoint, star, end}{The midpoint, start, and end of each interval
#' \item{midpoint, start, end}{The midpoint, start, and end of each interval
#' as a proportion of the total year that has elapsed.}
#' \item{doy}{The day of year associated with the midpoint of each interval.}
#' @export
Expand Down
8 changes: 1 addition & 7 deletions R/import_birdflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,7 @@
#'
#' @param hdf5 Path to an HDF5 file containing a fitted BirdFlow model.
#' @param ... Arguments to be passed to a version specific internal function.
#' Likely will only be used with
#' version 1 which takes two additional arguments: \describe{
#' \item{tiff}{Path to the model GeoTIFF.}
#' \item{species}{An eBird species code. It should appear in the
#' `species_code` column of the data.frame returned by
#' [auk::get_ebird_taxonomy()]}
#' }
#' Currently deprecated was used in early BirdFlow models.
#' @param version (optional) force reading of BirdFlow models as a particular
#' version. Normally, this will be determined from metadata in the HDF5
#' file.
Expand Down
4 changes: 3 additions & 1 deletion R/preprocess_species.R
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ preprocess_species <- function(species = NULL,

# Reformat and export dates

dates <- as.data.frame(ebirdst::ebirdst_weeks)
dates <- as.data.frame(ebirdst_weeks)
# Note ebirdst_weeks now stored in BirdFlowR is a copy of the ebirdst
# version that was dropped with the 2022 data release (nov 2023)
names(dates)[names(dates) == "week_number"] <- "interval"
dates$doy <- lubridate::yday(dates$date) + 0.5
dates$date <- as.character(dates$date)
Expand Down
Binary file added R/sysdata.rda
Binary file not shown.
42 changes: 42 additions & 0 deletions data-raw/ebirdst_weeks.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# This adds ebirdst_weeks as an internal dataset to the BirdFlowR package
# so that it no longer needs to pull it from ebirdst.
#
# Note: Internal data is stored in R/sysdata.rda and must all be created in
# a single call.
#
# ebirdst_weeks is from ebirdst version 2.2021.3. It is added to BirdFlowR
# for use when preprocessing ebirdst 2021 data (with the old ebird package)
# without referencing the copy in that package as doing so - even conditioned
# on version - breaks CRAN checks when checking against newer ebirdst package
# versions that do not have it.

# ebirdst_weeks.rds added to data-raw with Using ebirdst v 2.2021.3
# with this: saveRDS(ebirdst::ebirdst_weeks, "data-raw/ebirdst_weeks.rds")
# which never need to run again.

# Add the data-raw/ebirdst_weeks.rds to R/sysdata.rda
ebirdst_weeks <- readRDS("./data-raw/ebirdst_weeks.rds")
usethis::use_data(ebirdst_weeks, internal = TRUE)

### ROxygen Comments below copied from ebirdst/R/data.R v 2.2021.3
### They will not be rendered but kept here for reference.

#' eBird Status and Trends weeks
#'
#' eBird Status and Trends predictions are made for each of 52 weeks of the
#' year. This data frame provides the boundaries of the weeks.
#'
#' @format A data frame with 52 rows and 5 columns:
#' \describe{
#' \item{week_number}{Integer week number from 1-52.}
#' \item{date}{Date of the midpoint of the week.}
#' \item{week_midpoint}{Date of the midpoint of the week expressed as a
#' fraction of the year, i.e. a number from 0-1.}
#' \item{week_start}{Date of the start of the week expressed as a fraction of
#' the year, i.e. a number from 0-1.}
#' \item{week_end}{Date of the end of the week expressed as a fraction of the
#' year, i.e. a number from 0-1.}
#' }
"ebirdst_weeks"


Binary file added data-raw/ebirdst_weeks.rds
Binary file not shown.
38 changes: 31 additions & 7 deletions man/get_dates.Rd

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

8 changes: 1 addition & 7 deletions man/import_birdflow.Rd

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

6 changes: 3 additions & 3 deletions tests/testthat/_snaps/calc_movement_vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Code
mv
Output
i start end start_x start_y end_x end_y weight
1 797 5 6 1514879 5182031 1516433 5178565 6.633053e-08
2 798 5 6 1594875 5182031 1594266 5179248 8.513777e-08
i start end start_x start_y end_x end_y weight
1 154 5 6 -1725000 375000 -822249.8 60429.72 8.105351e-05
2 155 5 6 -1575000 375000 -820426.2 62271.54 4.196808e-06

12 changes: 6 additions & 6 deletions tests/testthat/_snaps/distribution_performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
a
Output
year spring-migration
min_step_cor 0.9726 0.9811
mean_step_cor 0.9918 0.9926
min_distr_cor 0.9479 0.9742
mean_distr_cor 0.9891 0.9906
st_traverse_cor 0.9863 0.9547
md_traverse_cor 0.9865 0.9554
min_step_cor 0.9645 0.9830
mean_step_cor 0.9881 0.9935
min_distr_cor 0.9615 0.9804
mean_distr_cor 0.9865 0.9920
st_traverse_cor 0.9863 0.9846
md_traverse_cor 0.9820 0.9907

10 changes: 5 additions & 5 deletions tests/testthat/_snaps/evaluate_performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
stats
Output
$mean_step_cor
[1] 0.9918336
[1] 0.9881073
$min_step_cor
[1] 0.9726291
[1] 0.9645225
$traverse_cor
[1] 0.9863106
[1] 0.9863234
$mean_distr_cor
[1] 0.9890949
[1] 0.9865373
$min_distr_cor
[1] 0.9478764
[1] 0.9615346

76 changes: 38 additions & 38 deletions tests/testthat/_snaps/get_transition.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@
Code
histogram_counts
Output
upper_bound count
1 1e-04 2904514
2 2e-03 2678
3 3e-03 696
4 4e-03 425
5 5e-03 339
6 6e-03 252
7 7e-03 187
8 8e-03 146
9 9e-03 122
10 1e-02 79
11 2e-02 392
12 4e-02 165
13 6e-02 52
14 8e-02 18
15 1e-01 16
16 2e-01 22
17 6e-01 20
18 1e+00 313
upper_bound count
1 1e-04 10718
2 2e-03 1204
3 3e-03 65
4 4e-03 42
5 5e-03 22
6 6e-03 21
7 7e-03 13
8 8e-03 14
9 9e-03 7
10 1e-02 3
11 2e-02 45
12 4e-02 23
13 6e-02 13
14 8e-02 5
15 1e-01 2
16 2e-01 5
17 6e-01 11
18 1e+00 104

# get_transition() is consistent for backwards transitions

Code
histogram_counts
Output
upper_bound count
1 1e-04 2904499
2 2e-03 2889
3 3e-03 673
4 4e-03 436
5 5e-03 339
6 6e-03 242
7 7e-03 196
8 8e-03 129
9 9e-03 123
10 1e-02 89
11 2e-02 280
12 4e-02 95
13 6e-02 20
14 8e-02 22
15 1e-01 15
16 2e-01 46
17 6e-01 25
18 1e+00 318
upper_bound count
1 1e-04 9307
2 2e-03 1874
3 3e-03 208
4 4e-03 124
5 5e-03 94
6 6e-03 72
7 7e-03 44
8 8e-03 49
9 9e-03 32
10 1e-02 34
11 2e-02 167
12 4e-02 103
13 6e-02 44
14 8e-02 19
15 1e-01 11
16 2e-01 26
17 6e-01 12
18 1e+00 97

Loading

0 comments on commit 43beefa

Please sign in to comment.