Topic: Biomass

Topic Description:

Functions for calculating above-ground tree biomass in CTFS plots.



File: biomass/biomass.CTFSdb.r

View File Source Download File No help file available

Function: density.ind

Function Description: density.ind

Create a vector of wood density for each individual tree based on the species name and plot. The table of individuals, called df, must include a dbh and a species name, the latter named sp. There must be a table of wood density submitted (wsgdata), and this table must have a column sp with species names, a column plot, plus the wood density in a column called wsg (though the name of that column can be changed using the argument denscol). The CTFS wood-density table has this structure, but any table with those columns will work. If a species in the df table has a matching species name in the correct plot, its wood density is taken. If a species is not found in the correct plot, then the mean wood density of all species in the same plot is taken. The function fails (returns only NAs) if there are no entries for the selected plot in the wood-density table. Returns a vector of wood density of the same size as the df table submitted.

Function Arguments:

ArgumentDefault Value
df
plot
wsgdata
denscol'wsg'

Sample Usage:

wooddens=density.ind(df=bci.full1,plot="bci",wsg=wsg.ctfs2)
mean(wooddens,na.rm=TRUE)
length(which(is.na(wooddens)))


Function Source:

density.ind=function(df,plot,wsgdata,denscol='wsg')
{
wsgdatamatch=which(wsgdata$site %in% plot)
if(length(wsgdatamatch)==0) return(rep(NA,dim(df)[1]))

wsgdata=unique(wsgdata[wsgdatamatch,])
meanwsg=mean(subset(wsgdata,idlevel=='species')[,denscol],na.rm=TRUE)

m=match(df$sp,wsgdata$sp)

result=wsgdata[m,denscol]
result[is.na(m)]=meanwsg
result[is.na(result)]=meanwsg

return(result)
}