Skip to content

Commit

Permalink
Merge pull request #643 from adokter/fix_K_eta_dbz_convert
Browse files Browse the repository at this point in the history
update default K in `eta_to_dbz()` and `dbz_to_eta()`
  • Loading branch information
adokter authored Nov 1, 2023
2 parents b7e919b + 10ada4d commit a517579
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@

# bioRad 0.7.3.9000

** Bugfixes

* Updated the default refractive index value used in conversion of linear reflectivity (eta) to logarithmic reflectivity (dBZ) (#642). The effect is a 7% increase in animal densities in output of functions `integrate_to_ppi()` and `read_cajun()` only.

# bioRad 0.7.3

## New features
Expand Down
4 changes: 2 additions & 2 deletions R/dbz_eta.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#' # radar cross section of 11 cm^2 per individual
#' dbz_to_eta(7, 5) / 11 # C-band
#' dbz_to_eta(7, 10) / 11 # S-band
dbz_to_eta <- function(dbz, wavelength, K = 0.93) {
dbz_to_eta <- function(dbz, wavelength, K = sqrt(0.93)) {
assertthat::assert_that(is.numeric(dbz))
assertthat::assert_that(is.numeric(wavelength) & all(wavelength > 0), msg = "`wavelength` must be a strictly positive numeric.")
assertthat::assert_that(is.numeric(K) & all(K > 0), msg = "`K` must be a strictly positive numeric.")
Expand Down Expand Up @@ -53,7 +53,7 @@ dbz_to_eta <- function(dbz, wavelength, K = 0.93) {
#' # cross section of 11 cm^2 per individual
#' eta_to_dbz(1000 * 11, 5) # C-band
#' eta_to_dbz(1000 * 11, 10) # S-band
eta_to_dbz <- function(eta, wavelength, K = 0.93) {
eta_to_dbz <- function(eta, wavelength, K = sqrt(0.93)) {
assertthat::assert_that(is.numeric(eta) & all(eta>=0), msg = "`eta` must be a strictly positive numeric.")
assertthat::assert_that(is.numeric(wavelength) & all(wavelength > 0), msg = "`wavelength` must be a strictly positive numeric.")
assertthat::assert_that(is.numeric(K) & all(K > 0), msg = "`K` must be a strictly positive numeric.")
Expand Down
2 changes: 1 addition & 1 deletion man/dbz_to_eta.Rd

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

2 changes: 1 addition & 1 deletion man/eta_to_dbz.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-dbz_eta.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ test_that("dbz_to_eta() returns error on incorrect parameters", {
})

test_that("dbz_to_eta() returns the correct eta", {
expect_equal(dbz_to_eta(7, 5), 2122.439, tolerance = 0.0001)
expect_equal(dbz_to_eta(7, 5), 2282.193, tolerance = 0.0001)
})
})

Expand All @@ -19,7 +19,7 @@ test_that("eta_to_dbz() returns error on incorrect parameters", {
})

test_that("eta_to_dbz() returns the correct dbz", {
expect_equal(eta_to_dbz(10000, 10), 25.77285, tolerance = 0.0001)
expect_equal(eta_to_dbz(10000, 10), 25.45768, tolerance = 0.0001)
})
})

5 changes: 3 additions & 2 deletions tests/testthat/test-read_cajun.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,12 @@ test_that("read_cajun() returns expected data", {
write.csv(x = cajun_csv, non_empty_file_path)
expect_equal(
ignore_attr = TRUE,
tolerance=0.0001,
read_cajun(non_empty_file_path, wavelength = c("S"))$data,
dplyr::tribble(
~height, ~u, ~v, ~w, ~ff, ~dd, ~sd_vvp, ~gap, ~dbz, ~eta, ~dens, ~DBZH, ~n, ~n_dbz, ~n_all, ~n_dbz_all, ~elev1, ~nvolumes_gr35_e1, ~elev2, ~nvolumes_gr35_e2, ~vcp, ~percent_rain,
1L, 9.1082, 5.4677, NA, 36.8916, 29911L, 7.2845, FALSE, 3.7747820481656, 50L, 4.54545454545455, 0.00727495214460544, NA, -6404.5974442746, NA, 851.2421, 12.5202, 0.3646, 216L, 1.3329, 0L, 852.3826,
2L, 14.4428, 10.1568, NA, 44.6877, 49823L, 10.2681, FALSE, 8.54599459536223, 150L, 13.6363636363636, 0.00727495214460544, NA, -241.9400975439, NA, 212.6159, 11.5492, 0.3646, 216L, 1.3329, 0L, 213.7921
1L, 9.1082, 5.4677, NA, 36.8916, 29911L, 7.2845, FALSE, 3.459612, 50L, 4.54545454545455, -0.3078956, NA, -6404.5974442746, NA, 851.2421, 12.5202, 0.3646, 216L, 1.3329, 0L, 852.3826,
2L, 14.4428, 10.1568, NA, 44.6877, 49823L, 10.2681, FALSE, 8.230824, 150L, 13.6363636363636, -0.3078956, NA, -241.9400975439, NA, 212.6159, 11.5492, 0.3646, 216L, 1.3329, 0L, 213.7921
)
)
})

0 comments on commit a517579

Please sign in to comment.