France.R 3.18 KB
Newer Older
Daniel Falster's avatar
Daniel Falster committed
1
2
#!/usr/bin/env Rscript

Georges Kunstler's avatar
Georges Kunstler committed
3
##### FORMAT TRAIT FOR France
4
5
source("R/find.trait/trait.fun.R")
source("R/format.data/format.fun.R")
Georges Kunstler's avatar
Georges Kunstler committed
6
7

### read species names
8
9
10



11
species.clean <- (read.csv("data/raw/France/species.csv", stringsAsFactors = FALSE))
Georges Kunstler's avatar
Georges Kunstler committed
12
13
14
species.clean$Latin_name <- (gsub("_", " ", species.clean$Latin_name))
species.clean$Latin_name_syn<- (gsub("_", " ", species.clean$Latin_name_syn))
species.clean <-  subset(species.clean,subset=!is.na(species.clean$Latin_name_syn))
Georges Kunstler's avatar
Georges Kunstler committed
15
species.clean$sp <- paste("sp",species.clean$code,sep=".")
Georges Kunstler's avatar
Georges Kunstler committed
16
species.clean$code <- NULL
17
18
19
## remove duplicated sp
species.clean <- species.clean[!duplicated(species.clean$sp),]

Georges Kunstler's avatar
Georges Kunstler committed
20
## read in data
21
data.TRY.std <- readRDS("output/formatted/TRY/data.TRY.std.rds")
Georges Kunstler's avatar
Georges Kunstler committed
22

23
max.height <- read.csv(file="output/formatted/France/max.height.csv", stringsAsFactors = FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
24
max.height$Max.height.genus <- FALSE
Georges Kunstler's avatar
Georges Kunstler committed
25
### extract and add height
26
27
28
data.traits <- fun.extract.format.sp.traits.TRY(sp=species.clean[["sp"]],
                                                sp.syno.table=species.clean,
                                                data=data.TRY.std)
Georges Kunstler's avatar
Georges Kunstler committed
29
30
31
data.traits <- merge(data.traits,
                     subset(max.height,select=c("sp","Max.height.mean","Max.height.sd","Max.height.genus")),
                     by="sp",all.x=TRUE,all.y=FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
32

33
34
height.genus.DF <- do.call("rbind",lapply(data.traits$Latin_name,
                                          fun.compute.mean.genus,data.traits,"Max.height.mean"))
Georges Kunstler's avatar
Georges Kunstler committed
35
data.traits[is.na(data.traits[["Max.height.mean"]]),
36
37
38
39
            c("Max.height.mean","Max.height.sd","Max.height.genus")] <-
            height.genus.DF[is.na(data.traits[["Max.height.mean"]]),]


40
#### GET THE ANGIO/CONIF AND EVERGREEN/DECIDUOUS
41
42
43
44
45
# read try categrocial data
try.cat <- read.csv("data/raw/TRY/TRY_Categorical_Traits_Lookup_Table_2012_03_17_TestRelease.csv",
         stringsAsFactors=FALSE,na.strings = "")
Pheno.Zanne <- read.csv("data/raw/ZanneNature/GlobalLeafPhenologyDatabase.csv",
         stringsAsFactors=FALSE)
46
# extract
47
48
data.cat.extract <- do.call("rbind",lapply(data.traits$sp ,fun.get.cat.var.from.try,
                                           data.traits,try.cat,Pheno.Zanne))
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# change category
data.cat.extract <- fun.change.factor.pheno.try(data.cat.extract)
data.cat.extract <- fun.change.factor.angio.try(data.cat.extract)
data.cat.extract <- fun.fill.pheno.try.with.zanne(data.cat.extract)

## fix pheno for species with issue
data.cat.extract[data.cat.extract$Latin_name %in% c('Populus sp','Tilia europaea',
                                                    'Prunus sp','Prunus dulcis',
                                                    'Sorbus latifolia','Pyrus spinosa',
                                                    'Sorbus semiincisa','Alnus alnobetula',
                                                    'Crataegus azarolus','Frangula dodonei',
                                                    'Tamarix africana'),'Pheno.T'] <- 'D'

data.cat.extract[data.cat.extract$Latin_name %in% c('Pinus nigra spp. salzmannii')
                 ,'Pheno.T']<-  'EV'
64
65
66



67
data.traits <- merge(data.traits,data.cat.extract[,c("sp","Phylo.group","Pheno.T")],by="sp")
Georges Kunstler's avatar
Georges Kunstler committed
68

69
### 
70
write.csv(data.traits,file="output/formatted/France/traits.csv",row.names = FALSE)
Georges Kunstler's avatar
Georges Kunstler committed
71