Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Kunstler Georges
traitcompet
Commits
87744325
Commit
87744325
authored
Feb 20, 2014
by
Georges Kunstler
Browse files
global format and functoin to remove growth outlier
parent
1d1c1227
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
87744325
...
@@ -27,7 +27,7 @@ $(D2)/TRY/data.TRY.std.rds:
...
@@ -27,7 +27,7 @@ $(D2)/TRY/data.TRY.std.rds:
BCI
:
$(D3)/BCI/Done.txt
BCI
:
$(D3)/BCI/Done.txt
$(D3)/BCI/Done.txt
:
R/process.data/process-fun.R $(D2)/BCI/traits.csv
$(D3)/BCI/Done.txt
:
R/process.data/process-fun.R $(D2)/BCI/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('BCI', Rlim=15,std.traits='local'); process_bigplot_dataset('BCI', Rlim=15,std.traits='
no
'); process_bigplot_dataset('BCI', Rlim=15,std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_bigplot_dataset('BCI', Rlim=15,std.traits='local'); process_bigplot_dataset('BCI', Rlim=15,std.traits='
global
'); process_bigplot_dataset('BCI', Rlim=15,std.traits='
no
');"
$(D2)/BCI/traits.csv
:
R/find.trait/BCI.R R/find.trait/trait-fun.R $(D2)/BCI/tree.csv
$(D2)/BCI/traits.csv
:
R/find.trait/BCI.R R/find.trait/trait-fun.R $(D2)/BCI/tree.csv
Rscript
$<
Rscript
$<
...
@@ -40,7 +40,7 @@ $(D2)/BCI/tree.csv: R/format.data/BCI.R $(shell find $(D1)/BCI -type f)
...
@@ -40,7 +40,7 @@ $(D2)/BCI/tree.csv: R/format.data/BCI.R $(shell find $(D1)/BCI -type f)
Japan
:
$(D3)/Japan/Done.txt
Japan
:
$(D3)/Japan/Done.txt
$(D3)/Japan/Done.txt
:
R/process.data/process-fun.R $(D2)/Japan/traits.csv
$(D3)/Japan/Done.txt
:
R/process.data/process-fun.R $(D2)/Japan/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Japan', Rlim=15,std.traits='local'); process_bigplot_dataset('Japan', Rlim=15,std.traits='
no
'); process_bigplot_dataset('Japan', Rlim=15,std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Japan', Rlim=15,std.traits='local'); process_bigplot_dataset('Japan', Rlim=15,std.traits='
global
'); process_bigplot_dataset('Japan', Rlim=15,std.traits='
no
');"
$(D2)/Japan/traits.csv
:
R/find.trait/Japan.R R/find.trait/trait-fun.R $(D2)/Japan/tree.csv
$(D2)/Japan/traits.csv
:
R/find.trait/Japan.R R/find.trait/trait-fun.R $(D2)/Japan/tree.csv
Rscript
$<
Rscript
$<
...
@@ -65,7 +65,7 @@ $(D2)/Luquillo/tree.csv: R/format.data/Luquillo.R $(shell find $(D1)/Luquillo -t
...
@@ -65,7 +65,7 @@ $(D2)/Luquillo/tree.csv: R/format.data/Luquillo.R $(shell find $(D1)/Luquillo -t
Mbaiki
:
$(D3)/Mbaiki/Done.txt
Mbaiki
:
$(D3)/Mbaiki/Done.txt
$(D3)/Mbaiki/Done.txt
:
R/process.data/process-fun.R $(D2)/Mbaiki/traits.csv
$(D3)/Mbaiki/Done.txt
:
R/process.data/process-fun.R $(D2)/Mbaiki/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='local'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='
no
'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='local'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='
global
'); process_bigplot_dataset('Mbaiki', Rlim=15,std.traits='
no
');"
$(D2)/Mbaiki/traits.csv
:
R/find.trait/Mbaiki.R R/find.trait/trait-fun.R $(D2)/Mbaiki/tree.csv
$(D2)/Mbaiki/traits.csv
:
R/find.trait/Mbaiki.R R/find.trait/trait-fun.R $(D2)/Mbaiki/tree.csv
Rscript
$<
Rscript
$<
...
@@ -90,7 +90,7 @@ $(D2)/Canada/tree.csv: R/format.data/Canada.R $(shell find $(D1)/Canada -type f)
...
@@ -90,7 +90,7 @@ $(D2)/Canada/tree.csv: R/format.data/Canada.R $(shell find $(D1)/Canada -type f)
France
:
$(D3)/France/Done.txt
France
:
$(D3)/France/Done.txt
$(D3)/France/Done.txt
:
R/process.data/process-fun.R $(D2)/France/traits.csv
$(D3)/France/Done.txt
:
R/process.data/process-fun.R $(D2)/France/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('France',std.traits='local'); process_inventory_dataset('France',std.traits='
no
');process_inventory_dataset('France',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('France',std.traits='local'); process_inventory_dataset('France',std.traits='
global
');process_inventory_dataset('France',std.traits='
no
');"
$(D2)/France/traits.csv
:
R/find.trait/France.R R/find.trait/trait-fun.R $(D2)/France/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/France/traits.csv
:
R/find.trait/France.R R/find.trait/trait-fun.R $(D2)/France/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
@@ -103,7 +103,7 @@ $(D2)/France/tree.csv: R/format.data/France.R $(shell find $(D1)/France -type f)
...
@@ -103,7 +103,7 @@ $(D2)/France/tree.csv: R/format.data/France.R $(shell find $(D1)/France -type f)
Fushan
:
$(D3)/Fushan/Done.txt
Fushan
:
$(D3)/Fushan/Done.txt
$(D3)/Fushan/Done.txt
:
R/process.data/process-fun.R $(D2)/Fushan/traits.csv
$(D3)/Fushan/Done.txt
:
R/process.data/process-fun.R $(D2)/Fushan/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='local'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='
no
');process_bigplot_dataset('Fushan', Rlim=15,std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='local'); process_bigplot_dataset('Fushan', Rlim=15,std.traits='
global
');process_bigplot_dataset('Fushan', Rlim=15,std.traits='
no
');"
$(D2)/Fushan/traits.csv
:
R/find.trait/Fushan.R R/find.trait/trait-fun.R $(D2)/Fushan/tree.csv
$(D2)/Fushan/traits.csv
:
R/find.trait/Fushan.R R/find.trait/trait-fun.R $(D2)/Fushan/tree.csv
...
@@ -117,7 +117,7 @@ $(D2)/Fushan/tree.csv: R/format.data/Fushan.R $(shell find $(D1)/Fushan -type f)
...
@@ -117,7 +117,7 @@ $(D2)/Fushan/tree.csv: R/format.data/Fushan.R $(shell find $(D1)/Fushan -type f)
NSW
:
$(D3)/NSW/Done.txt
NSW
:
$(D3)/NSW/Done.txt
$(D3)/NSW/Done.txt
:
R/process.data/process-fun.R $(D2)/NSW/traits.csv
$(D3)/NSW/Done.txt
:
R/process.data/process-fun.R $(D2)/NSW/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('NSW',std.traits='local'); process_inventory_dataset('NSW',std.traits='
no
');process_inventory_dataset('NSW',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('NSW',std.traits='local'); process_inventory_dataset('NSW',std.traits='
global
');process_inventory_dataset('NSW',std.traits='
no
');"
$(D2)/NSW/traits.csv
:
R/find.trait/NSW.R R/find.trait/trait-fun.R $(D2)/NSW/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/NSW/traits.csv
:
R/find.trait/NSW.R R/find.trait/trait-fun.R $(D2)/NSW/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
@@ -130,7 +130,7 @@ $(D2)/NSW/tree.csv: R/format.data/NSW.R $(shell find $(D1)/NSW -type f)
...
@@ -130,7 +130,7 @@ $(D2)/NSW/tree.csv: R/format.data/NSW.R $(shell find $(D1)/NSW -type f)
NVS
:
$(D3)/NVS/Done.txt
NVS
:
$(D3)/NVS/Done.txt
$(D3)/NVS/Done.txt
:
R/process.data/process-fun.R $(D2)/NVS/traits.csv
$(D3)/NVS/Done.txt
:
R/process.data/process-fun.R $(D2)/NVS/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('NVS',std.traits='local'); process_inventory_dataset('NVS',std.traits='
no
'); process_inventory_dataset('NVS',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('NVS',std.traits='local'); process_inventory_dataset('NVS',std.traits='
global
'); process_inventory_dataset('NVS',std.traits='
no
');"
$(D2)/NVS/traits.csv
:
R/find.trait/NVS.R R/find.trait/trait-fun.R $(D2)/NVS/tree.csv
$(D2)/NVS/traits.csv
:
R/find.trait/NVS.R R/find.trait/trait-fun.R $(D2)/NVS/tree.csv
Rscript
$<
Rscript
$<
...
@@ -143,7 +143,7 @@ $(D2)/NVS/tree.csv: R/format.data/NVS.R $(shell find $(D1)/NVS -type f)
...
@@ -143,7 +143,7 @@ $(D2)/NVS/tree.csv: R/format.data/NVS.R $(shell find $(D1)/NVS -type f)
Paracou
:
$(D3)/Paracou/Done.txt
Paracou
:
$(D3)/Paracou/Done.txt
$(D3)/Paracou/Done.txt
:
R/process.data/process-fun.R $(D2)/Paracou/traits.csv
$(D3)/Paracou/Done.txt
:
R/process.data/process-fun.R $(D2)/Paracou/traits.csv
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='local'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='
no
'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='local'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='
global
'); process_bigplot_dataset('Paracou', Rlim=15,std.traits='
no
');"
$(D2)/Paracou/traits.csv
:
R/find.trait/Paracou.R R/find.trait/trait-fun.R $(D2)/Paracou/tree.csv
$(D2)/Paracou/traits.csv
:
R/find.trait/Paracou.R R/find.trait/trait-fun.R $(D2)/Paracou/tree.csv
Rscript
$<
Rscript
$<
...
@@ -156,7 +156,7 @@ $(D2)/Paracou/tree.csv: R/format.data/Paracou.R $(shell find $(D1)/Paracou -type
...
@@ -156,7 +156,7 @@ $(D2)/Paracou/tree.csv: R/format.data/Paracou.R $(shell find $(D1)/Paracou -type
Spain
:
$(D3)/Spain/Done.txt
Spain
:
$(D3)/Spain/Done.txt
$(D3)/Spain/Done.txt
:
R/process.data/process-fun.R $(D2)/Spain/traits.csv
$(D3)/Spain/Done.txt
:
R/process.data/process-fun.R $(D2)/Spain/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Spain',std.traits='local'); process_inventory_dataset('Spain',std.traits='
no
'); process_inventory_dataset('Spain',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('Spain',std.traits='local'); process_inventory_dataset('Spain',std.traits='
global
'); process_inventory_dataset('Spain',std.traits='
no
');"
$(D2)/Spain/traits.csv
:
R/find.trait/Spain.R R/find.trait/trait-fun.R $(D2)/Spain/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Spain/traits.csv
:
R/find.trait/Spain.R R/find.trait/trait-fun.R $(D2)/Spain/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
@@ -169,7 +169,7 @@ $(D2)/Spain/tree.csv: R/format.data/Spain.R $(shell find $(D1)/Spain -type f)
...
@@ -169,7 +169,7 @@ $(D2)/Spain/tree.csv: R/format.data/Spain.R $(shell find $(D1)/Spain -type f)
Sweden
:
$(D3)/Sweden/Done.txt
Sweden
:
$(D3)/Sweden/Done.txt
$(D3)/Sweden/Done.txt
:
R/process.data/process-fun.R $(D2)/Sweden/traits.csv
$(D3)/Sweden/Done.txt
:
R/process.data/process-fun.R $(D2)/Sweden/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Sweden',std.traits='local'); process_inventory_dataset('Sweden',std.traits='
no
'); process_inventory_dataset('Sweden',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('Sweden',std.traits='local'); process_inventory_dataset('Sweden',std.traits='
global
'); process_inventory_dataset('Sweden',std.traits='
no
');"
$(D2)/Sweden/traits.csv
:
R/find.trait/Sweden.R R/find.trait/trait-fun.R $(D2)/Sweden/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Sweden/traits.csv
:
R/find.trait/Sweden.R R/find.trait/trait-fun.R $(D2)/Sweden/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
@@ -182,7 +182,7 @@ $(D2)/Sweden/tree.csv: R/format.data/Sweden.R $(shell find $(D1)/Sweden -type f)
...
@@ -182,7 +182,7 @@ $(D2)/Sweden/tree.csv: R/format.data/Sweden.R $(shell find $(D1)/Sweden -type f)
Swiss
:
$(D3)/Swiss/Done.txt
Swiss
:
$(D3)/Swiss/Done.txt
$(D3)/Swiss/Done.txt
:
R/process.data/process-fun.R $(D2)/Swiss/traits.csv
$(D3)/Swiss/Done.txt
:
R/process.data/process-fun.R $(D2)/Swiss/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('Swiss',std.traits='local'); process_inventory_dataset('Swiss',std.traits='
no
'); process_inventory_dataset('Swiss',std.traits='
global
');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('Swiss',std.traits='local'); process_inventory_dataset('Swiss',std.traits='
global
'); process_inventory_dataset('Swiss',std.traits='
no
');"
$(D2)/Swiss/traits.csv
:
R/find.trait/Swiss.R R/find.trait/trait-fun.R $(D2)/Swiss/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/Swiss/traits.csv
:
R/find.trait/Swiss.R R/find.trait/trait-fun.R $(D2)/Swiss/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
@@ -195,7 +195,7 @@ $(D2)/Swiss/tree.csv: R/format.data/Swiss.R $(shell find $(D1)/Swiss -type f)
...
@@ -195,7 +195,7 @@ $(D2)/Swiss/tree.csv: R/format.data/Swiss.R $(shell find $(D1)/Swiss -type f)
US
:
$(D3)/US/Done.txt
US
:
$(D3)/US/Done.txt
$(D3)/US/Done.txt
:
R/process.data/process-fun.R $(D2)/US/traits.csv
$(D3)/US/Done.txt
:
R/process.data/process-fun.R $(D2)/US/traits.csv
Rscript
-e
"source('
$<
'); process_inventory_dataset('US',std.traits='
g
lo
b
al'); process_inventory_dataset('US',std.traits='lo
c
al'); process_inventory_dataset('US',std.traits='no');"
Rscript
-e
"source('
$<
'); process_inventory_dataset('US',std.traits='lo
c
al'); process_inventory_dataset('US',std.traits='
g
lo
b
al'); process_inventory_dataset('US',std.traits='no');"
$(D2)/US/traits.csv
:
R/find.trait/US.R R/find.trait/trait-fun.R $(D2)/US/tree.csv $(D2)/TRY/data.TRY.std.rds
$(D2)/US/traits.csv
:
R/find.trait/US.R R/find.trait/trait-fun.R $(D2)/US/tree.csv $(D2)/TRY/data.TRY.std.rds
Rscript
$<
Rscript
$<
...
...
R/format.data/BCI.R
View file @
87744325
...
@@ -97,10 +97,12 @@ data.bci$y <- data.bci$gy; data.bci$gy <- NULL
...
@@ -97,10 +97,12 @@ data.bci$y <- data.bci$gy; data.bci$gy <- NULL
data.bci
$
G
<-
(
data.bci
$
DBH2
-
data.bci
$
DBH1
)
/
data.bci
$
year
## diameter growth in mm per year - BASED ON UNROUNDED YEARS
data.bci
$
G
<-
(
data.bci
$
DBH2
-
data.bci
$
DBH1
)
/
data.bci
$
year
## diameter growth in mm per year - BASED ON UNROUNDED YEARS
data.bci
$
BA.G
<-
(
pi
*
(
data.bci
$
DBH2
/
20
)
^
2
-
pi
*
(
data.bci
$
DBH1
/
20
)
^
2
)
/
data.bci
$
year
## BA growth in cm2/yr
data.bci
$
BA.G
<-
(
pi
*
(
data.bci
$
DBH2
/
20
)
^
2
-
pi
*
(
data.bci
$
DBH1
/
20
)
^
2
)
/
data.bci
$
year
## BA growth in cm2/yr
data.bci
$
G
[
data.bci
$
Status1
==
"missing"
|
data.bci
$
Status2
==
"missing"
]
<-
NA
data.bci
$
G
[
data.bci
$
Status1
==
"missing"
|
data.bci
$
Status2
==
"missing"
]
<-
NA
data.bci
$
G
[
abs
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)
>
0.005
&
!
is.na
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)]
<-
NA
data.bci
$
G
[
abs
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)
>
0.005
&
!
is.na
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)]
<-
NA
data.bci
$
G
[
data.bci
$
Codes2
%in%
c
(
'RF'
,
'RP'
,
'RT'
,
'R'
)]
<-
NA
data.bci
$
G
[
data.bci
$
Codes2
%in%
c
(
'RF'
,
'RP'
,
'RT'
,
'R'
)]
<-
NA
data.bci
$
BA.G
[
data.bci
$
Status1
==
"missing"
|
data.bci
$
Status2
==
"missing"
]
<-
NA
data.bci
$
BA.G
[
data.bci
$
Status1
==
"missing"
|
data.bci
$
Status2
==
"missing"
]
<-
NA
data.bci
$
BA.G
[
abs
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)
>
0.005
&
!
is.na
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)]
<-
NA
data.bci
$
BA.G
[
abs
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)
>
0.005
&
!
is.na
(
data.bci
$
HOM2
-
data.bci
$
HOM1
)]
<-
NA
data.bci
$
BA.G
[
data.bci
$
Codes2
%in%
c
(
'RF'
,
'RP'
,
'RT'
,
'R'
)]
<-
NA
data.bci
$
BA.G
[
data.bci
$
Codes2
%in%
c
(
'RF'
,
'RP'
,
'RT'
,
'R'
)]
<-
NA
data.bci
$
G
[
data.bci
$
Latin
%in%
sp.palm.fern
]
<-
NA
## remove fern and palm
data.bci
$
G
[
data.bci
$
Latin
%in%
sp.palm.fern
]
<-
NA
## remove fern and palm
data.bci
$
BA.G
[
data.bci
$
Latin
%in%
sp.palm.fern
]
<-
NA
## remove fern and palm
data.bci
$
BA.G
[
data.bci
$
Latin
%in%
sp.palm.fern
]
<-
NA
## remove fern and palm
...
@@ -113,10 +115,18 @@ data.bci$Latin <- NULL
...
@@ -113,10 +115,18 @@ data.bci$Latin <- NULL
data.bci
$
census
<-
data.bci
$
Census
data.bci
$
census
<-
data.bci
$
Census
data.bci
$
Census
<-
NULL
data.bci
$
Census
<-
NULL
## LIMIT TO TREES > 10CM dbh
## LIMIT TO TREES > 10CM dbh
data.bci
<-
subset
(
data.bci
,
subset
=
data.bci
[[
"D"
]]
>=
10
&
!
is.na
(
data.bci
[[
"D"
]]))
### select only tree above 10cm of dbh at census 1
data.bci
<-
subset
(
data.bci
,
subset
=
data.bci
[[
"D"
]]
>=
10
&
!
is.na
(
data.bci
[[
"D"
]]))
### select only tree above 10cm of dbh at census 1
## data.bci <- subset(data.bci,subset=data.bci[["census"]] %in% c(6,5)) ### select only census 6
## remove plot sherman
data.bci
<-
subset
(
data.bci
,
subset
=
data.bci
[[
"cluster"
]]
!=
'sherman'
)
## remove bci census 1 because too much error
data.bci
<-
subset
(
data.bci
,
subset
=!
(
data.bci
[[
"cluster"
]]
==
'bci'
&
data.bci
[[
"census"
]]
==
1
))
# rename census from 1
data.bci
[[
'census'
]][
data.bci
[[
'cluster'
]]
==
'bci'
]
<-
data.bci
[[
'census'
]][
data.bci
[[
'cluster'
]]
==
'bci'
]
-1
## read plots coordinates
## read plots coordinates
coord
<-
read.csv
(
'data/raw/BCI/Cndt_1ha_coordinates.csv'
,
header
=
TRUE
,
stringsAsFactors
=
FALSE
)
coord
<-
read.csv
(
'data/raw/BCI/Cndt_1ha_coordinates.csv'
,
header
=
TRUE
,
stringsAsFactors
=
FALSE
)
...
@@ -155,7 +165,8 @@ data.bci$MAP <- clim$MAP
...
@@ -155,7 +165,8 @@ data.bci$MAP <- clim$MAP
data.bci
[[
"ecocode"
]]
<-
"tropical"
data.bci
[[
"ecocode"
]]
<-
"tropical"
###################### PLOT SELECTION FOR THE ANALYSIS
###################### PLOT SELECTION FOR THE ANALYSIS
vec.basic.var
<-
c
(
"obs.id"
,
"tree.id"
,
"sp"
,
"sp.name"
,
"cluster"
,
"plot"
,
"ecocode"
,
"D"
,
"G"
,
"BA.G"
,
"dead"
,
vec.basic.var
<-
c
(
"obs.id"
,
"tree.id"
,
"sp"
,
"sp.name"
,
"cluster"
,
"plot"
,
"ecocode"
,
"D"
,
"G"
,
"BA.G"
,
"dead"
,
'Lon'
,
'Lat'
,
"x"
,
"y"
,
"census"
,
'MAT'
,
'MAP'
)
'Lon'
,
'Lat'
,
"x"
,
"y"
,
"census"
,
'MAT'
,
'MAP'
)
data.tree
<-
subset
(
data.bci
,
select
=
c
(
vec.basic.var
))
data.tree
<-
subset
(
data.bci
,
select
=
c
(
vec.basic.var
))
...
@@ -165,7 +176,6 @@ data.tree <- fun.convert.type.B(data.tree)
...
@@ -165,7 +176,6 @@ data.tree <- fun.convert.type.B(data.tree)
write.csv
(
data.tree
,
file
=
"output/formatted/BCI/tree.csv"
,
row.names
=
FALSE
)
write.csv
(
data.tree
,
file
=
"output/formatted/BCI/tree.csv"
,
row.names
=
FALSE
)
### write data plot with variables only at the plot level. I should delete them from the tree table but so far I keep them to not distroy later code
### write data plot with variables only at the plot level. I should delete them from the tree table but so far I keep them to not distroy later code
vec.basic.var.p
<-
c
(
"plot"
,
"cluster"
,
"Lon"
,
"Lat"
,
"ecocode"
,
"MAT"
,
"MAP"
)
vec.basic.var.p
<-
c
(
"plot"
,
"cluster"
,
"Lon"
,
"Lat"
,
"ecocode"
,
"MAT"
,
"MAP"
)
data.plot
<-
subset
(
data.tree
,
subset
=!
duplicated
(
data.tree
$
cluster
),
select
=
c
(
vec.basic.var.p
))
data.plot
<-
subset
(
data.tree
,
subset
=!
duplicated
(
data.tree
$
cluster
),
select
=
c
(
vec.basic.var.p
))
write.csv
(
data.plot
,
file
=
"output/formatted/BCI/plot.csv"
,
row.names
=
FALSE
)
write.csv
(
data.plot
,
file
=
"output/formatted/BCI/plot.csv"
,
row.names
=
FALSE
)
R/format.data/format-fun.R
View file @
87744325
...
@@ -122,3 +122,39 @@ symbols(x.t,y.t,circles=D.t ,main=plot.select,inches=inches,fg=fg,...)
...
@@ -122,3 +122,39 @@ symbols(x.t,y.t,circles=D.t ,main=plot.select,inches=inches,fg=fg,...)
}
}
##' .. remove too negative growth based on Condit R package with param fitted to BCI ..
##'
##' .. taken from trim.growth function in CTFS.R ..
##' @title trim.negative.growth
##' @param dbh1 in mm
##' @param dbh2 in mm
##' @param slope not to be changed
##' @param intercept
##' @param err.limit
##' @return a vector TRUE FALSE with FALSE outlier to be removed
##' @author Kunstler
trim.negative.growth
<-
function
(
dbh1
,
dbh2
,
slope
=
0.006214
,
intercept
=
.9036
,
err.limit
=
5
){
stdev.dbh1
<-
slope
*
dbh1
+
intercept
bad.grow
<-
which
(
dbh2
<=
(
dbh1
-
err.limit
*
stdev.dbh1
))
accept
<-
rep
(
TRUE
,
length
(
dbh1
))
accept
[
bad.grow
]
<-
FALSE
accept
[
is.na
(
dbh1
)
|
is.na
(
dbh2
)
|
dbh2
<=
0
|
dbh1
<=
0
]
<-
FALSE
return
(
accept
)
}
##' .. remove too high growth ..
##'
##' .. taken from trim.growth in Condit CTFS R package ..
##' @title trim.positive.growth
##' @param growth in mm
##' @param maxgrow in mm
##' @return TRUE FALSE vector with FALSE outlier
##' @author Kunstler
trim.positive.growth
<-
function
(
growth
,
maxgrow
=
75
){
bad.grow
<-
which
(
growth
>
maxgrow
)
accept
<-
rep
(
TRUE
,
length
(
growth
))
accept
[
bad.grow
]
<-
FALSE
accept
[
is.na
(
growth
)]
<-
FALSE
return
(
accept
)
}
R/process.data/test.tree.CWM-fun.R
View file @
87744325
####
####
############################
## function for test.tree.CWM
## function for test.tree.CWM
source
(
"R/utils/plot.R"
)
load.processed.data
<-
function
(
path
,
file.name
=
"data.tree.tot.csv"
){
load.processed.data
<-
function
(
path
,
file.name
=
"data.tree.tot.csv"
){
fname
<-
file.path
(
path
,
file.name
)
fname
<-
file.path
(
path
,
file.name
)
...
@@ -228,37 +230,7 @@ fun.test.value.one.ecoregion.B <- function(data.CWM,set,ecocode.select,path.form
...
@@ -228,37 +230,7 @@ fun.test.value.one.ecoregion.B <- function(data.CWM,set,ecocode.select,path.form
}
}
#### compute description of each table
## plot CWM
fun.hist.var
<-
function
(
var
,
set
,
data
){
hist
(
data
[[
var
]],
xlab
=
var
,
main
=
set
)
}
fun.plot.plot.CWM
<-
function
(
data.CWM
,
set
){
trait.name
<-
c
(
"Leaf.N"
,
"Seed.mass"
,
"SLA"
,
"Wood.density"
,
"Max.height"
)
name.var
<-
c
(
"focal"
,
"CWM.fill"
,
"abs.CWM.fill"
)
png
(
paste
(
"figs/test.processed/fig"
,
set
,
"BATOT.G.BA.B"
,
"png"
,
sep
=
"."
))
par
(
mfrow
=
c
(
1
,
2
))
plot
(
data.CWM
[[
"BATOT"
]],
data.CWM
[[
"G"
]],
xlab
=
"BATOT"
,
ylab
=
"G"
)
plot
(
data.CWM
[[
"BATOT"
]],
data.CWM
[[
"BA.G"
]],
xlab
=
"BATOT"
,
ylab
=
"BA.G"
)
dev.off
()
pdf
(
paste
(
"figs/test.processed/fig"
,
set
,
"CWM"
,
"pdf"
,
sep
=
"."
))
par
(
mfrow
=
c
(
5
,
3
))
for
(
i
in
trait.name
){
try
(
histt
<-
lapply
(
paste
(
i
,
name.var
,
sep
=
"."
),
fun.hist.var
,
set
,
data.CWM
))
}
dev.off
()
pdf
(
paste
(
"figs/test.processed/fig"
,
set
,
"perc"
,
"pdf"
,
sep
=
"."
))
par
(
mfrow
=
c
(
2
,
3
))
try
(
histt
<-
lapply
(
paste
(
trait.name
,
"perc.species"
,
sep
=
"."
),
fun.hist.var
,
set
,
data.CWM
))
dev.off
()
}
fun.perc.non.missing
<-
function
(
i
,
var.name
,
var.names.perc
,
data
){
fun.perc.non.missing
<-
function
(
i
,
var.name
,
var.names.perc
,
data
){
sel
<-
data
[[
var.names.perc
[
i
]]]
>
0.9
&
!
is.na
(
data
[[
var.names.perc
[
i
]]])
sel
<-
data
[[
var.names.perc
[
i
]]]
>
0.9
&
!
is.na
(
data
[[
var.names.perc
[
i
]]])
return
(
sum
(
!
is.na
((
data
[[
var.name
[
i
]]])[
sel
]))
/
length
(
data
[[
var.name
[
i
]]][
sel
]))
return
(
sum
(
!
is.na
((
data
[[
var.name
[
i
]]])[
sel
]))
/
length
(
data
[[
var.name
[
i
]]][
sel
]))
...
@@ -323,7 +295,6 @@ fun.test.set.tree.CWM.I <- function(set,filedir){
...
@@ -323,7 +295,6 @@ fun.test.set.tree.CWM.I <- function(set,filedir){
fun.test.set.ecocode.tree.CWM.I
(
data.temp
,
set
,
ecocode.select
)
fun.test.set.ecocode.tree.CWM.I
(
data.temp
,
set
,
ecocode.select
)
list.perc
[[
ecocode.select
]]
<-
fun.compute.percentage.species.genus
(
data.temp
)
list.perc
[[
ecocode.select
]]
<-
fun.compute.percentage.species.genus
(
data.temp
)
fun.test.range.vars.q
(
data.temp
,
paste
(
set
,
ecocode.select
))
fun.test.range.vars.q
(
data.temp
,
paste
(
set
,
ecocode.select
))
## fun.plot.plot.CWM (data.temp,paste(set,ecocode.select))
}
}
mat.perc
<-
do.call
(
"rbind"
,
list.perc
)
mat.perc
<-
do.call
(
"rbind"
,
list.perc
)
df.perc
<-
data.frame
(
set
=
rep
(
set
,
nrow
(
mat.perc
)),
ecocode
=
rownames
(
mat.perc
),
df.perc
<-
data.frame
(
set
=
rep
(
set
,
nrow
(
mat.perc
)),
ecocode
=
rownames
(
mat.perc
),
...
@@ -348,7 +319,6 @@ fun.test.set.tree.CWM.B <- function(set,filedir){
...
@@ -348,7 +319,6 @@ fun.test.set.tree.CWM.B <- function(set,filedir){
fun.test.set.ecocode.tree.CWM.B
(
data.temp
,
set
,
ecocode.select
)
fun.test.set.ecocode.tree.CWM.B
(
data.temp
,
set
,
ecocode.select
)
list.perc
[[
ecocode.select
]]
<-
fun.compute.percentage.species.genus
(
data.temp
)
list.perc
[[
ecocode.select
]]
<-
fun.compute.percentage.species.genus
(
data.temp
)
fun.test.range.vars.q
(
data.temp
,
paste
(
set
,
ecocode.select
))
fun.test.range.vars.q
(
data.temp
,
paste
(
set
,
ecocode.select
))
## fun.plot.plot.CWM (data.temp,paste(set,ecocode.select))
}
}
mat.perc
<-
do.call
(
"rbind"
,
list.perc
)
mat.perc
<-
do.call
(
"rbind"
,
list.perc
)
df.perc
<-
data.frame
(
set
=
rep
(
set
,
nrow
(
mat.perc
)),
ecocode
=
rownames
(
mat.perc
),
mat.perc
)
df.perc
<-
data.frame
(
set
=
rep
(
set
,
nrow
(
mat.perc
)),
ecocode
=
rownames
(
mat.perc
),
mat.perc
)
...
@@ -384,3 +354,99 @@ if (type=='I'){
...
@@ -384,3 +354,99 @@ if (type=='I'){
}
}
return
(
data.all
)
return
(
data.all
)
}
}
#### PLOT VAR PER SET
## plot hist of each var
fun.hist.var
<-
function
(
data
,
var
,
...
){
tryCatch
(
hist
(
data
[[
var
]],
xlab
=
var
,
main
=
unique
(
data
[[
'set'
]]),
...
),
warning
=
function
(
w
)
print
(
'warnings'
),
error
=
function
(
e
){
print
(
paste
(
unique
(
data
[[
'set'
]]),
'do not have value for'
,
var
));
plot
(
0
,
0
,
main
=
unique
(
data
[[
'set'
]]))})
}
fun.hist.var.set
<-
function
(
data
,
var
,
...
){
par
(
mfrow
=
c
(
5
,
3
),
mar
=
c
(
4.5
,
3.5
,
0.5
,
0.5
),
mgp
=
c
(
1.5
,
0.5
,
0
))
by
(
data
,
INDICES
=
data
[[
'set'
]],
FUN
=
fun.hist.var
,
var
=
var
,
xlim
=
range
(
data
[[
var
]],
na.rm
=
TRUE
),
...
)
}
fun.plot.xy
<-
function
(
data
,
var.x
,
var.y
,
...
){
tryCatch
(
plot
(
data
[[
var.x
]],
data
[[
var.y
]],
xlab
=
var.x
,
ylab
=
var.y
,
main
=
unique
(
data
[[
'set'
]]),
...
),
warning
=
function
(
w
)
print
(
'warnings'
),
error
=
function
(
e
){
print
(
paste
(
unique
(
data
[[
'set'
]]),
'do not have value for'
,
var.x
,
'or'
,
var.y
));
plot
(
0
,
0
,
main
=
unique
(
data
[[
'set'
]]))})
}
fun.plot.xy.set
<-
function
(
data
,
var.x
,
var.y
,
...
){
par
(
mfrow
=
c
(
5
,
3
),
mar
=
c
(
4.5
,
3.5
,
0.5
,
0.5
),
mgp
=
c
(
1.5
,
0.5
,
0
))
by
(
data
,
INDICES
=
data
[[
'set'
]],
FUN
=
fun.plot.xy
,
var.x
=
var.x
,
var.y
=
var.y
,
xlim
=
range
(
data
[[
var.x
]],
na.rm
=
TRUE
),
ylim
=
range
(
data
[[
var.y
]],
na.rm
=
TRUE
),
...
)
}
fun.plot.hist.trait.per.set
<-
function
(
data
){
trait.name
<-
c
(
"Leaf.N"
,
"Seed.mass"
,
"SLA"
,
"Wood.density"
,
"Max.height"
)
name.var
<-
c
(
"focal"
,
"CWM.fill"
,
"abs.CWM.fill"
)
for
(
i
in
name.var
){
for
(
t
in
trait.name
){
var.temp
<-
paste
(
t
,
i
,
sep
=
"."
)
to.pdf
(
fun.hist.var.set
(
data
,
var
=
var.temp
),
paste
(
"figs/test.processed/fig"
,
t
,
i
,
"pdf"
,
sep
=
"."
))
}
}
}
## remove growth outliers
##' .. remove too negative growth based on Condit R package with param fitted to BCI ..
##'
##' .. taken from trim.growth function in CTFS.R ..
##' @title trim.negative.growth
##' @param dbh1 in mm
##' @param dbh2 in mm
##' @param slope not to be changed
##' @param intercept
##' @param err.limit
##' @return a vector TRUE FALSE with FALSE outlier to be removed
##' @author Kunstler
trim.negative.growth
<-
function
(
dbh1
,
dbh2
,
slope
=
0.006214
,
intercept
=
.9036
,
err.limit
=
5
){
stdev.dbh1
<-
slope
*
dbh1
+
intercept
bad.grow
<-
which
(
dbh2
<=
(
dbh1
-
err.limit
*
stdev.dbh1
))
accept
<-
rep
(
TRUE
,
length
(
dbh1
))
accept
[
bad.grow
]
<-
FALSE
accept
[
is.na
(
dbh1
)
|
is.na
(
dbh2
)
|
dbh2
<=
0
|
dbh1
<=
0
]
<-
FALSE
return
(
accept
)
}
##' .. remove too high growth ..
##'
##' .. taken from trim.growth in Condit CTFS R package ..
##' @title trim.positive.growth
##' @param growth in mm
##' @param maxgrow in mm
##' @return TRUE FALSE vector with FALSE outlier
##' @author Kunstler
trim.positive.growth
<-
function
(
growth
,
maxgrow
=
75
){
bad.grow
<-
which
(
growth
>
maxgrow
)
accept
<-
rep
(
TRUE
,
length
(
growth
))
accept
[
bad.grow
]
<-
FALSE
accept
[
is.na
(
growth
)]
<-
FALSE
return
(
accept
)
}
#####
## function compute FD per plot
## TODO
fun.compute.sd.var.cluster
<-
function
(
data
,
var
){
cluster.unique.id
<-
paste
(
data
[[
'set'
],
data
[[
'ecocode'
]],
data
[[
'cluster'
]])
tapply
(
data
[[
var
]],
INDEX
=
cluster.unique.id
,
FUN
=
sd
,
na.rm
=
TRUE
)
}
R/process.data/test.tree.CWM.R
View file @
87744325
...
@@ -28,7 +28,7 @@ rm(data.all)
...
@@ -28,7 +28,7 @@ rm(data.all)
## test all set
## test all set
library
(
doParallel
)
library
(
doParallel
)
registerDoParallel
(
cores
=
5
)
registerDoParallel
(
cores
=
5
)
lmat.perc.I
<-
lapply
(
sets.I
,
fun.test.set.tree.CWM.I
,
filedir
=
filedir
)
lmat.perc.I
<-
mclapply
(
sets.I
,
fun.test.set.tree.CWM.I
,
filedir
=
filedir
,
mc.cores
=
getOption
(
"mc.cores"
,
5
))
lmat.perc.I
<-
mclapply
(
sets.I
,
fun.test.set.tree.CWM.I
,
filedir
=
filedir
,
mc.cores
=
getOption
(
"mc.cores"
,
5
))
mat.perc.I
<-
do.call
(
"rbind"
,
lmat.perc.I
)
mat.perc.I
<-
do.call
(
"rbind"
,
lmat.perc.I
)
...
@@ -37,23 +37,28 @@ mat.perc.B <- do.call("rbind",lmat.perc.B)
...
@@ -37,23 +37,28 @@ mat.perc.B <- do.call("rbind",lmat.perc.B)
mat.perc
<-
data.frame
(
rbind
(
mat.perc.I
,
mat.perc.B
),
stringsAsFactors
=
FALSE
)
mat.perc
<-
data.frame
(
rbind
(
mat.perc.I
,
mat.perc.B
),
stringsAsFactors
=
FALSE
)
mat.perc
<-
data.frame
(
lapply
(
mat.perc
,
function
(
x
)
(
unlist
(
x
))))
mat.perc
<-
data.frame
(
lapply
(
mat.perc
,
function
(
x
)
(
unlist
(
x
))))
write.csv
(
mat.perc
,
file
=
file.path
(
filedir
,
"all.sites.perc.traits.csv"
),
row.names
=
FALSE
)
write.csv
(
mat.perc
,
file
=
file.path
(
filedir
,
"all.sites.perc.traits.csv"
),
row.names
=
FALSE
)
## format table for report
## format table for report
mat.perc
<-
read.csv
(
file
=
file.path
(
filedir
,
"all.sites.perc.traits.csv"
))
## genus perc
## genus perc
mat.num.g
<-
mat.perc
[,
c
(
1
:
3
,
9
:
13
)]
mat.num.g
<-
mat.perc
[,
c
(
1
:
3
,
9
:
13
)]
mat.num.g
[,
4
:
8
]
<-
mat.perc
[,
9
:
13
]
/
mat.perc
[,
3
]
mat.num.g
[,
4
:
8
]
<-
mat.perc
[,
9
:
13
]
/
mat.perc
[,
3
]
names
(
mat.num.g
)
<-
c
(
'set'
,
'ecoregion'
,
'P obs total'
,
'P Leaf N'
,
'P Seed mass'
,
'P SLA'
,
'P Wood density'
,
'P Max height'
)
names
(
mat.num.g
)
<-
c
(
'set'
,
'ecoregion'
,
'P obs total'
,
'P Leaf N'
,
'P Seed mass'
,
'P SLA'
,
'P Wood density'
,
'P Max height'
)
library
(
'pander'
)
library
(
'pander'
)
pandoc.table
(
mat.num.g
,
caption
=
"Number of tree radial growth observation per data sets and ecoregion."
,
split.tables
=
'Inf'
)
pandoc.table
(
mat.num.g
,
caption
=
"Number of tree radial growth observation per data sets and ecoregion."
,
split.tables
=
'Inf'
)
## species perc
## species perc
mat.num.sp
<-
mat.perc
[,
c
(
1
:
8
)]
mat.num.sp
<-
mat.perc
[,
c
(
1
:
8
)]
mat.num.sp
[,
4
:
8
]
<-
mat.perc
[,
4
:
8
]
/
mat.perc
[,
3
]
mat.num.sp
[,
4
:
8
]
<-
mat.perc
[,
4
:
8
]
/
mat.perc
[,
3
]
pandoc.table
(
mat.num.sp
,
caption
=
"Number of tree radial growth observation per data sets and ecoregion."
,
split.tables
=
'Inf'
)
pandoc.table
(
mat.num.sp
,
caption
=
"Number of tree radial growth observation per data sets and ecoregion."
,
split.tables
=
'Inf'
)
### read all data
### read all data
...
@@ -61,6 +66,39 @@ data.all <- read.csv(file=file.path(filedir, "data.all.csv"))
...
@@ -61,6 +66,39 @@ data.all <- read.csv(file=file.path(filedir, "data.all.csv"))
if
(
dim
(
data.all
)[
1
]
!=
sum
(
mat.perc
[[
'num.obs'
]]))
stop
(
'error not same dimension per ecoregion and total'
)
if
(
dim
(
data.all
)[
1
]
!=
sum
(
mat.perc
[[
'num.obs'
]]))
stop
(
'error not same dimension per ecoregion and total'
)
data.all
[[
'G'
]][
!
(
trim.positive.growth
(
data.all
[[
'G'
]])
&
trim.negative.growth
(
dbh1
=
data.all
[[
'D'
]]
*
10
,
dbh2
=
data.all
[[
'D'
]]
*
10
+
data.all
[[
'year'
]]
*
data.all
[[
'G'
]]))]
<-
NA
data.all
[[
'BA.G'
]][
!
(
trim.positive.growth
(
data.all
[[
'G'
]])
&
trim.negative.growth
(
data.all
[[
'D'
]]
*
10
,
dbh2
=
data.all
[[
'D'
]]
*
10
+
data.all
[[
'year'
]]
*
data.all
[[
'G'
]]))]
<-
NA
## plot
fun.plot.hist.trait.per.set
(
data.all
)
to.pdf
(
fun.hist.var.set
(
data.all
,
var
=
'BATOT'
,
cex
=
0.6
),
filename
=
"figs/test.processed/fig.BATOT.set.pdf"
)
to.pdf
(
fun.hist.var.set
(
data.all
,
var
=
'G'
,
cex
=
0.6
),
filename
=
"figs/test.processed/fig.G.set.pdf"
)
to.pdf
(
fun.hist.var.set
(
data.all
,
var
=
'BA.G'
,
cex
=
0.6
),
filename
=
"figs/test.processed/fig.BA.G.set.pdf"
)
to.pdf
(
fun.hist.var.set
(
data.all
,
var
=
'D'
,
cex
=
0.6
),
filename
=
"figs/test.processed/fig.D.set.pdf"
)
to.dev
(
fun.plot.xy.set
(
data.all
,
var.x
=
'BATOT'
,
var.y
=
'BA.G'
,
cex
=
0.6
),
dev
=
png
,
filename
=
"figs/test.processed/fig.xy.BATOT.BA.G.set.png"
)
to.dev
(
fun.plot.xy.set
(
data.all
,
var.x
=
'D'
,
var.y
=
'BA.G'
,
cex
=
0.6
),
dev
=
png
,
filename
=
"figs/test.processed/fig.xy.D.BA.G.set.png"
)
to.dev
(
fun.plot.xy.set
(
data.all
,
var.x
=
'D'
,
var.y
=
'G'
,
cex
=
0.6
),
dev
=
png
,
filename
=
"figs/test.processed/fig.xy.D.G.set.png"
)
fun.plot.xy.trait.per.set
(
data.all
,
var.x
=
'BATOT'
,
var.y
=
'BA.G'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment