Skip to content

Commit e88712a

Browse files
Add language documentation to fix #94
1 parent 2707b7e commit e88712a

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

R/calculate_indices.R

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@
2222
#' @param raster The raster (either as a SpatRaster or object readable by
2323
#' [terra::rast()]) to compute indices from.
2424
#' @param indices A data frame of indices to compute. The intent is for this
25-
#' function to work with subsets of [spectral_indices], but any data frame with
26-
#' columns `formula` (containing a string representation of the equation used
27-
#' to calculate the index), `bands` (a list column containing character vectors
28-
#' of the necessary bands) and `short_name` (which will be used as the band
29-
#' name) will work.
25+
#' function to work with subsets of [spectral_indices()], but you can provide
26+
#' any data frame with `formula`, `bands`, and `short_name` columns; see
27+
#' "Custom indices" below.
3028
#' @param output_filename The filename to write the computed metrics to.
3129
#' @inheritParams rlang::args_dots_empty
3230
#' @inheritParams terra::predict
@@ -40,6 +38,27 @@
4038
#' @param names_suffix If not `NULL`, will be used (with [paste()]) to add a
4139
#' suffix to each of the band names returned.
4240
#'
41+
#' @section Custom indices:
42+
#' While this function is designed to work with subsets of [spectral_indices()],
43+
#' you can also provide your own custom indices by providing a data frame with
44+
#' at least three columns:
45+
#'
46+
#' * `formula` should contain a string representation of the equation used to
47+
#' calculate the index. This string will be interpreted as R code, and should use
48+
#' normal R arithmetic operators. Any additional functions used in calculating the
49+
#' index will need to be passed through `extra_objects`.
50+
#' * `bands` should be a list column containing character vectors identifying the
51+
#' bands required to calculate the index. These vectors will be checked against the
52+
#' band names of `raster` to make sure that all necessary bands are available
53+
#' before indices are calculated.
54+
#' * `short_name` should contain a string which will be used as the band name in
55+
#' the final output file.
56+
#'
57+
#' Sometimes you might want to tweak the formula used for an existing index, for
58+
#' instance to set non-data parameters to constant values. In that case, make sure
59+
#' you also update `bands` to reflect just the bands required by your updated formula,
60+
#' so that the function won't error unnecessarily.
61+
#'
4362
#' @return `output_filename`, unchanged.
4463
#'
4564
#' @examples

man/calculate_indices.Rd

Lines changed: 27 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_stac_data.Rd

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)