Revision 68e7f033
Added by Benoit Parmentier over 10 years ago
climate/research/oregon/interpolation/contribution_of_covariates_paper_interpolation.R | ||
---|---|---|
4 | 4 |
#different covariates using two baselines. Accuracy methods are added in the the function script to evaluate results. |
5 | 5 |
#Figures, tables and data for the contribution of covariate paper are also produced in the script. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 |
#MODIFIED ON: 05/21/2014
|
|
7 |
#MODIFIED ON: 07/03/2014
|
|
8 | 8 |
#Version: 5 |
9 | 9 |
#PROJECT: Environmental Layers project |
10 | 10 |
################################################################################################# |
... | ... | |
65 | 65 |
met_stations_outfiles_obj_file<-"/data/project/layers/commons/data_workflow/output_data_365d_gam_fus_lst_test_run_07172013/met_stations_outfiles_obj_gam_fusion__365d_gam_fus_lst_test_run_07172013.RData" |
66 | 66 |
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84 |
67 | 67 |
y_var_name <- "dailyTmax" |
68 |
out_prefix<-"_05252014"
|
|
68 |
out_prefix<-"_07032014"
|
|
69 | 69 |
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_contribution_covar_analyses_tables_fig" |
70 | 70 |
setwd(out_dir) |
71 | 71 |
|
... | ... | |
1190 | 1190 |
#stat_loc<-readOGR(dsn=in_dir1,layer=sub(".shp","",basename(met_obj$loc_stations))) |
1191 | 1191 |
#dim(stat_loc) |
1192 | 1192 |
|
1193 |
############################ |
|
1194 |
#### Figure 9: variograms for 2 dates and model 1 ### |
|
1195 |
|
|
1196 |
#Make a function to extract and plot variogram models...one per day and model |
|
1197 |
#plot.gstatVariogram |
|
1198 |
#Plot a sample variogram, and possibly a fitted model |
|
1199 |
#model 1 lat,lon and elev |
|
1200 |
layout_m<-c(1,1) # works if set to this?? ok set the resolution... |
|
1201 |
|
|
1202 |
date_selected <- c("20100101","20100901") |
|
1203 |
png(paste("Figure9_paper_","_variogram_",date_selected[1],"_",date_selected[2],"_",out_prefix,".png", sep=""), |
|
1204 |
height=960*layout_m[1],width=960*layout_m[2]) |
|
1205 |
#height=480*6,width=480*4) |
|
1206 |
|
|
1207 |
#p3 <- list_plots_spt[[3]] |
|
1208 |
p1<-plot(raster_prediction_obj_3$method_mod_obj[[1]]$mod[[1]]$exp_var,raster_prediction_obj_3$method_mod_obj[[1]]$mod[[1]]$var_model) |
|
1209 |
#plot(p1) |
|
1210 |
p241<-plot(raster_prediction_obj_3$method_mod_obj[[241]]$mod[[1]]$exp_var,raster_prediction_obj_3$method_mod_obj[[241]]$mod[[1]]$var_model) |
|
1211 |
#plot(p241) |
|
1212 |
|
|
1213 |
#grid.arrange(p1,p2,p3,ncol=1) |
|
1214 |
grid.arrange(p1,p241,ncol=1) |
|
1215 |
|
|
1216 |
dev.off() |
|
1217 |
#Combine both plot? + plot info on sill, nugget and range? and most frequent model selected |
|
1218 |
|
|
1219 |
|
|
1220 |
########################################### |
|
1221 |
### Figure 10: map of residuals...for a specific date... |
|
1222 |
index <- 244 |
|
1223 |
names_mod <- names(raster_prediction_obj_2$method_mod_obj[[index]][[y_var_name]]) #names of models to plot |
|
1224 |
#in_dir2 <-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data_365d_gam_day_lst_comb4_08152013" |
|
1225 |
#date_selected <- c("20100101") |
|
1226 |
date_selected <- c("20100901") |
|
1227 |
|
|
1228 |
data_v <-raster_prediction_obj_2$validation_mod_obj[[index]]$data_v #testing with residuals |
|
1229 |
#data_s<-validation_mod_obj[[index]]$data_s |
|
1230 |
date_proc<-strptime(date_selected, "%Y%m%d") # interpolation date being processed |
|
1231 |
mo<-as.integer(strftime(date_proc, "%m")) # current month of the date being processed |
|
1232 |
day<-as.integer(strftime(date_proc, "%d")) |
|
1233 |
year<-as.integer(strftime(date_proc, "%Y")) |
|
1234 |
datelabel=format(ISOdate(year,mo,day),"%b %d, %Y") |
|
1235 |
|
|
1236 |
#height=480*6,width=480*4) |
|
1237 |
list_p <- vector("list", length(names_mod)) |
|
1238 |
for (k in 1:length(names_mod)){ |
|
1239 |
model_name <- names_mod[k] |
|
1240 |
#fig_name <- file.path(out_path,paste("Figure_residuals_map_",y_var_name,"_",model_name,"_",sampling_dat$date,"_",sampling_dat$prop,"_", |
|
1241 |
# sampling_dat$run_samp,out_prefix,".png", sep="")) |
|
1242 |
|
|
1243 |
png(file.path(out_dir,paste("Figure_residuals_map_",y_var_name,"_",model_name,"_",date_selected,out_prefix,".png", sep=""))) |
|
1244 |
res_model_name <- paste("res",model_name,sep="_") |
|
1245 |
elev <- subset(s_raster,"elev_s") |
|
1246 |
#p1 <- levelplot(elev,scales = list(draw = FALSE), colorkey = FALSE,col.regions=rev(terrain.colors(255)),contour=T) |
|
1247 |
#add legend..par.settings = GrTheme |
|
1248 |
cx <- ((data_v[[res_model_name]])*2) |
|
1249 |
#p1 <- levelplot(elev,scales = list(draw = FALSE), colorkey = FALSE,par.settings = GrTheme) |
|
1250 |
|
|
1251 |
#p2 <- spplot(data_v,res_model_name, cex=1 * cx,main=paste("Residuals for ",res_model_name," ",datelabel,sep=""), |
|
1252 |
# col.regions=matlab.like(25)) |
|
1253 |
p2 <- bubble(data_v,res_model_name, main=paste("Residuals for ",res_model_name," ",datelabel,sep=""), |
|
1254 |
col.regions=matlab.like(25)) |
|
1255 |
p3 <- p2 + p1 + p2 #to force legend... |
|
1256 |
#p1 <- spplot(interp_area) |
|
1257 |
#p3 <- p1+p2 #to force legend... |
|
1258 |
#p + layer(sp.lines(mapaSHP, lwd=0.8, col='darkgray')) |
|
1259 |
|
|
1260 |
#p2 |
|
1261 |
print(p3) |
|
1262 |
|
|
1263 |
dev.off() |
|
1264 |
list_p[[k]] <- p3 |
|
1265 |
} |
|
1266 |
|
|
1267 |
layout_m<-c(2,5) # works if set to this?? ok set the resolution... |
|
1268 |
png(paste("Figure10_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""), |
|
1269 |
height=480*layout_m[1],width=480*layout_m[2]) |
|
1270 |
|
|
1271 |
grid.arrange(list_p[[1]],list_p[[2]],list_p[[3]],list_p[[4]],list_p[[5]], |
|
1272 |
list_p[[6]],list_p[[7]],list_p[[8]],list_p[[9]],list_p[[10]],ncol=5) |
|
1273 |
|
|
1274 |
dev.off() |
|
1275 |
|
|
1276 |
|
|
1277 |
list_data_v <- lapply(1:365,function(i){raster_prediction_obj_2$validation_mod_obj[[i]]$data_v} #testing with residuals |
|
1278 |
|
|
1279 |
test <- do.call(rbind,list_data_v) |
|
1280 |
|
|
1281 |
plot(res_mod1~elev,data=test) |
|
1282 |
plot(res_mod2~elev,data=test) |
|
1283 |
cor(test$res_mod1,test$elev) |
|
1284 |
cor(test$res_mod2,test$elev,use="complete.obs") #decrease in corellation when using elev |
|
1285 |
cor(test$res_mod1,test$LST,,use="complete.obs") |
|
1286 |
cor(test$res_mod5,test$LST,use="complete.obs") #decrease in correlation when using LST |
|
1287 |
|
|
1288 |
plot(res_mod1~LST,data=test) |
|
1289 |
plot(res_mod9~LST,data=test) |
|
1290 |
|
|
1193 | 1291 |
###################### END OF SCRIPT ####################### |
1194 | 1292 |
|
1195 | 1293 |
|
Also available in: Unified diff
contribution of covariates and method paper: revisions adding figures of variograms and map of residuals