Commit 1bffcab2 authored by Georges Kunstler's avatar Georges Kunstler
Browse files

add leaftype

parent 3a5a957d
......@@ -27,9 +27,3 @@ names(out) <- lapply(lapply(files,files.details.all),
### remove missing
out <- out[!unlist(lapply(out,FUN=function(x) is.null(x$lmer.summary)))]
saveRDS(out,file='output/list.lmer.out.nolog.all.rds')
names.param <- unique(unlist(lapply(out,function(list.res)
names(list.res$lmer.summary$fixed.coeff.E))))
DF.results <- do.call("rbind",lapply(out, fun.format.in.data.frame,
names.param = names.param))
DF.results$id <- paste(DF.results$set, DF.results$ecocode, sep=".")
saveRDS(DF.results,file='output/DF.lmer.nolog.all.rds')
......@@ -98,7 +98,12 @@ data.cat.extract$deciduous[data.cat.extract$deciduous %in% c('E') &
data.cat.extract$Pheno.T[!is.na(data.cat.extract$deciduous)] <-
data.cat.extract$deciduous[!is.na(data.cat.extract$deciduous)]
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## fix pheno for species with issue
data.traits[data.traits$Latin_name %in% c('Vasconcellea cauliflora'),
'Phylo.group'] <- 'Angiosperm'
......
......@@ -54,7 +54,7 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Betula spp.','Crataegus spp
'Tilia spp.','Ulmus spp.'),'Pheno.T'] <- 'D'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
###
write.csv(data.traits,file="output/formatted/Canada/traits.csv",row.names = FALSE)
......
......@@ -64,7 +64,7 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Pinus nigra spp. salzmannii
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
###
write.csv(data.traits,file="output/formatted/France/traits.csv",row.names = FALSE)
......
......@@ -14,7 +14,7 @@ species.clean <- data.frame(sp=data.tree[!duplicated(data.tree[["sp"]]),"sp"],
################ MASSAGE TRAIT DATA Obtain maximum height per species from data.trait no sd
################ available as we have only one observation for species
data.trait <- read.table("data/raw/Fushan/fs_trait_Kunstler.txt", header = T,
sep = "\t")
sep = "\t",stringsAsFactors = F)
colnames(data.trait) <- c("sp", "sla", "wd", "seedmassmg", "meanN", "maxheightm")
data.trait <- merge(data.trait, data.frame(sp = species.clean$sp, Latin_name= species.clean$Latin_name,
stringsAsFactors = F), by = "sp")
......@@ -61,7 +61,7 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Machilus zuihoensis',
'Symplocos sonoharae','Cyclobalanopsis sessilifolia',
'Eriobotrya deflexa','Neolitsea konishii'),"Pheno.T"] <- 'EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
......
......@@ -58,7 +58,13 @@ data.cat.extract <- fun.change.factor.angio.try(data.cat.extract)
data.cat.extract <- fun.fill.pheno.try.with.zanne(data.cat.extract)
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## fix pheno for species with issue
data.traits[data.traits$Latin_name %in% c('Benthamidia japonica','Tutcheria virgata'),
'Phylo.group'] <- 'Angiosperm'
### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING
write.csv(data.traits,file="output/formatted/Japan/traits.csv",row.names = FALSE)
......
......@@ -97,7 +97,13 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Cecropia schreberiana',
data.cat.extract[data.cat.extract$Latin_name %in% c('Chione venosa') ,'Pheno.T']<- 'D_EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## fix pheno for species with issue
data.traits[data.traits$Latin_name %in% c('Beilschmedia pendula'),
'Phylo.group'] <- 'Angiosperm'
###
write.csv(data.traits,file="output/formatted/Luquillo/traits.csv",row.names = FALSE)
......
......@@ -254,7 +254,7 @@ data.cat.extract <- fun.change.factor.angio.try(data.cat.extract)
data.cat.extract <- fun.fill.pheno.try.with.zanne(data.cat.extract)
data.traits <- merge(data.traits,
data.cat.extract[,c("sp","Phylo.group","Pheno.T")],
data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],
by="sp")
#=============================================================
......
......@@ -49,7 +49,13 @@ data.cat.extract <- fun.change.factor.angio.try(data.cat.extract)
data.cat.extract <- fun.fill.pheno.try.with.zanne(data.cat.extract)
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## fix pheno for species with issue
data.traits[data.traits$Latin_name %in% c('Cyclophylum longipetalum'),
'Phylo.group'] <- 'Angiosperm'
### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING
......
......@@ -72,7 +72,7 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Aristotelia serrata',
'Fuchsia procumbens','Muehlenbeckia australis','Muehlenbeckia complexa',
'Olearia fimbriata','Urtica ferox'),'Pheno.T'] <- 'D_EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
### TODO ADD GENUS MEAN FOR HEIGHT IF SPECIES IS MISSING
write.csv(data.traits,file="output/formatted/NVS/traits.csv",row.names = FALSE)
......@@ -344,6 +344,10 @@ data.traits2 <- fun.extract.format.sp.traits.TRY(sp=species.clean2[["sp"]],
sp.syno.table=species.clean2,
data=data.TRY.std)
# for familly
species.clean3 <- species.clean[paste('sp',species.clean$sp,sep='.') %in% species.clean2$sp,]
## TODO NEED TO COMBINE BOTH
data.traits <- fun.combine.nontry.and.try(
trait = c('Leaf.N', 'SLA', 'Seed.mass',
......@@ -371,7 +375,8 @@ data.cat.extract <- fun.fill.pheno.try.with.zanne(data.cat.extract)
data.traits <- merge(data.traits,data.cat.extract[, c("sp",
"Phylo.group",
"Pheno.T")],
"Pheno.T",
'LeafType.T')],
by="sp")
......@@ -394,7 +399,15 @@ data.traits$Pheno.T2 <- NULL
## compute perc of traits cover per species
print(sapply(c('Leaf.N','SLA','Seed.mass','Wood.density','Max.height'),
fun.compute.perc.cover.one.trait,data.traits))
## Fix missing angio
Taxo.Zanne <- read.csv("data/raw/ZanneNature/Spermatophyta_Genera.csv",
stringsAsFactors=FALSE)
data.traits$Phylo.group[is.na(data.traits$Phylo.group)][
species.clean3$Famille[is.na(data.traits$Phylo.group)] %in%
Taxo.Zanne[Taxo.Zanne$Angiospermae=='Angiospermae','family']] <- 'Angiosperm'
# write.table(data.genus,file="data.genus.txt",sep="\t",row.names=FALSE)
write.csv(data.traits,file="./output/formatted/Paracou/traits.csv",
row.names=FALSE)
......
......@@ -62,7 +62,20 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Juniperus turbinata',
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group",
"Pheno.T",'LeafType.T')],
by="sp")
## fill missing phylo missing value
data.traits[data.traits$Latin_name %in% c('Otros pinos'),
'Phylo.group'] <- 'Gymnosperm'
data.traits[data.traits$Latin_name %in% c('Otros eucaliptos',
'Otros arboles ripicolas',
'Otras laurisilvas',
'Otras frondosas'),
'Phylo.group'] <- 'Angiosperm'
# write
write.csv(data.traits,file="output/formatted/Spain/traits.csv",row.names = FALSE)
......
......@@ -102,7 +102,16 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Abies ssp',
'Picea ssp other than P.abies') ,'Pheno.T']<- 'EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## fill missing phylo missing value
data.traits[data.traits$Latin_name %in% c('Conifers other than pinus; larix; picea and abies'),
'Phylo.group'] <- 'Gymnosperm'
data.traits[data.traits$Latin_name %in% c('Other broadleaved'),
'Phylo.group'] <- 'Angiosperm'
### writing
write.csv(data.traits,file="output/formatted/Sweden/traits.csv",row.names = FALSE)
......
......@@ -92,7 +92,7 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Abies spec.',
'Picea spec.','Thuja spec.','Sequoiadendron') ,'Pheno.T']<- 'EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
### write
......
......@@ -6,8 +6,10 @@ source("R/find.trait/trait-fun.R")
### read species names
data.tree <- read.csv("output/formatted/US/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"],
Latin_name=data.tree[!duplicated(data.tree[["sp"]])
,"sp.name"],
Latin_name_syn=data.tree[
!duplicated(data.tree[["sp"]]),"sp.name"],
stringsAsFactors =FALSE)
rm(data.tree)
......@@ -82,10 +84,20 @@ data.cat.extract[data.cat.extract$Latin_name %in% c('Abies spp.','Tsuga spp.','M
'Cecropia schreberiana','Cestrum laurifolium',
'Cupania triquetra','Coffea liberica','Myrsine cubana',
' Petitia domingensis','Prunus occidentalis',
'Quercus hypoleucoides','Senna siamea') ,'Pheno.T']<- 'EV'
'Quercus hypoleucoides','Senna siamea') ,
'Pheno.T']<- 'EV'
data.cat.extract[data.cat.extract$Latin_name %in% c('Annona reticulata',
'Cinnamomum elongatum') ,'Pheno.T']<- 'D_EV'
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
'Cinnamomum elongatum') ,
'Pheno.T']<- 'D_EV'
data.traits <- merge(data.traits,
data.cat.extract[,c("sp","Phylo.group",
"Pheno.T",'LeafType.T')],by="sp")
## fix pheno for species with issue
data.traits[data.traits$Latin_name %in% c('Family Arecaceae not listed above',
'Poitea florida'),
'Phylo.group'] <- 'Angiosperm'
# Write
write.csv(data.traits,file="output/formatted/US/traits.csv",row.names = FALSE)
......
......@@ -101,3 +101,18 @@ fun.test.set <- function(set,filedir) {
cat(set,"OK \n")
return(data.frame(set=rep(set,nrow(get.traits)),get.traits))
}
fun.ellipsoid.hull <- function(set,x,y,sets.v,col.vec){
require(cluster)
xy <- cbind((x[sets.v==set]),(y[sets.v==set]))
xy <- xy[!is.na(xy[,1]) & !is.na(xy[,2]),]
xy <- xy[xy[,1]>quantile(xy[,1],0.1) &xy[,1]<quantile(xy[,1],0.9) &
xy[,2]>quantile(xy[,2],0.1) &xy[,2]<quantile(xy[,2],0.9),]
if (nrow(xy)>10){
exy <- ellipsoidhull(xy)
lines(predict(exy),col=col.vec[set])
}
}
......@@ -15,23 +15,10 @@ all.traits <- do.call("rbind",aa)
trait.name <- c("Leaf.N.mean","SLA.mean","Wood.density.mean","Max.height.mean")
fun.ellipsoid.hull <- function(set,x,y,sets.v,col.vec){
require(cluster)
xy <- cbind((x[sets.v==set]),(y[sets.v==set]))
xy <- xy[!is.na(xy[,1]) & !is.na(xy[,2]),]
xy <- xy[xy[,1]>quantile(xy[,1],0.1) &xy[,1]<quantile(xy[,1],0.9) &
xy[,2]>quantile(xy[,2],0.1) &xy[,2]<quantile(xy[,2],0.9),]
if (nrow(xy)>10){
exy <- ellipsoidhull(xy)
lines(predict(exy),col=col.vec[set])
}
}
pdf("figs/test.traits/traits.XY.pdf",height=9,width=6)
pdf("figs/test.traits/traits.XY.set.pdf",height=9,width=6)
t.min <- c(2,1,0.1,1)
t.max <- c(60,100,1.5,100)
par(mfrow=c(3,2))
......@@ -42,16 +29,97 @@ par(mfrow=c(3,2))
xlab=trait.name[i],ylab=trait.name[j],
log="xy",xlim=c(t.min[i],t.max[i]),ylim=c(t.min[j],t.max[j]),
cex=0.2)
lapply(sets,fun.ellipsoid.hull,
all.traits[[trait.name[i]]] ,
all.traits[[trait.name[j]]],
all.traits[['set']],col.vec=col.vec)
## lapply(sets,fun.ellipsoid.hull,
## all.traits[[trait.name[i]]] ,
## all.traits[[trait.name[j]]],
## all.traits[['set']],col.vec=col.vec)
}
}
legend("topright", legend = sets, bty = "n", col = col.vec[sets],pch=pch.vec[sets], cex = 0.7)
dev.off()
pdf("figs/test.traits/traits.XY.angio.pdf",height=9,width=6)
t.min <- c(2,1,0.1,1)
t.max <- c(60,100,1.5,100)
par(mfrow=c(3,2))
for (i in 1:3) {
for (j in (i+1):4) {
plot(all.traits[[trait.name[i]]] ,all.traits[[trait.name[j]]],
col=c('black','red')[unclass(factor(all.traits$Phylo.group=='Angiosperm'))],
xlab=trait.name[i],ylab=trait.name[j],
log="xy",xlim=c(t.min[i],t.max[i]),ylim=c(t.min[j],t.max[j]),
cex=0.2)
}
}
legend("topright", legend = unique(factor(na.exclude(all.traits$Phylo.group)=='Angiosperm')), bty = "n",
col =c('black','red')[unique(unclass(factor(na.exclude(all.traits$Phylo.group)=='Angiosperm')))],
pch=1,cex = 0.7)
dev.off()
pdf("figs/test.traits/traits.XY.EV.pdf",height=9,width=6)
t.min <- c(2,1,0.1,1)
t.max <- c(60,100,1.5,100)
par(mfrow=c(3,2))
for (i in 1:3) {
for (j in (i+1):4) {
plot(all.traits[[trait.name[i]]] ,all.traits[[trait.name[j]]],
col=c('black','red')[unclass(factor(all.traits$Pheno.T=='EV'))],
xlab=trait.name[i],ylab=trait.name[j],
log="xy",xlim=c(t.min[i],t.max[i]),ylim=c(t.min[j],t.max[j]),
cex=0.2)
}
}
legend("topright", legend = unique(factor(na.exclude(all.traits$Pheno.T)=='EV')), bty = "n",
col =c('black','red')[unique(unclass(factor(na.exclude(all.traits$Pheno.T)=='EV')))],
pch=1,cex = 0.7)
dev.off()
## DIVIDE IN CONIF ANGIO_EV ANGIO_NOT_ EV ???
cat <- all.traits$Phylo.group
cat[cat=='Gymnosperm' & !is.na(cat)] <- "Gymno"
cat[all.traits$Phylo.group=='Angiosperm' & all.traits$Pheno.T == 'EV' &
!is.na(all.traits$Pheno.T ) & !is.na(all.traits$Phylo.group)] <- "Angio_EV"
cat[all.traits$Phylo.group=='Angiosperm' & all.traits$Pheno.T != 'EV' &
!is.na(all.traits$Pheno.T ) & !is.na(all.traits$Phylo.group)] <- "Angio_other"
cat[all.traits$Phylo.group=='Angiosperm' &
is.na(all.traits$Pheno.T ) & !is.na(all.traits$Phylo.group)] <- "Angio_unknown"
sum(is.na(cat))
pdf("figs/test.traits/traits.XY.cat.pdf",height=9,width=6)
t.min <- c(2,1,0.1,1)
t.max <- c(60,100,1.5,100)
par(mfrow=c(3,2))
for (i in 1:3) {
for (j in (i+1):4) {
plot(all.traits[[trait.name[i]]] ,all.traits[[trait.name[j]]],
col=unclass(factor(cat)),
xlab=trait.name[i],ylab=trait.name[j],
log="xy",xlim=c(t.min[i],t.max[i]),ylim=c(t.min[j],t.max[j]),
cex=0.2)
}
}
legend("bottomleft", legend = unique(na.exclude(cat)), bty = "n",
col =unique(unclass(factor(na.exclude(cat)))),
pch=1,cex = 0.7)
dev.off()
pdf("figs/test.traits/traits.boxplot.cat.pdf")
par(mfrow=c(2,2))
for (i in 1:4) {
boxplot(all.traits[[trait.name[i]]]~ cat,las=3)
}
dev.off()
par(mfrow=c(2,2))
for (i in 1:4) hist(log10(all.traits[[trait.name[i]]]),main=trait.name[i])
......
......@@ -324,7 +324,7 @@ fun.data.per.ecoregion <- function(ecoregion, data.tot, site.name,
data.merged <- fun.merged.DT(data,data.CWM,"obs.id")
cat('merge data and CWM done',"\n")
## add Phylo.group and Pheno.T to the data
data.merged <- merge(data.merged,data.TRAITS[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.merged <- merge(data.merged,data.TRAITS[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
## write data
if(std.traits=='local'){
write.csv(data.merged, file = file.path(path, "data.tree.tot.csv"), row.names = FALSE)
......@@ -382,7 +382,7 @@ for (i in unique(data$ecocode)){
data.merged <- fun.remove.tree.in.buffer.cluster(data.merged)
cat("dim after buffer tree removed",dim(data.merged),'vs ',dim(data.t),"\n")
## add Phylo.group and Pheno.T to the data
data.merged <- merge(data.merged,data.TRAITS[,c("sp","Phylo.group","Pheno.T")],by="sp")
data.merged <- merge(data.merged,data.TRAITS[,c("sp","Phylo.group","Pheno.T",'LeafType.T')],by="sp")
if(std.traits=='local'){
write.csv(data.merged, file = file.path(path, "data.tree.tot.csv"), row.names = FALSE)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment