Revision bac85c93
Added by Benoit Parmentier almost 9 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part2.R | ||
---|---|---|
5 | 5 |
#Analyses, figures, tables and data are also produced in the script. |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 03/23/2014 |
8 |
#MODIFIED ON: 01/01/2016
|
|
8 |
#MODIFIED ON: 01/02/2016
|
|
9 | 9 |
#Version: 4 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#COMMENTS: analyses for run 10 global analyses,all regions 1500x4500km with additional tiles to increase overlap |
... | ... | |
16 | 16 |
|
17 | 17 |
################################################################################################# |
18 | 18 |
|
19 |
### Loading R library and packages |
|
20 |
#library used in the workflow production: |
|
21 |
library(gtools) # loading some useful tools |
|
22 |
library(mgcv) # GAM package by Simon Wood |
|
23 |
library(sp) # Spatial pacakge with class definition by Bivand et al. |
|
24 |
library(spdep) # Spatial pacakge with methods and spatial stat. by Bivand et al. |
|
25 |
library(rgdal) # GDAL wrapper for R, spatial utilities |
|
26 |
library(gstat) # Kriging and co-kriging by Pebesma et al. |
|
27 |
library(fields) # NCAR Spatial Interpolation methods such as kriging, splines |
|
28 |
library(raster) # Hijmans et al. package for raster processing |
|
29 |
library(gdata) # various tools with xls reading, cbindX |
|
30 |
library(rasterVis) # Raster plotting functions |
|
31 |
library(parallel) # Parallelization of processes with multiple cores |
|
32 |
library(maptools) # Tools and functions for sp and other spatial objects e.g. spCbind |
|
33 |
library(maps) # Tools and data for spatial/geographic objects |
|
34 |
library(reshape) # Change shape of object, summarize results |
|
35 |
library(plotrix) # Additional plotting functions |
|
36 |
library(plyr) # Various tools including rbind.fill |
|
37 |
library(spgwr) # GWR method |
|
38 |
library(automap) # Kriging automatic fitting of variogram using gstat |
|
39 |
library(rgeos) # Geometric, topologic library of functions |
|
40 |
#RPostgreSQL # Interface R and Postgres, not used in this script |
|
41 |
library(gridExtra) |
|
42 |
#Additional libraries not used in workflow |
|
43 |
library(pgirmess) # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess} |
|
44 |
library(colorRamps) |
|
45 |
library(zoo) |
|
46 |
library(xts) |
|
19 |
|
|
47 | 20 |
|
48 | 21 |
#### FUNCTION USED IN SCRIPT |
49 | 22 |
|
50 |
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_07182014.R" #first interp paper |
|
51 |
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_08132014.R" |
|
52 |
function_global_run_assessment_part2 <- "global_run_scalingup_assessment_part2_functions_0923015.R" |
|
23 |
#function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_07182014.R" #first interp paper
|
|
24 |
#function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_08132014.R"
|
|
25 |
#function_global_run_assessment_part2 <- "global_run_scalingup_assessment_part2_functions_0923015.R"
|
|
53 | 26 |
|
54 |
load_obj <- function(f) |
|
55 |
{ |
|
56 |
env <- new.env() |
|
57 |
nm <- load(f, env)[1] |
|
58 |
env[[nm]] |
|
59 |
} |
|
60 | 27 |
|
61 |
create_dir_fun <- function(out_dir,out_suffix){ |
|
62 |
if(!is.null(out_suffix)){ |
|
63 |
out_name <- paste("output_",out_suffix,sep="") |
|
64 |
out_dir <- file.path(out_dir,out_name) |
|
65 |
} |
|
66 |
#create if does not exists |
|
67 |
if(!file.exists(out_dir)){ |
|
68 |
dir.create(out_dir) |
|
69 |
} |
|
70 |
return(out_dir) |
|
71 |
} |
|
72 | 28 |
|
73 | 29 |
|
74 | 30 |
############################################ |
... | ... | |
106 | 62 |
file_format <- ".rst" #PARAM 9 |
107 | 63 |
NA_value <- -9999 #PARAM10 |
108 | 64 |
NA_flag_val <- NA_value |
109 |
#tile_size <- "1500x4500" #PARAM 11 |
|
110 | 65 |
multiple_region <- TRUE #PARAM 12 |
111 | 66 |
#region_name <- "world" #PARAM 13 |
112 | 67 |
countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" #PARAM 13, copy this on NEX too |
113 | 68 |
plot_region <- TRUE |
114 | 69 |
num_cores <- 6 #PARAM 14 |
115 |
reg_modified <- TRUE #PARAM 15 |
|
116 | 70 |
region_name <- c("reg4") #reference region to merge if necessary, if world all the regions are together #PARAM 16 |
117 | 71 |
#use previous files produced in step 1a and stored in a data.frame |
118 | 72 |
df_assessment_files <- "df_assessment_files_reg4_1984_run_global_analyses_pred_12282015.txt" #PARAM 17 |
119 | 73 |
threshold_missing_day <- c(367,365,300,200) #PARM18 |
120 | 74 |
|
121 |
########################## START SCRIPT ############################## |
|
122 |
|
|
75 |
list_param_run_assessment_plottingin_dir <- list(y_var_name, interpolation_method, out_suffix, |
|
76 |
out_dir, create_out_dir_param, mosaic_plot, proj_str, file_format, NA_value, |
|
77 |
multiple_region, countries_shp, plot_region, num_cores, |
|
78 |
region_name, df_assessment_files, threshold_missing_day) |
|
123 | 79 |
|
124 |
####### PART 1: Read in data ######## |
|
80 |
names(list_param_run_assessment_plottingin_dir) <- c("y_var_name","interpolation_method","out_suffix", |
|
81 |
"out_dir","create_out_dir_param","mosaic_plot","proj_str","file_format","NA_value", |
|
82 |
"multiple_region","countries_shp","plot_region","num_cores", |
|
83 |
"region_name","df_assessment_files","threshold_missing_day") |
|
125 | 84 |
|
126 |
if(create_out_dir_param==TRUE){ |
|
127 |
out_dir <- create_dir_fun(out_dir,out_suffix) |
|
128 |
setwd(out_dir) |
|
129 |
}else{ |
|
130 |
setwd(out_dir) #use previoulsy defined directory |
|
131 |
} |
|
85 |
run_assessment_plotting_prediction_fun(list_param_run_assessment_plottingin_dir) |
|
132 | 86 |
|
133 |
setwd(out_dir) |
|
134 |
#i <- year_predicted |
|
135 | 87 |
run_assessment_plotting_prediction_fun <-function(list_param_run_assessment_plotting){ |
136 | 88 |
|
89 |
#### |
|
90 |
#1) in_dir: input directory containing data tables and shapefiles for plotting #PARAM 0 |
|
91 |
#2) y_var_name : variables being predicted e.g. dailyTmax #PARAM1 |
|
92 |
#3) interpolation_method: method used #c("gam_CAI") #PARAM2 |
|
93 |
#4) out_suffix: output suffix #PARAM3 |
|
94 |
#5) out_dir # |
|
95 |
#6) create_out_dir_param # FALSE #PARAM 5 |
|
96 |
#7) mosaic_plot #FALSE #PARAM6 |
|
97 |
#8) proj_str # projection/coordinates system e.g. CRS_WGS84 #PARAM 8 #check this parameter |
|
98 |
#9) file_format #".rst" #PARAM 9 |
|
99 |
#10) NA_value #-9999 #PARAM10 |
|
100 |
#11) multiple_region # <- TRUE #PARAM 12 |
|
101 |
#12) countries_shp #<- "world" #PARAM 13 |
|
102 |
#13) plot_region #<- TRUE |
|
103 |
#14) num_cores <- number of cores used # 6 #PARAM 14 |
|
104 |
#16) region_name #<- c("reg4"), world if full assessment #reference region to merge if necessary #PARAM 16 |
|
105 |
#18) df_assessment_files #PARAM 16 |
|
106 |
#19) threshold_missing_day #PARM18 |
|
107 |
# |
|
108 |
|
|
109 |
### Loading R library and packages |
|
110 |
#library used in the workflow production: |
|
111 |
library(gtools) # loading some useful tools |
|
112 |
library(mgcv) # GAM package by Simon Wood |
|
113 |
library(sp) # Spatial pacakge with class definition by Bivand et al. |
|
114 |
library(spdep) # Spatial pacakge with methods and spatial stat. by Bivand et al. |
|
115 |
library(rgdal) # GDAL wrapper for R, spatial utilities |
|
116 |
library(gstat) # Kriging and co-kriging by Pebesma et al. |
|
117 |
library(fields) # NCAR Spatial Interpolation methods such as kriging, splines |
|
118 |
library(raster) # Hijmans et al. package for raster processing |
|
119 |
library(gdata) # various tools with xls reading, cbindX |
|
120 |
library(rasterVis) # Raster plotting functions |
|
121 |
library(parallel) # Parallelization of processes with multiple cores |
|
122 |
library(maptools) # Tools and functions for sp and other spatial objects e.g. spCbind |
|
123 |
library(maps) # Tools and data for spatial/geographic objects |
|
124 |
library(reshape) # Change shape of object, summarize results |
|
125 |
library(plotrix) # Additional plotting functions |
|
126 |
library(plyr) # Various tools including rbind.fill |
|
127 |
library(spgwr) # GWR method |
|
128 |
library(automap) # Kriging automatic fitting of variogram using gstat |
|
129 |
library(rgeos) # Geometric, topologic library of functions |
|
130 |
#RPostgreSQL # Interface R and Postgres, not used in this script |
|
131 |
library(gridExtra) |
|
132 |
#Additional libraries not used in workflow |
|
133 |
library(pgirmess) # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess} |
|
134 |
library(colorRamps) |
|
135 |
library(zoo) |
|
136 |
library(xts) |
|
137 |
|
|
138 |
####### Function used in the script ####### |
|
139 |
|
|
140 |
load_obj <- function(f){ |
|
141 |
env <- new.env() |
|
142 |
nm <- load(f, env)[1] |
|
143 |
env[[nm]] |
|
144 |
} |
|
145 |
|
|
146 |
create_dir_fun <- function(out_dir,out_suffix){ |
|
147 |
if(!is.null(out_suffix)){ |
|
148 |
out_name <- paste("output_",out_suffix,sep="") |
|
149 |
out_dir <- file.path(out_dir,out_name) |
|
150 |
} |
|
151 |
#create if does not exists |
|
152 |
if(!file.exists(out_dir)){ |
|
153 |
dir.create(out_dir) |
|
154 |
} |
|
155 |
return(out_dir) |
|
156 |
} |
|
157 |
|
|
158 |
#function_assessment_part2_functions <- "global_run_scalingup_assessment_part2_functions_0923015.R" |
|
159 |
#source(file.path(script_path,function_assessment_part2_functions)) #source all functions used in this script |
|
160 |
|
|
161 |
####### PARSE INPUT ARGUMENTS/PARAMETERS ##### |
|
162 |
|
|
137 | 163 |
in_dir <- list_param_run_assessment_plotting$in_dir #PARAM 0 |
138 | 164 |
y_var_name <- list_param_run_assessment_plotting$y_var_name #PARAM1 |
139 | 165 |
interpolation_method <- list_param_run_assessment_plotting$interpolation_method #c("gam_CAI") #PARAM2 |
... | ... | |
148 | 174 |
countries_shp <- list_param_run_assessment_plotting$countries_shp #<- "world" #PARAM 13 |
149 | 175 |
plot_region <- list_param_run_assessment_plotting$plot_region #<- TRUE |
150 | 176 |
num_cores <- list_param_run_assessment_plotting$num_cores # 6 #PARAM 14 |
151 |
reg_modified <- list_param_run_assessment_plotting$reg_modified #<- TRUE #PARAM 15 |
|
152 |
region <- list_param_run_assessment_plotting$region #<- c("reg4") #reference region to merge if necessary #PARAM 16 |
|
153 | 177 |
region_name <- list_param_run_assessment_plotting$region_name #<- "world" #PARAM 13 |
154 | 178 |
df_assessment_files <- list_param_run_assessment_plotting$df_assessment_files #PARAM 16 |
155 | 179 |
threshold_missing_day <- list_param_run_assessment_plotting$threshold_missing_day #PARM18 |
156 | 180 |
|
157 | 181 |
NA_flag_val <- NA_value |
158 |
|
|
159 |
#tile_size <- "1500x4500" #PARAM 11 |
|
160 |
|
|
182 |
|
|
161 | 183 |
##################### START SCRIPT ################# |
162 | 184 |
|
185 |
####### PART 1: Read in data ######## |
|
186 |
|
|
187 |
if(create_out_dir_param==TRUE){ |
|
188 |
out_dir <- create_dir_fun(out_dir,out_suffix) |
|
189 |
setwd(out_dir) |
|
190 |
}else{ |
|
191 |
setwd(out_dir) #use previoulsy defined directory |
|
192 |
} |
|
193 |
|
|
194 |
setwd(out_dir) |
|
195 |
|
|
196 |
#i <- year_predicted |
|
163 | 197 |
###Table 1: Average accuracy metrics |
164 | 198 |
###Table 2: daily accuracy metrics for all tiles |
165 | 199 |
|
... | ... | |
216 | 250 |
#list_shp_reg_files <- file.path("/data/project/layers/commons/NEX_data/",out_dir, |
217 | 251 |
#"shapefiles",basename(list_shp_reg_files)) |
218 | 252 |
|
219 |
#table(summary_metrics_v$reg) |
|
220 |
#table(summary_metrics_v$reg) |
|
221 |
|
|
222 | 253 |
### Potential function starts here: |
223 | 254 |
#function(in_dir,out_dir,list_shp_reg_files,title_str,region_name,num_cores,out_suffix,out_suffix) |
224 | 255 |
|
... | ... | |
226 | 257 |
#can make this more general later on..should have this already in a local directory on Atlas or NEX!!!! |
227 | 258 |
|
228 | 259 |
#http://www.diva-gis.org/Data |
229 |
countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp" |
|
260 |
#countries_shp <-"/data/project/layers/commons/NEX_data/countries.shp"
|
|
230 | 261 |
path_to_shp <- dirname(countries_shp) |
231 | 262 |
layer_name <- sub(".shp","",basename(countries_shp)) |
232 | 263 |
reg_layer <- readOGR(path_to_shp, layer_name) |
... | ... | |
306 | 337 |
|
307 | 338 |
|
308 | 339 |
tb$tile_id <- factor(tb$tile_id, levels=unique(tb$tile_id)) |
309 |
|
|
310 | 340 |
model_name <- as.character(unique(tb$pred_mod)) |
311 | 341 |
|
312 |
|
|
313 | 342 |
## Figure 2a |
314 |
|
|
315 | 343 |
for(i in 1:length(model_name)){ |
316 | 344 |
|
317 | 345 |
res_pix <- 480 |
... | ... | |
328 | 356 |
} |
329 | 357 |
|
330 | 358 |
## Figure 2b |
331 |
#wtih ylim and removing trailing...
|
|
359 |
#with ylim and removing trailing...
|
|
332 | 360 |
for(i in 1:length(model_name)){ |
333 | 361 |
|
334 | 362 |
res_pix <- 480 |
... | ... | |
370 | 398 |
|
371 | 399 |
dev.off() |
372 | 400 |
|
373 |
|
|
374 | 401 |
################ |
375 | 402 |
### Figure 4: plot predicted tiff for specific date per model |
376 | 403 |
|
... | ... | |
459 | 486 |
png(filename=paste("Figure6_ac_metrics_map_centroids_tile_",model_name[i],"_",out_suffix,".png",sep=""), |
460 | 487 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
461 | 488 |
|
462 |
#plot(r_pred) |
|
463 |
#plot(reg_layer) |
|
464 |
#plot(ac_mod1,cex=sqrt(ac_mod1$rmse),pch=1,add=T) |
|
465 |
#plot(ac_mod,cex=(ac_mod$rmse^2)/10,pch=1,col="red",add=T) |
|
466 |
|
|
467 | 489 |
#coordinates(ac_mod) <- ac_mod[,c("lon","lat")] |
468 | 490 |
coordinates(ac_mod) <- ac_mod[,c("lon.x","lat.x")] #solve this later |
469 | 491 |
p_shp <- layer(sp.polygons(reg_layer, lwd=1, col='black')) |
... | ... | |
526 | 548 |
threshold_missing_day[i])) |
527 | 549 |
p1 <- p+p_shp |
528 | 550 |
try(print(p1)) #error raised if number of missing values below a threshold does not exist |
529 |
#plot(ac_mod1,cex=(ac_mod1$rmse1)*2,pch=1,add=T) |
|
530 |
#title(paste("Averrage RMSE per tile and by ",model_name[i])) |
|
531 |
|
|
551 |
|
|
532 | 552 |
dev.off() |
533 | 553 |
} |
534 | 554 |
|
535 | 555 |
###################### |
536 | 556 |
### Figure 7: Number of predictions: daily and monthly |
537 | 557 |
|
538 |
#xyplot(rmse~pred_mod | tile_id,data=subset(as.data.frame(summary_metrics_v), |
|
539 |
# pred_mod!="mod_kr"),type="b") |
|
540 |
|
|
541 |
#xyplot(n~pred_mod | tile_id,data=subset(as.data.frame(summary_metrics_v), |
|
542 |
# pred_mod!="mod_kr"),type="h") |
|
543 |
|
|
544 |
#cor |
|
545 |
|
|
546 |
# |
|
547 | 558 |
## Figure 7a |
548 | 559 |
png(filename=paste("Figure7a_number_daily_predictions_per_models","_",out_suffix,".png",sep=""), |
549 | 560 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
... | ... | |
585 | 596 |
#dev.off() |
586 | 597 |
# |
587 | 598 |
|
588 |
|
|
589 | 599 |
########################################################## |
590 | 600 |
##### Figure 8: Breaking down accuracy by regions!! ##### |
591 | 601 |
|
... | ... | |
616 | 626 |
dev.off() |
617 | 627 |
|
618 | 628 |
##################################################### |
619 |
#### Figure 9: plotting mosaics of regions ########### |
|
620 |
## plot mosaics... |
|
629 |
#### Figure 9: plotting boxplot by year and regions ########### |
|
621 | 630 |
|
622 |
#First collect file names |
|
623 |
|
|
624 |
|
|
625 |
#names(lf_mosaics_reg) <- l_reg_name |
|
626 |
|
|
627 |
#This part should be automated... |
|
628 |
#plot Australia |
|
629 |
#lf_m <- lf_mosaics_reg[[2]] |
|
630 |
#out_dir_str <- out_dir |
|
631 |
#reg_name <- "reg6_1000x3000" |
|
632 |
#lapply() |
|
633 |
#list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_suffix) |
|
634 |
#list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_suffix,l_dates=day_to_mosaic) |
|
635 |
|
|
636 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
637 |
#debug(plot_daily_mosaics) |
|
638 |
#lf_m_mask_reg6_1000x3000 <- plot_daily_mosaics(1,list_param=list_param_plot_daily_mosaics) |
|
639 |
|
|
640 |
#lf_m_mask_reg6_1000x3000 <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 10) |
|
641 |
|
|
642 |
|
|
643 |
################## WORLD MOSAICS NEEDS MAJOR CLEAN UP OF CODE HERE |
|
644 |
##make functions!! |
|
645 |
###Combine mosaics with modified code from Alberto |
|
646 |
|
|
647 |
#use list from above!! |
|
631 |
## Figure 8a |
|
632 |
res_pix <- 480 |
|
633 |
col_mfrow <- 1 |
|
634 |
row_mfrow <- 1 |
|
648 | 635 |
|
649 |
# test_list <-list.files(path=file.path(out_dir,"mosaics"), |
|
650 |
# pattern=paste("^world_mosaics.*.tif$",sep=""), |
|
651 |
# ) |
|
652 |
# #world_mosaics_mod1_output1500x4500_km_20101105_run10_1500x4500_global_analyses_03112015.tif |
|
653 |
# |
|
654 |
# #test_list<-lapply(1:30,FUN=function(i){lapply(1:x[[i]]},x=lf_mosaics_mask_reg) |
|
655 |
# #test_list<-unlist(test_list) |
|
656 |
# #mosaic_list_mean <- vector("list",length=1) |
|
657 |
# mosaic_list_mean <- test_list |
|
658 |
# out_rastnames <- "world_test_mosaic_20100101" |
|
659 |
# out_path <- out_dir |
|
660 |
# |
|
661 |
# list_param_mosaic<-list(mosaic_list_mean,out_path,out_rastnames,file_format,NA_flag_val,out_suffix) |
|
662 |
# names(list_param_mosaic)<-c("mosaic_list","out_path","out_rastnames","file_format","NA_flag_val","out_suffix") |
|
663 |
# #mean_m_list <-mclapply(1:12, list_param=list_param_mosaic, mosaic_m_raster_list,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement |
|
664 |
# |
|
665 |
# lf <- mosaic_m_raster_list(1,list_param_mosaic) |
|
666 |
# |
|
667 |
# debug(mosaic_m_raster_list) |
|
668 |
# mosaic_list<-list_param$mosaic_list |
|
669 |
# out_path<-list_param$out_path |
|
670 |
# out_names<-list_param$out_rastnames |
|
671 |
# file_format <- list_param$file_format |
|
672 |
# NA_flag_val <- list_param$NA_flag_val |
|
673 |
# out_suffix <- list_param$out_suffix |
|
674 |
|
|
675 |
##Now mosaic for mean: should reorder files!! |
|
676 |
#out_rastnames_mean<-paste("_",lst_pat,"_","mean",out_suffix,sep="") |
|
677 |
#list_date_names<-c("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec") |
|
678 |
#mosaic_list<-split(tmp_str1,list_date_names) |
|
679 |
#new_list<-vector("list",length(mosaic_list)) |
|
680 |
# for (i in 1:length(list_date_names)){ |
|
681 |
# j<-grep(list_date_names[i],mosaic_list,value=FALSE) |
|
682 |
# names(mosaic_list)[j]<-list_date_names[i] |
|
683 |
# new_list[i]<-mosaic_list[j] |
|
684 |
# } |
|
685 |
# mosaic_list_mean <-new_list #list ready for mosaicing |
|
686 |
# out_rastnames_mean<-paste(list_date_names,out_rastnames_mean,sep="") |
|
687 |
|
|
688 |
### Now mosaic tiles...Note that function could be improved to use less memory |
|
689 |
|
|
690 |
|
|
691 |
################## PLOTTING WORLD MOSAICS ################ |
|
692 |
|
|
693 |
#lf_world_pred <-list.files(path=file.path(out_dir,"mosaics"), |
|
694 |
# pattern=paste("^world_mosaics.*.tif$",sep=""),full.names=T) |
|
695 |
|
|
696 |
lf_world_pred <-list.files(path=file.path(out_dir,"mosaics"), |
|
697 |
pattern=paste("^reg5.*.",".tif$",sep=""),full.names=T) |
|
698 |
l_reg_name <- unique(df_tile_processed$reg) |
|
699 |
lf_world_pred <-list.files(path=file.path(out_dir,l_reg_name[[i]]), |
|
700 |
pattern=paste(".tif$",sep=""),full.names=T) |
|
701 |
|
|
702 |
#mosaic_list_mean <- test_list |
|
703 |
#out_rastnames <- "world_test_mosaic_20100101" |
|
704 |
#out_path <- out_dir |
|
705 |
|
|
706 |
#lf_world_pred <- list.files(pattern="world.*2010090.*.tif$") |
|
707 |
#lf_raster_fname <- list.files(pattern="world.*2010*.*02162015.tif$",full.names=T) |
|
708 |
lf_raster_fname <- lf_world_pred |
|
709 |
prefix_str <- "Figure10_clim_world_mosaics_day_" |
|
710 |
l_dates <-day_to_mosaic |
|
711 |
screenRast=FALSE |
|
712 |
list_param_plot_screen_raster <- list(lf_raster_fname,screenRast,l_dates,out_dir,prefix_str,out_suffix) |
|
713 |
names(list_param_plot_screen_raster) <- c("lf_raster_fname","screenRast","l_dates","out_dir_str","prefix_str","out_suffix_str") |
|
714 |
|
|
715 |
debug(plot_screen_raster_val) |
|
716 |
|
|
717 |
world_m_list1<- plot_screen_raster_val(1,list_param_plot_screen_raster) |
|
718 |
#world_m_list <- mclapply(11:30, list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement |
|
719 |
world_m_list <- mclapply(1:length(l_dates), list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement |
|
720 |
|
|
721 |
s_pred <- stack(lf_raster_fname) |
|
722 |
|
|
723 |
res_pix <- 1500 |
|
724 |
col_mfrow <- 3 |
|
725 |
row_mfrow <- 2 |
|
726 |
|
|
727 |
png(filename=paste("Figure10_levelplot_combined_",region_name,"_",out_suffix,".png",sep=""), |
|
636 |
png(filename=paste("Figure9a_boxplot_overall_separated_by_region_year_with_oultiers_",model_name[i],"_",out_suffix,".png",sep=""), |
|
728 | 637 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
729 | 638 |
|
730 |
levelplot(s_pred,layers=1:6,col.regions=rev(terrain.colors(255)),cex=4) |
|
731 |
|
|
639 |
p<- bwplot(rmse~pred_mod | reg, data=tb, |
|
640 |
main="RMSE per model and region over all tiles") |
|
641 |
print(p) |
|
732 | 642 |
dev.off() |
733 | 643 |
|
734 |
# blues<- designer.colors(6, c( "blue", "white") ) |
|
735 |
# reds <- designer.colors(6, c( "white","red") ) |
|
736 |
# colorTable<- c( blues[-6], reds) |
|
737 |
# breaks with a gap of 10 to 17 assigned the white color |
|
738 |
# brks<- c(seq( 1, 10,,6), seq( 17, 25,,6)) |
|
739 |
# image.plot( x,y,z,breaks=brks, col=colorTable) |
|
740 |
# |
|
644 |
## Figure 8b |
|
645 |
png(filename=paste("Figure8b_boxplot_overall_separated_by_region_year_scaling_",model_name[i],"_",out_suffix,".png",sep=""), |
|
646 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
741 | 647 |
|
742 |
#lf_world_mask_reg <- vector("list",length=length(lf_world_pred)) |
|
743 |
#for(i in 1:length(lf_world_pred)){ |
|
744 |
# |
|
745 |
# lf_m <- lf_mosaics_reg[i] |
|
746 |
# out_dir_str <- out_dir |
|
747 |
#reg_name <- paste(l_reg_name[i],"_",tile_size,sep="") #make this automatic |
|
748 |
#lapply() |
|
749 |
# list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=tile_size,out_dir_str=out_dir_str,out_suffix=out_suffix,l_dates=day_to_mosaic) |
|
750 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
751 |
|
|
752 |
#lf_world_mask_reg[[i]] <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 10) |
|
753 |
} |
|
754 |
|
|
755 |
############# NEW MASK AND DATA |
|
756 |
## Plot areas and day predicted as first check |
|
757 |
|
|
758 |
l_reg_name <- unique(df_tile_processed$reg) |
|
759 |
#(subset(df_tile_processed$reg == l_reg_name[i],date) |
|
648 |
boxplot(rmse~pred_mod,data=tb,ylim=c(0,5),outline=FALSE)#,names=tb$pred_mod) |
|
649 |
title("RMSE per model over all tiles") |
|
650 |
p<- bwplot(rmse~pred_mod | reg, data=tb,ylim=c(0,5), |
|
651 |
main="RMSE per model and region over all tiles") |
|
652 |
print(p) |
|
653 |
dev.off() |
|
760 | 654 |
|
761 |
for(i in 1:length(l_reg_name)){ |
|
762 |
lf_world_pred<-list.files(path=file.path(out_dir,l_reg_name[[i]]), |
|
763 |
pattern=paste(".tif$",sep=""),full.names=T) |
|
764 |
|
|
765 |
#mosaic_list_mean <- test_list |
|
766 |
#out_rastnames <- "world_test_mosaic_20100101" |
|
767 |
#out_path <- out_dir |
|
768 |
|
|
769 |
#lf_world_pred <- list.files(pattern="world.*2010090.*.tif$") |
|
770 |
#lf_raster_fname <- list.files(pattern="world.*2010*.*02162015.tif$",full.names=T) |
|
771 |
lf_raster_fname <- lf_world_pred |
|
772 |
prefix_str <- paste("Figure10_",l_reg_name[i],sep="") |
|
773 |
|
|
774 |
l_dates <- basename(lf_raster_fname) |
|
775 |
tmp_name <- gsub(".tif","",l_dates) |
|
776 |
tmp_name <- gsub("gam_CAI_dailyTmax_predicted_mod1_0_1_","",tmp_name) |
|
777 |
#l_dates <- tmp_name |
|
778 |
l_dates <- paste(l_reg_name[i],"_",tmp_name,sep="") |
|
779 |
|
|
780 |
screenRast=TRUE |
|
781 |
list_param_plot_screen_raster <- list(lf_raster_fname,screenRast,l_dates,out_dir,prefix_str,out_suffix) |
|
782 |
names(list_param_plot_screen_raster) <- c("lf_raster_fname","screenRast","l_dates","out_dir_str","prefix_str","out_suffix_str") |
|
783 |
|
|
784 |
#undebug(plot_screen_raster_val) |
|
785 |
|
|
786 |
#world_m_list1<- plot_screen_raster_val(1,list_param_plot_screen_raster) |
|
787 |
#world_m_list <- mclapply(11:30, list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement |
|
788 |
world_m_list <- mclapply(1:length(l_dates), list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = num_cores) #This is the end bracket from mclapply(...) statement |
|
789 |
|
|
790 |
#s_pred <- stack(lf_raster_fname) |
|
791 |
|
|
792 |
#res_pix <- 1500 |
|
793 |
#col_mfrow <- 3 |
|
794 |
#row_mfrow <- 2 |
|
795 |
|
|
796 |
#png(filename=paste("Figure10_levelplot_combined_",region_name,"_",out_suffix,".png",sep=""), |
|
797 |
# width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
798 |
|
|
799 |
#levelplot(s_pred,layers=1:6,col.regions=rev(terrain.colors(255)),cex=4) |
|
800 |
|
|
801 |
#dev.off() |
|
802 | 655 |
} |
803 | 656 |
|
804 | 657 |
|
Also available in: Unified diff
clean up of assessment figure plotting called from part1