Skip to content

Commit

Permalink
updating doc
Browse files Browse the repository at this point in the history
  • Loading branch information
adelegem committed Nov 15, 2024
1 parent 07cde5e commit 9875579
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
25 changes: 13 additions & 12 deletions R/calculate_spectral_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
#' @examples
#' 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))
#' pixelvalues <- calculate_cv(df,
#' wavelengths = c('blue','green','red','red_edge','nir'),
#' rarefaction = TRUE, min_points = 5000, n = 999)
#' 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)

calculate_cv <- function(pixel_values_df,
wavelengths,
rarefaction = FALSE,
Expand Down Expand Up @@ -70,7 +71,7 @@ calculate_cv <- function(pixel_values_df,



# sv function\
# sv function
#' @import data.table
#' @export
calculate_sv <- function(pixel_values_df, wavelengths) {
Expand Down Expand Up @@ -177,7 +178,7 @@ calculate_spectral_metrics <- function(pixel_values_df,
# calculate metrics, pass rarefaction where needed
cv <- calculate_cv(site_pixel_values, wavelengths = wavelengths, rarefaction = rarefaction, n = n, min_points = min_points)
sv <- calculate_sv(site_pixel_values, wavelengths = wavelengths)
chv <- calculate_chv_nopca(site_pixel_values, wavelengths, rarefaction = rarefaction, min_points = min_points)
chv <- calculate_chv_nopca(site_pixel_values, wavelengths, rarefaction = rarefaction, n = n, min_points = min_points)

results[[site]] <- list(CV = cv, SV = sv, CHV = chv)
}
Expand Down
9 changes: 9 additions & 0 deletions R/create_masked_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#' @param nir_threshold_df optional - a two columned df with 'site' col (site values must match first string of input file name) and threshold values for each file
#' @param red_band_index layer number for red band
#' @param nir_band_index layer number for nir band
#' @examples
#' input_folder <- 'inst/doc/multiband_image'
#' output_folder <- tempdir()
#' create_masked_raster(input_folder,
#' output_dir = output_folder,
#' ndvi_threshold = 0.02,
#' nir_threshold = 0.04,
#' red_band_index = 3,
#' nir_band_index = 5)
#' @return A masked raster image, saved in the output directory
#' @export

Expand Down
15 changes: 3 additions & 12 deletions R/extract_pixel_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,9 @@
#' @param wavelength_names wavelength names for each band, must match order of stacked layers
#' @return a df with pixel values for each of the image layers
#' @examples
#' 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))
#' pixelvalues <- calculate_cv(df,
#' wavelengths = c('blue','green','red','red_edge','nir'),
#' rarefaction = TRUE, min_points = 5000, n = 999)
#' aoi_files <- list.files('inst/doc/fishnet', pattern = '_fishnet.shp$', full.names = TRUE)
#' raster_files <- list.files('inst/doc/multiband_image', pattern = '.tif$', full.names = TRUE)
#' pixelvalues <- extract_pixel_values(raster_files, aoi_files, c('blue', 'green', 'red', 'red_edge', 'nir'))
#' @export

extract_pixel_values <- function(raster_files, aoi_files, wavelength_names){
Expand Down
8 changes: 6 additions & 2 deletions R/find_optimum_thresholds.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
#' @param class_col name of column where object class are stored
#' @param class_value value/s of class that should be masked - e.g. for ndvi, 'non-veg' or c('bare_ground','rocks'), for nir, 'shadow'
#' @return a df with optimum thresholds for each site
#' @export
#' @examples
#' rnorm(500)
#' ndvi_values <- data.frame(site = rep(c("site_one", "site_two"), each = 100),
#' point = rep(1:100, times = 2),
#' ndvi = runif(200, min = -1, max = 1),
#' class = sample(rep(c('veg', 'non-veg'), each = 100)))
#' ndvi_thresholds <- find_optimum_thresholds(ndvi_values, class_col = 'class', band_or_index_col = 'ndvi', site_col = 'site', class_value = 'non-veg')
#' @export


# add a for loop so nir and ndvi ground truth values can be given in the same df instead of seperately :)
Expand Down

0 comments on commit 9875579

Please sign in to comment.