From e28cca46be4508ff162789afe343558c5bb1ae2e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Feret Date: Wed, 17 Jan 2024 00:51:07 +0100 Subject: [PATCH] # prospect v1.6.1 ## addition - added input dataframe InputPROSPECT to function PROSPECT --- DESCRIPTION | 4 +- NAMESPACE | 1 + NEWS.md | 4 ++ R/Lib_PROSPECT.R | 82 +++++++++++++++++++++++++++++------- man/Invert_PROSPECT_OPT.Rd | 4 +- man/PROSPECT.Rd | 3 ++ man/SetInitParm.Rd | 2 +- man/define_Input_PROSPECT.Rd | 51 ++++++++++++++++++++++ man/optimal_features_SFS.Rd | 3 +- 9 files changed, 133 insertions(+), 21 deletions(-) create mode 100644 man/define_Input_PROSPECT.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 088a712..0ce2522 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: prospect Title: PROSPECT leaf radiative transfer model and inversion routines -Version: 1.6.0 +Version: 1.6.1 Authors@R: c(person(given = "Jean-Baptiste", family = "Feret", email = "jb.feret@teledetection.fr", @@ -18,7 +18,7 @@ Depends: R (>= 3.5.0) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.0 Suggests: knitr, emojifont, diff --git a/NAMESPACE b/NAMESPACE index 6a27bb1..d001035 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(calctav) export(check_prospect_parms) export(check_version_prospect) export(colour_to_ansi) +export(define_Input_PROSPECT) export(download_LeafDB) export(optimal_features_SFS) export(print_msg) diff --git a/NEWS.md b/NEWS.md index 8e0154c..4ff8e87 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# prospect v1.6.1 +## addition +- added input dataframe InputPROSPECT to function PROSPECT + # prospect v1.6.0 Released version of the software with the latest changes from the review diff --git a/R/Lib_PROSPECT.R b/R/Lib_PROSPECT.R index 2757c3d..2ade9ac 100644 --- a/R/Lib_PROSPECT.R +++ b/R/Lib_PROSPECT.R @@ -21,6 +21,7 @@ #' @param SpecPROSPECT list. Includes spectral constants derived from #' SpecPROSPECT_FullRange: refractive index, specific absorption coefficients #' and corresponding spectral bands +#' @param Input_PROSPECT list. Includes all prospect input parameters #' @param N numeric. Leaf structure parameter #' @param CHL numeric. Chlorophyll content (microg.cm-2) #' @param CAR numeric. Carotenoid content (microg.cm-2) @@ -35,23 +36,24 @@ #' @return leaf directional-hemispherical reflectance and transmittance #' @importFrom expint expint #' @export -PROSPECT <- function(SpecPROSPECT = NULL, N = 1.5, CHL = 40.0, - CAR = 8.0, ANT = 0.0, BROWN = 0.0, EWT = 0.01, - LMA = NULL, PROT = 0, CBC = 0, alpha = 40.0) { +PROSPECT <- function(SpecPROSPECT = NULL, Input_PROSPECT = NULL, + N = 1.5, CHL = 40.0, CAR = 8.0, ANT = 0.0, BROWN = 0.0, + EWT = 0.01, LMA = NULL, PROT = 0, CBC = 0, alpha = 40.0) { + # define PROSPECT input in a dataframe + Input_PROSPECT <- define_Input_PROSPECT(Input_PROSPECT, CHL, CAR, ANT, BROWN, + EWT, LMA, PROT, CBC, N, alpha) # default: simulates leaf optics using full spectral range if (is.null(SpecPROSPECT)) SpecPROSPECT <- prospect::SpecPROSPECT_FullRange - # check if LMA, PROT and CBC are correctly parameterized - dm_val <- check_version_prospect(LMA, PROT, CBC) # compute total absorption corresponding to each homogeneous layer - Kall <- (CHL * SpecPROSPECT$SAC_CHL + - CAR * SpecPROSPECT$SAC_CAR + - ANT * SpecPROSPECT$SAC_ANT + - BROWN * SpecPROSPECT$SAC_BROWN + - EWT * SpecPROSPECT$SAC_EWT + - dm_val$LMA * SpecPROSPECT$SAC_LMA + - dm_val$PROT * SpecPROSPECT$SAC_PROT + - dm_val$CBC * SpecPROSPECT$SAC_CBC) / N + Kall <- (Input_PROSPECT$CHL * SpecPROSPECT$SAC_CHL + + Input_PROSPECT$CAR * SpecPROSPECT$SAC_CAR + + Input_PROSPECT$ANT * SpecPROSPECT$SAC_ANT + + Input_PROSPECT$BROWN * SpecPROSPECT$SAC_BROWN + + Input_PROSPECT$EWT * SpecPROSPECT$SAC_EWT + + Input_PROSPECT$LMA * SpecPROSPECT$SAC_LMA + + Input_PROSPECT$PROT * SpecPROSPECT$SAC_PROT + + Input_PROSPECT$CBC * SpecPROSPECT$SAC_CBC) / Input_PROSPECT$N # Non-conservative scattering (normal case) when Kall > 0 j <- which(Kall <= 0) @@ -71,10 +73,10 @@ PROSPECT <- function(SpecPROSPECT = NULL, N = 1.5, CHL = 40.0, # *********************************************************************** # reflectivity and transmissivity at the interface # *********************************************************************** - if (alpha == 40) { + if (Input_PROSPECT$alpha == 40) { talf <- SpecPROSPECT$calctav_40 } else { - talf <- calctav(alpha, SpecPROSPECT$nrefrac) + talf <- calctav(Input_PROSPECT$alpha, SpecPROSPECT$nrefrac) } ralf <- 1 - talf t12 <- SpecPROSPECT$calctav_90 @@ -194,6 +196,56 @@ check_version_prospect <- function(LMA, PROT, CBC){ return(list('LMA' = LMA, 'PROT' = PROT, 'CBC' = CBC)) } + +#' This function produces a data frame from all prospect input variables if not +#' defined already +#' +#' + +#' @param Input_PROSPECT numeric. content corresponding to LMA +#' @param CHL numeric. Chlorophyll content (microg.cm-2) +#' @param CAR numeric. Carotenoid content (microg.cm-2) +#' @param ANT numeric. Anthocyanin content (microg.cm-2) +#' @param BROWN numeric. Brown pigment content (Arbitrary units) +#' @param EWT numeric. Equivalent Water Thickness (g.cm-2) +#' @param LMA numeric. Leaf Mass per Area (g.cm-2) +#' @param PROT numeric. protein content (g.cm-2) +#' @param CBC numeric. NonProt Carbon-based constituent content (g.cm-2) +#' @param N numeric. Leaf structure parameter +#' @param alpha numeric. Solid angle for incident light at surface of leaf +#' +#' @return list. updated LMA, PROT and CBC +#' @export + +define_Input_PROSPECT <- function(Input_PROSPECT, CHL = NULL, CAR = NULL, + ANT = NULL, BROWN = NULL, EWT = NULL, + LMA = NULL, PROT = NULL, CBC = NULL, + N = NULL, alpha = NULL){ + + default_PROSPECT <- data.frame('CHL' = 40.0, 'CAR' = 8.0, 'ANT' = 0.0, + 'BROWN' = 0.0, 'EWT' = 0.01, 'LMA' = 0.0, + 'PROT'= 0.0, 'CBC' = 0.0, 'N' = 1.5, + 'alpha' = 40.0) + if (is.null(Input_PROSPECT)){ + dm_val <- prospect::check_version_prospect(LMA, PROT, CBC) + Input_PROSPECT <- data.frame('CHL' = CHL, 'CAR' = CAR, 'ANT' = ANT, + 'BROWN' = BROWN, 'EWT' = EWT, 'LMA' = dm_val$LMA, + 'PROT'= dm_val$PROT, 'CBC' = dm_val$CBC, + 'N' = N, 'alpha' = alpha) + } else if (!is.null(Input_PROSPECT)){ + missing <- which(!names(default_PROSPECT)%in%names(Input_PROSPECT)) + if (length(missing)>0) Input_PROSPECT <- cbind(Input_PROSPECT, default_PROSPECT[missing]) + dm_val <- prospect::check_version_prospect(Input_PROSPECT$LMA, + Input_PROSPECT$PROT, + Input_PROSPECT$CBC) + Input_PROSPECT$LMA <- dm_val$LMA + Input_PROSPECT$PROT <- dm_val$PROT + Input_PROSPECT$CBC <- dm_val$CBC + } + return(Input_PROSPECT) +} + + #' This function adapts SpecPROSPECT accordingly to experimental data #' or to a spectral domain defined by UserDomain #' @param lambda numeric. Spectral bands corresponding to experimental data diff --git a/man/Invert_PROSPECT_OPT.Rd b/man/Invert_PROSPECT_OPT.Rd index 2989955..911b5ac 100644 --- a/man/Invert_PROSPECT_OPT.Rd +++ b/man/Invert_PROSPECT_OPT.Rd @@ -31,8 +31,8 @@ refractive index, specific absorption coefficients and corresponding spectral ba \item{Tran}{numeric. Measured Transmittance data} -\item{PROSPECT_version}{character. Version of prospect model used for the inversion: '5', '5B', 'D', 'DB', 'PRO', 'PROB', -See details.} +\item{PROSPECT_version}{character. Version of prospect model used for the +inversion: 'D', 'PRO'.} \item{Parms2Estimate}{character vector. Parameters to estimate (can be 'ALL')} diff --git a/man/PROSPECT.Rd b/man/PROSPECT.Rd index f406f55..3dc9491 100644 --- a/man/PROSPECT.Rd +++ b/man/PROSPECT.Rd @@ -8,6 +8,7 @@ on the parameterization.} \usage{ PROSPECT( SpecPROSPECT = NULL, + Input_PROSPECT = NULL, N = 1.5, CHL = 40, CAR = 8, @@ -25,6 +26,8 @@ PROSPECT( SpecPROSPECT_FullRange: refractive index, specific absorption coefficients and corresponding spectral bands} +\item{Input_PROSPECT}{list. Includes all prospect input parameters} + \item{N}{numeric. Leaf structure parameter} \item{CHL}{numeric. Chlorophyll content (microg.cm-2)} diff --git a/man/SetInitParm.Rd b/man/SetInitParm.Rd index 63bb31d..814d9c7 100644 --- a/man/SetInitParm.Rd +++ b/man/SetInitParm.Rd @@ -22,7 +22,7 @@ SetInitParm( \item{ParmEst}{character. PROSPECT parameters to be estimated} \item{PROSPECT_version}{character. Version of prospect model used for the -inversion: '5', '5B', 'D', 'DB', 'PRO', 'PROB',} +inversion: 'D' or 'PRO'} \item{Nprior}{numeric prior estimation of N} diff --git a/man/define_Input_PROSPECT.Rd b/man/define_Input_PROSPECT.Rd new file mode 100644 index 0000000..e9e3a80 --- /dev/null +++ b/man/define_Input_PROSPECT.Rd @@ -0,0 +1,51 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/Lib_PROSPECT.R +\name{define_Input_PROSPECT} +\alias{define_Input_PROSPECT} +\title{This function produces a data frame from all prospect input variables if not +defined already} +\usage{ +define_Input_PROSPECT( + Input_PROSPECT, + CHL = NULL, + CAR = NULL, + ANT = NULL, + BROWN = NULL, + EWT = NULL, + LMA = NULL, + PROT = NULL, + CBC = NULL, + N = NULL, + alpha = NULL +) +} +\arguments{ +\item{Input_PROSPECT}{numeric. content corresponding to LMA} + +\item{CHL}{numeric. Chlorophyll content (microg.cm-2)} + +\item{CAR}{numeric. Carotenoid content (microg.cm-2)} + +\item{ANT}{numeric. Anthocyanin content (microg.cm-2)} + +\item{BROWN}{numeric. Brown pigment content (Arbitrary units)} + +\item{EWT}{numeric. Equivalent Water Thickness (g.cm-2)} + +\item{LMA}{numeric. Leaf Mass per Area (g.cm-2)} + +\item{PROT}{numeric. protein content (g.cm-2)} + +\item{CBC}{numeric. NonProt Carbon-based constituent content (g.cm-2)} + +\item{N}{numeric. Leaf structure parameter} + +\item{alpha}{numeric. Solid angle for incident light at surface of leaf} +} +\value{ +list. updated LMA, PROT and CBC +} +\description{ +This function produces a data frame from all prospect input variables if not +defined already +} diff --git a/man/optimal_features_SFS.Rd b/man/optimal_features_SFS.Rd index 5976cb8..dc3a1a9 100644 --- a/man/optimal_features_SFS.Rd +++ b/man/optimal_features_SFS.Rd @@ -61,7 +61,8 @@ Assumes 1nm spectral sampling} \item{number_features}{vector. number of features to be identified} -\item{PROSPECT_version}{character. Version of prospect model used for the inversion: '5', '5B', 'D', 'DB', 'PRO', 'PROB',} +\item{PROSPECT_version}{character. Version of prospect model used for the +inversion: 'D', 'PRO'} \item{MeritFunction}{character. name of the function to be used as merit function with given criterion to minimize (default = RMSE)}