Skip to content

Commit

Permalink
Merge pull request #192 from birdflow-science/191-lookup_season_times…
Browse files Browse the repository at this point in the history
…teps-throws-uninformitive-error-when-the-season-start-and-end-date-are-the-same

Fix date lookup for seasons that start and end on the same date.
  • Loading branch information
ethanplunkett authored Jun 14, 2024
2 parents 6a239ab + f31b001 commit 5f1d670
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 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.9063
Version: 0.1.0.9064
Authors@R:
c(person("Ethan", "Plunkett", email = "plunkett@umass.edu", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4405-2251")),
Expand Down
31 changes: 23 additions & 8 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# BirdFlowR 0.1.0.9064
2024-06-14

Fix #191 Date lookup now works for seasons that start and end on the same day.

# BirdFlowR 0.1.0.9063
2024-06-12

Fix #168 -- allow `NA` in species date fields as in Magnificent Frigate bird
Fix #168 -- allow `NA` in species date fields as in Magnificent Frigate bird.

* Replace `NA` with `$species` with empty string before writing to HDF5 with
`export_birdflow()`
* Replace empty string with `NA` when reading `$species` items in
Expand Down Expand Up @@ -89,7 +94,9 @@ parameters.

# BirdFlowR 0.1.0.9055
2024-03-29

## Flux II

* Flux values are now divided by the radius to standardize units at
at P/km/week/ where P is the proportion of the population.
* Add tests for `calc_flux()` and `is_between()`
Expand Down Expand Up @@ -1377,15 +1384,17 @@ it is `TRUE`.
* Expanded "Learn More"" section in README.md to link to all vignettes as well
as the BirdFlow paper.

# BirdFlowR 0.0.0.9021 2023-03-03
# BirdFlowR 0.0.0.9021
2023-03-03

* Updated preprocess_species()
- Now only downloads the files it needs [#21](https://github.com/birdflow-science/BirdFlowR/issues/21)
- Slight adjustment to resolution heuristic, it should take fewer steps to
find the right resolution.
- Added additional tests to cover error conditions and clipping

# BirdFlowR 0.0.0.9019 2023-03-01
# BirdFlowR 0.0.0.9019
2023-03-01

* Nomenclature cleanup (round 1)
- collapse_distr(x, bf) -> collapse_raster(raster, bf)
Expand All @@ -1412,24 +1421,28 @@ it is `TRUE`.
still accessible with ?function_name.


# BirdFlowR 0.0.0.9016 2023-02-27
# BirdFlowR 0.0.0.9016
2023-02-27

* Added package down. Starting to use [semantic versioning](https://semver.org/).

# BirdFlowR 0.0.0.9017 2023-02-27
# BirdFlowR 0.0.0.9017
2023-02-27

* Fix bug introduced by **ebirdst** 2.2021.0 (switch from **raster** to
**terra**) [#17](https://github.com/birdflow-science/BirdFlowR/issues/17).

# BirdFlowR 0.0.0.9003 2023-02-27
# BirdFlowR 0.0.0.9003
2023-02-27

* Updated installation instructions. Closing
[#11](https://github.com/birdflow-science/BirdFlowR/issues/11).

* Added docker file.
[Usage instructions.](https://github.com/birdflow-science/BirdFlowR/pull/15#issuecomment-1445152787)

# BirdFlowR 0.0.0.9002 2023-02-23
# BirdFlowR 0.0.0.9002
2023-02-23

* Added "biocViews:" before "Imports:" in DESCRIPTION so that devtools can find
and install rhdf5 (from Bioconductor) while installing the packages BirdFlowR
Expand All @@ -1446,7 +1459,9 @@ needs. [#13](https://github.com/birdflow-science/BirdFlowR/issues/13)
polar projections or global extents in most projections. Fixes
[#14](https://github.com/birdflow-science/BirdFlowR/issues/14)

# BirdFlowR 0.0.0.9001 2023-02-21
# BirdFlowR 0.0.0.9001
2023-02-21

* Switched order of package installation in readme and added installation of
rnaturalearthdata to vignette
[#11](https://github.com/birdflow-science/BirdFlowR/issues/11)
Expand Down
2 changes: 1 addition & 1 deletion R/lookup_timestep_sequence.R
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ lookup_season_timesteps <- function(x, season, season_buffer = 1) {
if (circular) {

# Buffered season should at most add up to n_timesteps
n <- ifelse(end > start, end - start + 1, n_timesteps(x) - start + 1 + end)
n <- ifelse(end >= start, end - start + 1, n_timesteps(x) - start + 1 + end)
if ((n + 2 * season_buffer) > n_timesteps(x))
stop("season_buffer is too large.")

Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-lookup_timestep_sequence.R
Original file line number Diff line number Diff line change
Expand Up @@ -575,3 +575,18 @@ test_that("lookup_timestep() throws meaningful error for NA's in bf$species", {
regexp = "season has NA .* season lookup is impossible")

})

test_that("lookup_season_timesteps() works with single timestep season", {
# See https://github.com/birdflow-science/BirdFlowR/issues/191
# The Northerth Saw-whet Owl "nswowl

bf <- BirdFlowModels::amewoo

# Hack species info to artificially recreate problem with standard test model
# same date for start and end of prebreeding migration
bf$species$prebreeding_migration_end <- bf$species$prebreeding_migration_start

expect_no_error(a <- lookup_season_timesteps(bf, season = "prebreeding"))
expect_equal(length(a), 3) # given default season buffer of 1

})

0 comments on commit 5f1d670

Please sign in to comment.