Skip to content

Commit 38084c0

Browse files
committed
getting help file to work
1 parent 17437a5 commit 38084c0

16 files changed

+68
-26
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
^\.Rproj\.user$
33
^\.github$
44
^LICENSE\.md$
5+
^\.DS_Store$

DESCRIPTION

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ Imports:
1414
pROC,
1515
raster,
1616
data.table,
17-
stringr,
18-
vegan,
19-
tidyr,
2017
geometry,
21-
sf,
2218
ausplotsR,
2319
terra
2420
Suggests:

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
export(calculate_chv)
4+
export(calculate_chv_nopca)
35
export(calculate_cv)
46
export(calculate_field_diversity)
7+
export(calculate_spectral_metrics)
8+
export(calculate_sv)
59
export(create_masked_raster)
610
export(create_multiband_image)
711
export(extract_pixel_values)
812
export(find_optimum_thresholds)
913
import(ausplotsR)
14+
import(data.table)

R/calculate_field_diversity.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#' @export
66
#' @import ausplotsR
77

8+
89
calculate_field_diversity <- function(survey_data){
910
# get unique site names
1011
ausplot_sites <- unique(survey_data$site_location_name)

R/calculate_spectral_metrics.R

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,36 @@
1-
#' @title Calculate spectral metrics
2-
#' @description Calculates CV, SV, and CHV from pixel values dataframe with columns for each wavelength + site_name + aoi_id
3-
#' @param pixel_values_df the data frame containing pixel values, obtained from extract_pixel_values function
4-
#' @param wavelengths a list of wavelengths which correspond to column names from pixel_values_df
5-
#' @param rarefaction either TRUE or FALSE to apply rarefaction step. substantially increases processing time
6-
#' @param min_points if rarefaction = T, the minimum number of pixels for any aoi - to standardise uneven number of pixels across different sites
7-
#' @param n if rarefaction = T, number of subset permutations
8-
#' @return a dataframe containing spectral metrics for each aois within each site/raster
1+
#' @title Calculate Spectral Metrics
2+
#' @description Calculates CV, SV, and CHV from a pixel values dataframe with columns for each wavelength, `site_name`, and `aoi_id`.
3+
#' This help file applies to the functions `calculate_cv`, `calculate_sv`, `calculate_chv`, `calculate_chv_nopca`, and `calculate_spectral_metrics`.
4+
#' @param pixel_values_df A data frame containing pixel values, typically obtained from the `extract_pixel_values` function.
5+
#' @param wavelengths A list of wavelengths that correspond to column names in `pixel_values_df`.
6+
#' @param rarefaction Logical; if TRUE, applies a rarefaction step that increases processing time.
7+
#' @param min_points Integer; minimum number of pixels per `aoi` to standardize uneven pixel numbers across sites (used if `rarefaction = TRUE`).
8+
#' @param n Integer; number of subset permutations if `rarefaction = TRUE`.
9+
#' @return A dataframe containing spectral metrics for each `aoi` within each site/raster.
10+
#' @aliases calculate_cv calculate_sv calculate_chv calculate_chv_nopca calculate_spectral_metrics
911
#' @export
10-
11-
# rarefraction cv function
12+
#' @import data.table
13+
#' @examples
14+
#' set.seed(123)
15+
#' df <- data.frame(
16+
#' site_name = rep(c("site_one", "site_two", "site_three", "site_four"), each = 5000),
17+
#' aoi_id = 1,
18+
#' blue = runif(20000, min = 0, max = 1),
19+
#' green = runif(20000, min = 0, max = 1),
20+
#' red = runif(20000, min = 0, max = 1),
21+
#' red_edge = runif(20000, min = 0, max = 1),
22+
#' nir = runif(20000, min = 0, max = 1))
23+
#' pixelvalues <- calculate_cv(df,
24+
#' wavelengths = c('blue','green','red','red_edge','nir'),
25+
#' rarefaction = TRUE, min_points = 5000, n = 999)
1226
calculate_cv <- function(pixel_values_df,
1327
wavelengths,
1428
rarefaction = FALSE,
1529
min_points = NULL,
1630
n = NULL) {
1731

1832
# convert to a data.table for efficiency
19-
setDT(pixel_values_df)
33+
data.table::setDT(pixel_values_df)
2034

2135
if (rarefaction) {
2236
# initialize a list to store CV values for each replication
@@ -56,7 +70,9 @@ calculate_cv <- function(pixel_values_df,
5670

5771

5872

59-
# sv function
73+
# sv function\
74+
#' @import data.table
75+
#' @export
6076
calculate_sv <- function(pixel_values_df, wavelengths) {
6177
# convert pixel_values_df to data.table for better performance
6278
setDT(pixel_values_df)
@@ -83,6 +99,8 @@ calculate_sv <- function(pixel_values_df, wavelengths) {
8399

84100

85101
# chv function
102+
#' @import data.table
103+
#' @export
86104
calculate_chv <- function(df, dim) {
87105
CHV_df <- df %>%
88106
select(1:dim)
@@ -96,6 +114,8 @@ calculate_chv <- function(df, dim) {
96114
}
97115

98116
# function to calculate chv for each aoi
117+
#' @import data.table
118+
#' @export
99119
calculate_chv_nopca <- function(df,
100120
wavelengths,
101121
rarefaction = FALSE,
@@ -141,7 +161,8 @@ calculate_chv_nopca <- function(df,
141161
}
142162

143163

144-
## FUNCTION FOR CALCULATING ALL METRICS
164+
#' @import data.table
165+
#' @export
145166
calculate_spectral_metrics <- function(pixel_values_df,
146167
masked = TRUE,
147168
wavelengths,

doc/create_multiband_image/blue.tif

-9 MB
Binary file not shown.

doc/create_multiband_image/green.tif

-9.01 MB
Binary file not shown.

doc/create_multiband_image/nir.tif

-8.98 MB
Binary file not shown.

doc/create_multiband_image/red.tif

-8.91 MB
Binary file not shown.
-9.03 MB
Binary file not shown.

0 commit comments

Comments
 (0)