#!/usr/bin/env Rscript ##### FORMAT TRAIT FOR Canada source("R/find.trait/trait.fun.R") ### read species names data.tree <- read.csv("output/formatted/BCI/tree.csv", stringsAsFactors = FALSE) species.clean <- data.frame(sp=data.tree[!duplicated(data.tree[["sp"]]),"sp"], Latin_name=data.tree[!duplicated(data.tree[["sp"]]),"sp.name"], Latin_name_syn=data.tree[!duplicated(data.tree[["sp"]]),"sp.name"], stringsAsFactors =FALSE) ###################################### MASSAGE TRAIT DATA Use HEIGHT_AVG, LMALAM_AVD, SEED_DRY ## data.trait.new <- read.table("data/raw/BCI/Kunstler.BCI.traits.txt", stringsAsFactors = FALSE, ## header = T) #### NEW DATA BASE SENT PER JOE NEED RESTRUCTURE OF THE CODE data.trait <- read.csv("data/raw/BCI/BCITRAITS_20101220.csv", stringsAsFactors = FALSE, header = T) data.trait$Latin <- apply(data.trait[, 1:2], 1, paste, collapse = " ") data.trait <- data.trait[,c("GENUS.","SP.","Latin","SEED_DRY","LMALAM_AVD","LMALAM_SED","LMALAM_ND","SG100C_AVG","SG100C_SEM","SG100C_N","HEIGHT_AVG","HEIGHT_SEM","HEIGHT_N")] data.trait$sp <- data.trait[["SP."]] data.trait[["SP."]] <- NULL data.trait$Leaf.N.mean <- NA data.trait$Leaf.N.sd <- NA data.trait$Seed.mass.mean <- data.trait$SEED_DRY*1000 data.trait$SEED_DRY <- NULL data.trait$Seed.mass.sd <- NA data.trait$SLA.mean <- 1/data.trait$LMALAM_AVD data.trait$SLA.mean <- data.trait$SLA.mean*1000 ## Conversion from g m^-2 to mm2 mg^-1 data.trait$SLA.sd <- 1/data.trait$LMALAM_SED data.trait$SLA.sd <- data.trait$SLA.sd*1000 ## Conversion from g m^-2 to mm2 mg^-1 data.trait$SLA.sd <- data.trait$SLA.sd*sqrt(data.trait$LMALAM_ND) ## conversion of SEM in SD data.trait$LMALAM_AVD <- data.trait$LMALAM_SED <- data.trait$LMALAM_ND <- NULL data.trait$Wood.density.mean <- data.trait$SG100C_AVG; data.trait$Wood.density.sd <- data.trait$SG100C_SEM*sqrt(data.trait$SG100C_N) ## conversion of SEM in SD data.trait$SG100C_AVG <- data.trait$SG100C_N <- data.trait$SG100C_SEM <- NULL data.trait$Max.height.mean <- (data.trait$HEIGHT_AVG) data.trait$Max.height.sd <- (data.trait$HEIGHT_SEM*sqrt(data.trait$HEIGHT_N)) data.trait$HEIGHT_SEM <- data.trait$HEIGHT_N <- data.trait$HEIGHT_AVG <- NULL data.trait$Latin_name <- sub("_"," ",data.trait$Latin) data.trait$GENUS. <- NULL data.trait$Latin <- NULL data.TRAITS.std <- data.trait rm(data.trait) ## extract data.traits <- fun.extract.format.sp.traits.NOT.TRY(sp=species.clean$Latin_name, Latin_name=species.clean$Latin_name, data=data.TRAITS.std,name.match.traits="Latin_name") ## change sp data.traits$sp <- species.clean$sp ### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING write.csv(data.traits,file="output/formatted/BCI/traits.csv",row.names = FALSE)