Revision cd4209e0
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation_functions.R | ||
---|---|---|
4 | 4 |
# interpolation code. |
5 | 5 |
#Figures and data for the contribution of covariate paper are also produced. |
6 | 6 |
#AUTHOR: Benoit Parmentier # |
7 |
#DATE: 05/21/2014
|
|
7 |
#DATE: 07/18/2014
|
|
8 | 8 |
#Version: 2 |
9 | 9 |
#PROJECT: Environmental Layers project # |
10 | 10 |
################################################################################################# |
... | ... | |
64 | 64 |
#This extract a data.frame object from raster prediction obj and combine them in one data.frame |
65 | 65 |
extract_from_list_obj<-function(obj_list,list_name){ |
66 | 66 |
#extract object from list of list. This useful for raster_prediction_obj |
67 |
#the output is a data.frame |
|
67 | 68 |
library(plyr) |
68 | 69 |
|
69 | 70 |
list_tmp<-vector("list",length(obj_list)) |
... | ... | |
71 | 72 |
tmp<-obj_list[[i]][[list_name]] #double bracket to return data.frame |
72 | 73 |
list_tmp[[i]]<- as.data.frame(tmp) #deal with spdf cases |
73 | 74 |
} |
75 |
|
|
74 | 76 |
tb_list_tmp<-do.call(rbind.fill,list_tmp) #long rownames |
75 | 77 |
#tb_list_tmp<-do.call(rbind,list_tmp) #long rownames |
76 | 78 |
|
77 | 79 |
return(tb_list_tmp) #this is a data.frame |
78 | 80 |
} |
79 | 81 |
|
82 |
add_rownames_list_df <-function(obj_list){ |
|
83 |
#extract object from list of list. This useful for raster_prediction_obj |
|
84 |
#rownames are loaded in a column called rownames |
|
85 |
#the output is a data.frame |
|
86 |
library(plyr) |
|
87 |
|
|
88 |
list_tmp<-vector("list",length(obj_list)) |
|
89 |
for (i in 1:length(obj_list)){ |
|
90 |
tmp <- obj_list[[i]] #double bracket to return data.frame |
|
91 |
rownames_char <- names(obj_list)[i] |
|
92 |
rownames_col <- rep(rownames_char,nrow(tmp)) |
|
93 |
tmp$rownames <- rownames_col |
|
94 |
list_tmp[[i]]<- as.data.frame(tmp) #deal with spdf cases |
|
95 |
} |
|
96 |
#tb_list_tmp<-do.call(rbind.fill,list_tmp) #long rownames |
|
97 |
#tb_list_tmp<-do.call(rbind,list_tmp) #long rownames |
|
98 |
return(list_tmp) #this is a data.frame |
|
99 |
} |
|
100 |
|
|
101 |
#df must have a specific format: "%Y%m%d |
|
102 |
add_month_tag<-function(tb,date_col){ |
|
103 |
date<-strptime(tb[[date_col]], "%Y%m%d") # interpolation date being processed |
|
104 |
month<-strftime(date, "%m") # current month of the date being processed |
|
105 |
} |
|
106 |
|
|
80 | 107 |
calc_stat_from_raster_prediction_obj <-function(raster_prediction_obj,stat,training=FALSE){ |
81 | 108 |
#Calculate statistics from validation and training out of raster_prediction_obj |
82 | 109 |
#If training is TRUE, then using training dataset |
Also available in: Unified diff
contributions of covariates and methods paper: slight changes to function script for LST analyses