################################################################################
# Spectra functions
################################################################################
#' Verify if object are spectra
#'
#' @param spec any object
#'
#' @return boolean
#' @export
is_spectra = function(spec){
inherits(spec, "spectra")
}
#' Vector normalization of spectra
#'
#' @param spec spectra object to be vector normalized
#'
#' @return spectra object with normalized spectra
#' @export
normalize_spectra = function(spec){
if( !is_spectra(spec) ){
stop("Object must be of class spectra")
}
refl = reflectance(spec)
refl_squared = refl * refl
vec_ones = rep.int(1L, ncol(refl_squared))
spec_sq_rowsum = refl_squared %*% vec_ones
magnitudes = as.vector(sqrt(spec_sq_rowsum))
# normalize and construct a `spectra` object
spec[] = i_reflectance(refl / magnitudes)
# add a magnitute attribute to the`spectra` object
spec$magnitudes = magnitudes
# return
spec
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.