Skip to content

Commit

Permalink
removing examples for now
Browse files Browse the repository at this point in the history
  • Loading branch information
wcornwell committed Nov 12, 2024
1 parent f6f1af1 commit 1e2ca77
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 74 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ Imports:
stringr,
vegan,
tidyr,
tidyverse,
geometry,
sf,
ausplotsR,
terra
Suggests:
testthat (>= 3.0.0)
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(create_masked_raster)
export(create_multiband_image)
export(extract_pixel_values)
export(find_optimum_thresholds)
import(ausplotsR)
import(data.table)
import(dplyr)
import(geometry)
Expand All @@ -15,6 +16,5 @@ import(sf)
import(stringr)
import(terra)
import(tidyr)
import(tidyverse)
import(tools)
import(vegan)
5 changes: 0 additions & 5 deletions R/calculate_field_diversity.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
#' @description Takes ausplot survey data, calculates field diversity for each site
#' @param survey_data a df obtained from ausplotsR package with survey data for appropriate sites
#' @return a list, containing 'field diversity' - values of species richness, shannon's index, simpsons index, exponential shannon's, inverse simpson, pielou's evenness, and 'community matrices'
#' ausplotdata <- get_ausplots(veg.vouchers = T, veg.PI = T)
#' twentyfour_survey_data <- veg$veg.PI %>%
#' left_join(veg$site.info %>% dplyr::select(site_unique, visit_start_date), by = "site_unique") %>%
#' filter(substr(visit_start_date, 1, 4) == '2024')
#' twentyfour_diversity <- calculate_field_diversity(twentyfour_survey_data)
#' @export
#' @import dplyr
#' @import tidyr
Expand Down
10 changes: 0 additions & 10 deletions R/calculate_spectral_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@
#' @param min_points if rarefaction = T, the minimum number of pixels for any aoi - to standardise uneven number of pixels across different sites
#' @param n if rarefaction = T, number of subset permutations
#' @return a dataframe containing spectral metrics for each aois within each site/raster
#' @example 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_spectral_metrics(df, wavelengths = c('blue','green','red','red_edge','nir'), rarefaction = T, min_points = 5000, n = 999)
#' @export
#' @import dplyr
#' @import data.table
Expand Down
14 changes: 2 additions & 12 deletions R/create_masked_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
#' @param red_band_index layer number for red band
#' @param nir_band_index layer number for nir band
#' @return A masked raster image, saved in the output directory
#' @examples
#'input_folder <- 'doc/multiband_image'
#'create_masked_raster(input_folder,
#'output_dir = 'tempdir()',
#'ndvi_threshold = 0.02,
#'nir_threshold = 0.04,
#'red_band_index = 3,
#'NIR_band_index = 5)
#' @export
#' @import terra
#' @import raster
Expand All @@ -32,7 +24,7 @@
create_masked_raster <- function(input, output_dir,
ndvi_threshold = NULL, nir_threshold = NULL,
ndvi_threshold_df = NULL, nir_threshold_df = NULL,
red_band_index = 3, NIR_band_index = 5) {
red_band_index = 3, nir_band_index = 5) {

if (dir.exists(input)) {
# list all ENVI or TIF files in the directory
Expand Down Expand Up @@ -83,7 +75,7 @@ create_masked_raster <- function(input, output_dir,

# identify the bands for Red and NIR
red <- raster_data[[red_band_index]]
nir <- raster_data[[NIR_band_index]]
nir <- raster_data[[nir_band_index]]

# calculate NDVI
ndvi <- (nir - red) / (nir + red)
Expand All @@ -102,6 +94,4 @@ create_masked_raster <- function(input, output_dir,
}
}

library(tools)
create_masked_raster('C:/Users/adele/Documents/fg_spectral_diversity/data_out/combined_rasters/2024/NSABHC0009_combined_image.tif', 'test', ndvi_threshold = 0.02, nir_threshold = 0.04)

12 changes: 0 additions & 12 deletions R/create_multiband_image.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
#' @param desired_band_order Order of files to be combined. should be in wavelength order. provide vector of file basenames in correct order
#' @param output_dir Folder to store combined tif file
#' @return combined tif file
#' @examples
#' input_dir <- tempdir()
#' for (i in 1:3) {
#' band <- rast(ncol=10, nrow=10, vals = runif(100, 0, 1))
#' writeRaster(band, filename = file.path(input_dir, paste0("band", i, ".tif")), overwrite = TRUE)
#' }
#' output_dir <- file.path(tempdir(), "output_dir")
#' if (!dir.exists(output_dir)) {
#' dir.create(output_dir, recursive = TRUE)
#' }
#' create_multiband_image(input_dir, c('band1','band2','band3'), output_dir)
#' @export
#' @import tools
#' @import terra
Expand Down Expand Up @@ -61,4 +50,3 @@ create_multiband_image <- function(input_dir, desired_band_order, output_dir){
}
}

print(input_dir)
4 changes: 0 additions & 4 deletions R/extract_pixel_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
#' @param aoi_files area of interest file - shapefile containing one or more site polygons for each raster
#' @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
#' raster_files <- list.files('doc/multiband_image', pattern = '.tif$', full.names = TRUE)
#' aoi_files <- list.files('doc/fishnet', pattern = '.shp$', full.names = TRUE)
#' pixelvalues <- extract_pixel_values(raster_files, aoi_files, c('blue','green','red','red_edge','nir'))
#' @export
#' @import raster
#' @import dplyr
Expand Down
8 changes: 2 additions & 6 deletions R/find_optimum_thresholds.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@
#' @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
#' @examples
#' 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 = 'class', value = 'nir', site = 'site', class_value = 'non-veg')
#' @export
#' @examples
#' rnorm(500)
#' @import pROC
#' @import dplyr

Expand Down
22 changes: 16 additions & 6 deletions man/calculate_cv.Rd

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

10 changes: 1 addition & 9 deletions man/create_masked_raster.Rd

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

3 changes: 0 additions & 3 deletions man/create_multiband_image.Rd

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

3 changes: 0 additions & 3 deletions man/extract_pixel_values.Rd

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

4 changes: 2 additions & 2 deletions man/find_optimum_thresholds.Rd

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

0 comments on commit 1e2ca77

Please sign in to comment.