Skip to content

Commit

Permalink
more internalization
Browse files Browse the repository at this point in the history
  • Loading branch information
miquelcaceres committed Jun 2, 2024
1 parent a8bb29d commit 8fec9b6
Show file tree
Hide file tree
Showing 31 changed files with 301 additions and 177 deletions.
35 changes: 34 additions & 1 deletion R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' @rdname aspwb
#' @keywords internal
aspwbInput <- function(crop_factor, control, soil) {
.Call(`_medfate_aspwbInput`, crop_factor, control, soil)
}

#' @rdname aspwb
#' @keywords internal
aspwb_day <- function(x, date, meteovec, latitude, elevation, slope = NA_real_, aspect = NA_real_, runon = 0.0, lateralFlows = NULL, waterTableDepth = NA_real_, modifyInput = TRUE) {
.Call(`_medfate_aspwb_day`, x, date, meteovec, latitude, elevation, slope, aspect, runon, lateralFlows, waterTableDepth, modifyInput)
}
Expand Down Expand Up @@ -65,6 +67,7 @@ aspwb_day <- function(x, date, meteovec, latitude, elevation, slope = NA_real_,
#' S <- aspwb(x, examplemeteo, latitude = 41.82592, elevation = 100)
#'
#' @name aspwb
#' @keywords internal
aspwb <- function(x, meteo, latitude, elevation, slope = NA_real_, aspect = NA_real_, waterTableDepth = NA_real_) {
.Call(`_medfate_aspwb`, x, meteo, latitude, elevation, slope, aspect, waterTableDepth)
}
Expand Down Expand Up @@ -542,91 +545,109 @@ fire_necrosisHeight <- function(Ib_surf, t_res, thermal_factor, T_air = 25.0, rh
#' plant_ID(exampleforest, SpParamsMED)
#'
#' @name plant_values
#' @keywords internal
plant_ID <- function(x, SpParams, treeOffset = 0L, shrubOffset = 0L) {
.Call(`_medfate_cohortIDs`, x, SpParams, treeOffset, shrubOffset)
}

#' @rdname plant_values
#' @keywords internal
plant_basalArea <- function(x, SpParams) {
.Call(`_medfate_cohortBasalArea`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_largerTreeBasalArea <- function(x, SpParams, self_proportion = 0.5) {
.Call(`_medfate_cohortLargerTreeBasalArea`, x, SpParams, self_proportion)
}

#' @rdname plant_values
#' @keywords internal
plant_cover <- function(x, SpParams) {
.Call(`_medfate_cohortCover`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_species <- function(x, SpParams) {
.Call(`_medfate_cohortSpecies`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_speciesName <- function(x, SpParams) {
.Call(`_medfate_cohortSpeciesName`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_density <- function(x, SpParams) {
.Call(`_medfate_cohortDensity`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_height <- function(x, SpParams) {
.Call(`_medfate_cohortHeight`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_individualArea <- function(x, SpParams) {
.Call(`_medfate_cohortIndividualArea`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_crownRatio <- function(x, SpParams) {
.Call(`_medfate_cohortCrownRatio`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_crownBaseHeight <- function(x, SpParams) {
.Call(`_medfate_cohortCrownBaseHeight`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_crownLength <- function(x, SpParams) {
.Call(`_medfate_cohortCrownLength`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_foliarBiomass <- function(x, SpParams, gdd = NA_real_) {
.Call(`_medfate_cohortFoliarBiomass`, x, SpParams, gdd)
}

#' @rdname plant_values
#' @keywords internal
plant_fuelLoading <- function(x, SpParams, gdd = NA_real_, includeDead = TRUE) {
.Call(`_medfate_cohortFuelLoading`, x, SpParams, gdd, includeDead)
}

#' @rdname plant_values
#' @keywords internal
plant_equilibriumLeafLitter <- function(x, SpParams, AET = 800) {
.Call(`_medfate_cohortEquilibriumLeafLitter`, x, SpParams, AET)
}

#' @rdname plant_values
#' @keywords internal
plant_equilibriumSmallBranchLitter <- function(x, SpParams, smallBranchDecompositionRate = 0.81) {
.Call(`_medfate_cohortEquilibriumSmallBranchLitter`, x, SpParams, smallBranchDecompositionRate)
}

#' @rdname plant_values
#' @keywords internal
plant_phytovolume <- function(x, SpParams) {
.Call(`_medfate_cohortPhytovolume`, x, SpParams)
}

#' @rdname plant_values
#' @keywords internal
plant_LAI <- function(x, SpParams, gdd = NA_real_, bounded = TRUE) {
.Call(`_medfate_cohortLAI`, x, SpParams, gdd, bounded)
}
Expand All @@ -651,16 +672,19 @@ plant_LAI <- function(x, SpParams, gdd = NA_real_, bounded = TRUE) {
#' @seealso \code{\link{spwb}}, \code{\link{forest}}, \code{\link{plant_basalArea}}, \code{\link{summary.forest}}
#'
#' @name herb_values
#' @keywords internal
herb_foliarBiomass <- function(x, SpParams) {
.Call(`_medfate_herbFoliarBiomass`, x, SpParams)
}

#' @rdname herb_values
#' @keywords internal
herb_fuelLoading <- function(x, SpParams) {
.Call(`_medfate_herbFuelLoading`, x, SpParams)
}

#' @rdname herb_values
#' @keywords internal
herb_LAI <- function(x, SpParams) {
.Call(`_medfate_herbLAI`, x, SpParams)
}
Expand Down Expand Up @@ -711,21 +735,25 @@ herb_LAI <- function(x, SpParams) {
#' species_parameter(c("Pinus halepensis", "Quercus ilex"), SpParamsMED, "Psi_Extract")
#'
#' @name species_values
#' @keywords internal
species_basalArea <- function(x, SpParams) {
.Call(`_medfate_speciesBasalArea`, x, SpParams)
}

#' @rdname species_values
#' @keywords internal
species_cover <- function(x, SpParams) {
.Call(`_medfate_speciesCover`, x, SpParams)
}

#' @rdname species_values
#' @keywords internal
species_density <- function(x, SpParams) {
.Call(`_medfate_speciesDensity`, x, SpParams)
}

#' @rdname species_values
#' @keywords internal
species_foliarBiomass <- function(x, SpParams, gdd = NA_real_) {
.Call(`_medfate_speciesFoliarBiomass`, x, SpParams, gdd)
}
Expand All @@ -751,16 +779,19 @@ stand_foliarBiomass <- function(x, SpParams, gdd = NA_real_) {
}

#' @rdname stand_values
#' @keywords internal
stand_fuelLoading <- function(x, SpParams, gdd = NA_real_, includeDead = TRUE) {
.Call(`_medfate_standFuelLoading`, x, SpParams, gdd, includeDead)
}

#' @rdname stand_values
#' @keywords internal
stand_shrubVolume <- function(x, SpParams) {
.Call(`_medfate_standShrubVolume`, x, SpParams)
}

#' @rdname stand_values
#' @keywords internal
stand_LAI <- function(x, SpParams, gdd = NA_real_, bounded = TRUE) {
.Call(`_medfate_standLAI`, x, SpParams, gdd, bounded)
}
Expand Down Expand Up @@ -3855,12 +3886,13 @@ plant_water <- function(x) {
#' @param herbTranspiration Transpiration of herbaceous plants for \code{day} (mm).
#' @param stepFunctions An integer to indicate a simulation step for which photosynthesis and profit maximization functions are desired.
#'
#'
#' @keywords internal
transp_transpirationSperry <- function(x, meteo, day, latitude, elevation, slope, aspect, canopyEvaporation = 0.0, snowMelt = 0.0, soilEvaporation = 0.0, herbTranspiration = 0.0, stepFunctions = NA_integer_, modifyInput = TRUE) {
.Call(`_medfate_transpirationSperry`, x, meteo, day, latitude, elevation, slope, aspect, canopyEvaporation, snowMelt, soilEvaporation, herbTranspiration, stepFunctions, modifyInput)
}

#' @rdname transp_modes
#' @keywords internal
transp_transpirationSureau <- function(x, meteo, day, latitude, elevation, slope, aspect, canopyEvaporation = 0.0, snowMelt = 0.0, soilEvaporation = 0.0, herbTranspiration = 0.0, modifyInput = TRUE) {
.Call(`_medfate_transpirationSureau`, x, meteo, day, latitude, elevation, slope, aspect, canopyEvaporation, snowMelt, soilEvaporation, herbTranspiration, modifyInput)
}
Expand Down Expand Up @@ -4048,6 +4080,7 @@ transp_transpirationSureau <- function(x, meteo, day, latitude, elevation, slope
#' modifyInput = FALSE)
#'
#' @name transp_modes
#' @keywords internal
transp_transpirationGranier <- function(x, meteo, day, latitude, elevation, slope, aspect, modifyInput = TRUE) {
.Call(`_medfate_transpirationGranier`, x, meteo, day, latitude, elevation, slope, aspect, modifyInput)
}
Expand Down
6 changes: 6 additions & 0 deletions R/VerticalProfiles.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#'
#' vprofile_windExtinction(exampleforest, SpParamsMED)
#'
#' @keywords internal
#' @name vprofile_leafAreaDensity
vprofile_leafAreaDensity<-function(x, SpParams = NULL, z = NULL, gdd = NA,
byCohorts = FALSE, bySpecies = FALSE, includeHerbs = FALSE,
Expand Down Expand Up @@ -117,6 +118,7 @@ vprofile_leafAreaDensity<-function(x, SpParams = NULL, z = NULL, gdd = NA,
}

#' @rdname vprofile_leafAreaDensity
#' @keywords internal
vprofile_rootDistribution<-function(x, SpParams, d = NULL, bySpecies = FALSE,
draw = TRUE, xlim = NULL) {
if(is.null(d)){
Expand Down Expand Up @@ -145,6 +147,7 @@ vprofile_rootDistribution<-function(x, SpParams, d = NULL, bySpecies = FALSE,
}

#' @rdname vprofile_leafAreaDensity
#' @keywords internal
vprofile_fuelBulkDensity<-function(x, SpParams, z = NULL, gdd = NA,
draw = TRUE, xlim = NULL) {
if(is.null(z)) z <- seq(0, ceiling(max(plant_height(x, SpParams))/100)*100 +10, by=1)
Expand All @@ -163,6 +166,7 @@ vprofile_fuelBulkDensity<-function(x, SpParams, z = NULL, gdd = NA,
}

#' @rdname vprofile_leafAreaDensity
#' @keywords internal
vprofile_PARExtinction<-function(x, SpParams, z = NULL, gdd = NA, includeHerbs = FALSE,
draw = TRUE, xlim = c(0,100)) {
if(is.null(z)) z <- seq(0, ceiling(max(plant_height(x, SpParams), na.rm = TRUE)/100)*100 +10, by=1)
Expand All @@ -181,6 +185,7 @@ vprofile_PARExtinction<-function(x, SpParams, z = NULL, gdd = NA, includeHerbs =
}

#' @rdname vprofile_leafAreaDensity
#' @keywords internal
vprofile_SWRExtinction<-function(x, SpParams, z = NULL, gdd = NA, includeHerbs = FALSE,
draw = TRUE, xlim = c(0,100)) {
if(is.null(z)) z <- seq(0, ceiling(max(plant_height(x, SpParams))/100)*100 +10, by=1)
Expand All @@ -199,6 +204,7 @@ vprofile_SWRExtinction<-function(x, SpParams, z = NULL, gdd = NA, includeHerbs =
}

#' @rdname vprofile_leafAreaDensity
#' @keywords internal
vprofile_windExtinction<-function(x, SpParams, u = 1, windMeasurementHeight = 200,
boundaryLayerSize = 2000, target = "windspeed",
z = NULL, gdd = NA, includeHerbs = FALSE,
Expand Down
64 changes: 64 additions & 0 deletions R/dataset_documentation.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
#' Description of the plant cohorts of a forest stand.
#'
#' \code{exampleforest} is an example of forest stand description, whereas \code{exampleforest2} is an alternative forest description where leaf area index and crown ratio are supplied instead of structural (density, DBH and cover) parameters.
#'
#' @name forest
#' @aliases exampleforest exampleforest2
#' @docType data
#'
#' @source DGCN (2005). Tercer Inventario Forestal Nacional (1997-2007): Catalunya. \enc{Dirección}{Direccion} General de \enc{Conservación}{Conservacion} de la Naturaleza, Ministerio de Medio Ambiente, Madrid.
#' @seealso \code{\link{forest}}, \code{\link{spwb}}, \code{\link{spwbInput}}
#' @format An object of class \code{forest} contains the description of the woody (tree or shrub) cohorts and herb layer of a forest patch.
#' It has the following structure (see details):
#' \itemize{
#' \item{\code{treeData}: A data frame of tree cohorts (in rows) and the following columns:
#' \itemize{
#' \item{\code{Species}: String with species (taxon) name or a non-negative integer for tree species identity (i.e., 0,1,2,...) matching SpParams.}
#' \item{\code{Height}: Total tree height (in cm).}
#' \item{\code{DBH}: Tree diameter at breast height (in cm).}
#' \item{\code{N}: Density (number of individuals/hectare) that the measured tree represents.}
#' \item{\code{Z50}: Depth (in mm) corresponding to 50\% of fine roots.}
#' \item{\code{Z95}: Depth (in mm) corresponding to 95\% of fine roots.}
#' }
#' }
#' \item{\code{shrubData}: A data frame of shrub cohorts (in rows) and the following columns:
#' \itemize{
#' \item{\code{Species}: String with species (taxon) name or a non-negative integer for shrub species identity (i.e., 0,1,2,...) matching SpParams.}
#' \item{\code{Height}: Average total height of plants (in cm).}
#' \item{\code{Cover}: Percent cover.}
#' \item{\code{Z50}: Depth (in mm) corresponding to 50\% of fine roots.}
#' \item{\code{Z95}: Depth (in mm) corresponding to 95\% of fine roots.}
#' }
#' }
#' \item{\code{herbCover}: Percent cover of the herb layer (optional).}
#' \item{\code{herbHeight}: Mean height (in cm) of the herb layer (optional).}
#' \item{\code{seedBank}: A data frame containing seed bank information with the following columns:
#' \itemize{
#' \item{\code{Species}: String with species (taxon) name or a non-negative integer for tree species identity (i.e., 0,1,2,...) matching SpParams.}
#' \item{\code{Percent}: Amount of seeds in relation to full seed bank (in \%).}
#' }
#' }
#' }
#' @details
#' The structure presented above for \code{forest} objects corresponds to the required data elements.
#' A \code{forest} object can contain additional information when this is available. Data frames \code{treeData}
#' and \code{shrubData} can contain additional columns:
#' \itemize{
#' \item{\code{LAI}: Leaf area index (m2/m2)}
#' \item{\code{FoliarBiomass}: Standing dry biomass of leaves (kg/m2)}
#' \item{\code{FuelLoading}: Fine fuel loading (kg/m2)}
#' \item{\code{CrownRatio}: The ratio between crown length and total height (between 0 and 1)}
#' }
#' Similarly, one can define \code{forest} list elements \code{herbLAI}, \code{herbFoliarBiomass} or \code{herbFuelLoading}.
#' All these values are used to override allometry-based estimates of those variables when initializing
#' inputs for functions \code{\link{spwb}} or \code{\link{spwb_day}}. Note that leaf area index, foliar biomass and
#' fuel loading are related entities, and they are treated as such in medfate. Therefore, users are expected to supply
#' one or the other, and not all of them at the same time.
#'
#' @seealso \code{\link{summary.forest}}, \code{\link{emptyforest}}, \code{\link{plot.forest}}
#' @examples
#' data(exampleforest)
#' data(exampleforest2)
#' @keywords data
NULL

#' Example daily meteorology data
#'
#' Example data set of meteorological input.
Expand Down
40 changes: 40 additions & 0 deletions R/emptyforest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#' Creation of an empty forest
#'
#' Creates an empty \code{\link{forest}} object.
#'
#' @param ntree,nshrub Number of tree and shrub cohorts, respectively.
#' @param nseed Number of species in the seed bank.
#'
#' @return An empty \code{\link{forest}} object.
#'
#' @author Miquel De \enc{Cáceres}{Caceres} Ainsa, CREAF
#'
#' @seealso \code{\link{forest}}, \code{\link{tree2forest}}, \code{\link{summary.forest}}, \code{\link{forest_mapWoodyTables}}, \code{\link{forest_mergeTrees}},
#' \code{\link{plot.forest}}
#'
#' @examples
#' # Initializes forest with 2 tree cohorts and 1 shrub cohort
#' emptyforest(ntree = 2, nshrub = 1)
#'
#' @name emptyforest
emptyforest <- function(ntree = 0, nshrub = 0, nseed = 0) {
l <- list()
l$treeData <- data.frame(Species=as.character(rep(NA, ntree)),
DBH=as.numeric(rep(NA, ntree)),
Height=as.numeric(rep(NA, ntree)),
N=as.numeric(rep(NA, ntree)),
Z50 = as.numeric(rep(NA, ntree)),
Z95=as.numeric(rep(NA, ntree)))
l$shrubData <- data.frame(Species=as.character(rep(NA, nshrub)),
Height=as.numeric(rep(NA, nshrub)),
Cover = as.numeric(rep(NA, nshrub)),
Z50 = as.numeric(rep(NA, nshrub)),
Z95=as.numeric(rep(NA, nshrub)))
l$herbCover <- NA;
l$herbHeight <- NA;
l$seedBank <- data.frame(Species = as.character(rep(NA, nseed)),
Percent = as.numeric(rep(NA, nseed)))
class(l)<-c("forest","list")
return(l)
}

1 change: 1 addition & 0 deletions R/hydraulics_supplyFunctionPlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#' @param speciesNames A flag to indicate the use of species names instead of cohort names in plots.
#' @param ylim Graphical parameter to override function defaults.
#'
#' @keywords internal
hydraulics_supplyFunctionPlot<-function(x, draw = TRUE, type="E", speciesNames = FALSE, ylim=NULL) {

TYPES = c("E","dEdP","StemPsi","RootPsi","ERhizo")
Expand Down
1 change: 1 addition & 0 deletions R/hydraulics_vulnerabilityCurvePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#' @param draw A flag to indicate whether the vulnerability curve should be drawn or just returned.
#' @param ylim,xlab,ylab Graphical parameters to override function defaults.
#'
#' @keywords internal
hydraulics_vulnerabilityCurvePlot<-function(x, soil = NULL, type="leaf", vulnerabilityFunction = "Weibull",
psiVec = seq(-0.1, -8.0, by =-0.01),
relative = FALSE, speciesNames = FALSE,
Expand Down
Loading

0 comments on commit 8fec9b6

Please sign in to comment.