Skip to content

Commit ebbdc2b

Browse files
Merge pull request #224 from birdflow-science/bmtr
Rename `calc_flux()` to `calc_bmtr()`.
2 parents 7fe9b72 + 1a6782e commit ebbdc2b

22 files changed

+540
-345
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: BirdFlowR
22
Title: Predict and Visualize Bird Movement
3-
Version: 0.1.0.9076
3+
Version: 0.1.0.9077
44
Authors@R:
55
c(person("Ethan", "Plunkett", email = "[email protected]", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0003-4405-2251")),

LICENSE

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,2 @@
1-
MIT License
2-
3-
Copyright (c) 2022 birdflow-science
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
14-
15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
1+
YEAR: 2025
2+
COPYRIGHT HOLDER: birdflow-science

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2022 BirdFlowR authors
3+
Copyright (c) 2025 birdflow-science
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export(Routes)
2222
export(add_dynamic_mask)
2323
export(add_stay_id)
2424
export(add_stay_id_with_varied_intervals)
25+
export(animate_bmtr)
2526
export(animate_distr)
2627
export(animate_flux)
2728
export(animate_movement_vectors)
@@ -32,6 +33,7 @@ export(as_distr)
3233
export(as_transitions)
3334
export(birdflow_options)
3435
export(build_transitions)
36+
export(calc_bmtr)
3537
export(calc_flux)
3638
export(calc_interval_metrics)
3739
export(calc_movement_vectors)
@@ -88,6 +90,7 @@ export(n_parameters)
8890
export(n_timesteps)
8991
export(n_transitions)
9092
export(pad_timestep)
93+
export(plot_bmtr)
9194
export(plot_distr)
9295
export(plot_flux)
9396
export(plot_loss)

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# BirdFlowR 0.1.0.9077
2+
2025-09-29
3+
4+
Rename `calc_flux()` to `calc_bmtr()`
5+
The old function now wraps the new with a deprecation warning.
6+
17
# BirdFlowR 0.1.0.9076
28
2025-05-25
39

R/animate_bmtr.R

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#' Animate BirdFlow Migration Traffic Rate (BMTR)
2+
#'
3+
#' Animate migration traffic rates produced by [calc_bmtr()].
4+
#'
5+
#' @inheritParams plot_bmtr
6+
#' @inheritDotParams plot_bmtr
7+
#'
8+
#' @return A [`gganim`][gganimate::gganimate-package] object
9+
#' @export
10+
#' @inherit calc_bmtr examples
11+
#' @seealso [calc_bmtr()],[plot_bmtr()]
12+
animate_bmtr <- function(bmtr, bf, title = species(bf), ...) {
13+
p <- plot_bmtr(bmtr, bf, ...)
14+
15+
anim <- p +
16+
ggplot2::facet_null() +
17+
gganimate::transition_manual(frames = .data$label) +
18+
ggplot2::labs(title = title,
19+
subtitle = "{current_frame}")
20+
21+
return(anim)
22+
}
23+
24+
25+
26+
27+
#' Animate Bird Flow Migration Traffic Rate (BMTR)
28+
#'
29+
#' DEPRECATED FUNCTION. Please use [animate_bmtr()] instead.
30+
#' @inheritDotParams animate_bmtr -bmtr
31+
#' @param flux the output from [calc_bmtr()] or, deprecated, [calc_flux()]
32+
#' @inherit animate_bmtr return
33+
#' @export
34+
animate_flux <- function(flux, ...){
35+
warning("animate_flux() is deprecated. ",
36+
"Please use animate_bmtr() instead.")
37+
animate_bmtr(flux, ...)
38+
}
39+

R/animate_flux.R

Lines changed: 0 additions & 22 deletions
This file was deleted.

R/calc_flux.R renamed to R/calc_bmtr.R

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#' Estimate bird flux
1+
#' Estimate BirdFlow Migration Traffic Rate (BMTR)
22
#'
3-
#' `calc_flux()` estimates the proportion of the species that passes near
3+
#' `calc_bmtr()` estimates the proportion of the species that passes near
44
#' a set of points during each transition in a BirdFlow model.
55
#'
66
#' @section Units:
@@ -18,14 +18,14 @@
1818
#'
1919
#' @section Limitations:
2020
#'
21-
#' `calc_flux()` makes the incorrect simplifying assumption
21+
#' `calc_bmtr()` makes the incorrect simplifying assumption
2222
#' that birds follow the shortest (great circle) path
2323
#' between the center of the the source and destination raster cells. Caution
2424
#' should be used when interpreting the results especially around
2525
#' major geographic features such as coasts, large lakes, mountain ranges, and
2626
#' ecological system boundaries that might result in non-linear migration paths.
2727
#'
28-
#' `calc_flux()` assumes that a line passes by a point if any part of the line
28+
#' `calc_bmtr()` assumes that a line passes by a point if any part of the line
2929
#' is within the radius of the point. This assumption breaks down if the
3030
#' radius is much larger than the movement lengths as points that are ahead of
3131
#' the line may still be within a radius of the line. In the extreme a large
@@ -34,9 +34,9 @@
3434
#' the default points and radius as the points ahead of the line will never be
3535
#' within the radius.
3636
#'
37-
#' The default points for `calc_flux()` are aligned with the cell centers as
37+
#' The default points for `calc_bmtr()` are aligned with the cell centers as
3838
#' are the movement lines. This alignment means that a very small radius will
39-
#' result in an overestimate of flux. The default value of half the cell size
39+
#' result in an overestimate of bmtr. The default value of half the cell size
4040
#' is sufficient for this not to be a problem, as we are capturing and
4141
#' standardizing the units based on the entire cell area that that point
4242
#' represents.
@@ -56,13 +56,13 @@
5656
#' or an even number. This is a placeholder, currently only `1` is supported.
5757
#' @param format The format to return the results in one of:
5858
#' \describe{
59-
#' \item{`"points"`}{Returns a list with `flux` a matrix or array of
60-
#' flux values, and `points` a data frame of either the input `points` or the
59+
#' \item{`"points"`}{Returns a list with `bmtr` a matrix or array of
60+
#' bmtr values, and `points` a data frame of either the input `points` or the
6161
#' default cell center derived points.}
6262
#' \item{`"dataframe"`}{Returns a "long" data frame with columns:
6363
#' * `x` and `y` coordinates of the points.
6464
#' * `transition` Transition code.
65-
#' * `flux` The flux at the point. See "Units" below .
65+
#' * `bmtr` The bmtr at the point. See "Units" below .
6666
#' * `date` The date associated with the transition, will be at the midpoint
6767
#' between timesteps.
6868
#'
@@ -71,7 +71,7 @@
7171
#' transition.}
7272
#'}
7373
#' @inheritParams is_between
74-
#' @param weighted If `FALSE` use the original and quicker version of flux
74+
#' @param weighted If `FALSE` use the original and quicker version of bmtr
7575
#' that sums all the marginal probability for transitions that pass within a
7676
#' fixed distance of the point. If `TRUE` assign a weight to the point and
7777
#' transition combo that then is multiplied by the marginal probability before
@@ -86,25 +86,25 @@
8686
#'
8787
#' \dontrun{
8888
#' bf <- BirdFlowModels::amewoo
89-
#' flux <- calc_flux(bf)
89+
#' bmtr <- calc_bmtr(bf)
9090
#'
91-
#' plot_flux(flux, bf)
91+
#' plot_bmtr(bmtr, bf)
9292
#'
93-
#' animate_flux(flux, bf)
93+
#' animate_bmtr(bmtr, bf)
9494
#' }
9595
#'
96-
calc_flux <- function(bf, points = NULL, radius = NULL, n_directions = 1,
96+
calc_bmtr <- function(bf, points = NULL, radius = NULL, n_directions = 1,
9797
format = NULL, batch_size = 5e5, check_radius = TRUE,
9898
weighted = FALSE) {
9999

100100

101101
if (!requireNamespace("SparseArray", quietly = TRUE)) {
102-
stop("The SparseArray package is required to use calc_flux(). ",
102+
stop("The SparseArray package is required to use calc_bmtr(). ",
103103
"Please install it prior to calling this function.")
104104
}
105105

106106
if (n_directions != 1)
107-
stop("Only one directional flux is supported at the moment.")
107+
stop("Only one directional bmtr is supported at the moment.")
108108

109109
if (is.null(format)) {
110110
if (is.null(points)) {
@@ -131,7 +131,7 @@ calc_flux <- function(bf, points = NULL, radius = NULL, n_directions = 1,
131131
points <- result$points
132132
radius_km <- result$radius / 1000
133133

134-
bf_msg("Calculating Flux\n")
134+
bf_msg("Calculating BMTR\n")
135135

136136
timesteps <- lookup_timestep_sequence(bf)
137137
transitions <- lookup_transitions(bf)
@@ -174,12 +174,12 @@ calc_flux <- function(bf, points = NULL, radius = NULL, n_directions = 1,
174174
}
175175
}
176176

177-
bf_msg(" Formatting flux\n")
177+
bf_msg(" Formatting BMTR\n")
178178
# Standardize to P of population to pass through KM of transect in a week
179179
net_movement <- net_movement / (radius_km * 2)
180180

181181
if (format == "points") {
182-
return(list(flux = net_movement, point = points))
182+
return(list(bmtr = net_movement, point = points))
183183
}
184184

185185
if (format == "spatraster") {
@@ -205,7 +205,7 @@ calc_flux <- function(bf, points = NULL, radius = NULL, n_directions = 1,
205205
wide <- cbind(as.data.frame(points)[, c("x", "y")],
206206
net_movement)
207207
long <- tidyr::pivot_longer(wide, cols = setdiff(names(wide), c("x", "y")),
208-
names_to = "transition", values_to = "flux")
208+
names_to = "transition", values_to = "bmtr")
209209

210210
long$date <- as.character(lookup_date(long$transition, bf))
211211

@@ -215,3 +215,20 @@ calc_flux <- function(bf, points = NULL, radius = NULL, n_directions = 1,
215215

216216
stop(format, "is not a recoginized format.") # shouldn't ever get here
217217
}
218+
219+
220+
221+
222+
#' Calculate Bird Flow Migration Traffic Rate
223+
#'
224+
#' DEPRECATED FUNCTION. Please use [calc_bmtr()] instead.
225+
#' @inheritDotParams calc_bmtr
226+
#'
227+
#' @inherit calc_bmtr return
228+
#' @export
229+
calc_flux <- function(...){
230+
warning("calc_flux() is deprecated. ",
231+
"Please use calc_bmtr() instead.")
232+
calc_bmtr(...)
233+
234+
}

R/calc_distance_weights.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Brownian bridge based weighting. This is a placeholder for now to allow
33
# implementing weight_betweeness.
44

5-
#' calculate the weights of transitions for flux points
5+
#' calculate the weights of transitions for bmtr points
66
#'
77
#' `calc_dist_weights()` is an internal function that takes summary stats
88
#' on the relationship between points and a transition line and returns
@@ -17,7 +17,7 @@
1717
#' @param dist_along_line How far along the line is the point, after
1818
#' projecting it onto the line (m)
1919
#' @param line_lengths How long is the line (m)
20-
#' @param radius_m The radius of the transect at the flux points - used to
20+
#' @param radius_m The radius of the transect at the bmtr points - used to
2121
#' determine the band of probability density that will be added to form
2222
#' the weight.
2323
#' @param res_m The resolution of the associated bird flow model, used to

R/is_between.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ is_between <- function(bf, points = NULL, radius = NULL, n_directions = 1,
8787
if (is.null(radius)) {
8888
radius <- mean(res(bf)) / 2
8989
} else if (check_radius) {
90-
# Analysis of the effect of changing radius is in test-calc_flux.R
90+
# Analysis of the effect of changing radius is in test-calc_bmtr.R
9191

9292
radius_cells <- radius / mean(res(bf)) # radius converted to cells
9393
if (radius_cells <= 0.25 || radius_cells >= 1) {
9494
stop("radius should be less than the resolution and more than 1/4 the ",
95-
"resolution or the flux is likely to be biased. ",
95+
"resolution or BMTR is likely to be biased. ",
9696
"Set check_radius to FALSE to ignore this advice.")
9797
}
9898
}

0 commit comments

Comments
 (0)