Skip to content

Commit

Permalink
Merge branch 'master' of github.com:traitecoevo/saltbush
Browse files Browse the repository at this point in the history
  • Loading branch information
wcornwell committed Nov 18, 2024
2 parents f0cecc1 + b599c8d commit c9a7d00
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions R/calculate_spectral_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#' red = runif(20000, min = 0, max = 1),
#' red_edge = runif(20000, min = 0, max = 1),
#' nir = runif(20000, min = 0, max = 1))
#' spectral_metrics <- calculate_cv(df,
#' spectral_metrics <- calculate_spectral_metrics(df,
#' wavelengths = c('blue','green','red','red_edge','nir'),
#' rarefaction = TRUE, min_points = 5000, n = 999)

Expand Down Expand Up @@ -183,7 +183,7 @@ calculate_spectral_metrics <- function(pixel_values_df,
sv <- calculate_sv(site_pixel_values, wavelengths = wavelengths)
chv <- calculate_chv_nopca(site_pixel_values, wavelengths, rarefaction = rarefaction, n = n, min_points = min_points)

results <- list(CV = cv, SV = sv, CHV = chv)
results[[site]] <- list(CV = cv, SV = sv, CHV = chv)
}

combined_cv <- dplyr::bind_rows(lapply(results, function(x) x$CV), .id = 'site')
Expand Down
2 changes: 1 addition & 1 deletion man/calculate_cv.Rd

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

21 changes: 21 additions & 0 deletions tests/testthat/test-test_spectral.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ test_that("calculate_cv works", {
expect_true(pixelvalues$aoi_id==1)
})

test_that("calculate_spectral_metrics works", {
set.seed(123)
df <- data.frame(
site_name = rep(c("site_one", "site_two", "site_three", "site_four"), each = 5000),
aoi_id = 1,
blue = runif(20000, min = 0, max = 1),
green = runif(20000, min = 0, max = 1),
red = runif(20000, min = 0, max = 1),
red_edge = runif(20000, min = 0, max = 1),
nir = runif(20000, min = 0, max = 1))
spectral_metrics <- calculate_spectral_metrics(df,
wavelengths = c('blue','green','red','red_edge','nir'),
rarefaction = TRUE, min_points = 5000, n = 999)
expect_type(spectral_metrics,"data.frame")
expect_true(spectral_metrics$CV<0.6)
expect_true(spectral_metrics$SV<0.42)
expect_true(spectral_metrics$CHV_nopca<0.87)
expect_true(spectral_metrics$aoi_id==1)
expect_true(spectral_metrics$image_type=='masked')
})

test_that("extract_pixel_values works", {
aoi_files <- list.files(
system.file("extdata/fishnet", package = "saltbush"),
Expand Down

0 comments on commit c9a7d00

Please sign in to comment.