Revision 043c6c28
Added by Benoit Parmentier almost 11 years ago
climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R | ||
---|---|---|
38 | 38 |
|
39 | 39 |
#### FUNCTION USED IN SCRIPT |
40 | 40 |
|
41 |
function_analyses_paper <-"contribution_of_covariates_paper_interpolation_functions_10152013.R" |
|
42 |
|
|
43 |
plot_transect_m2<-function(list_trans,r_stack,title_plot,disp=FALSE,m_layers){ |
|
44 |
#This function creates plot of transects for stack of raster images. |
|
45 |
#Arguments: |
|
46 |
#list_trans: list of files containing the transects lines in shapefile format |
|
47 |
#r_stack: raster stack containing the information to extect |
|
48 |
#title_plot: plot title |
|
49 |
#disp: display and save from X11 if TRUE or plot to png file if FALSE |
|
50 |
#m_layers: index for layerers containing alternate units to be drawned on a differnt scale |
|
51 |
#RETURN: |
|
52 |
#list containing transect information |
|
53 |
|
|
54 |
nb<-length(list_trans) |
|
55 |
t_col<-rainbow(nb) |
|
56 |
t_col<-c("red","green","black") |
|
57 |
lty_list<-c("dashed","solid","dotted") |
|
58 |
list_trans_data<-vector("list",nb) |
|
59 |
|
|
60 |
#For scale 1 |
|
61 |
for (i in 1:nb){ |
|
62 |
trans_file<-list_trans[[i]][1] |
|
63 |
filename<-sub(".shp","",trans_file) #Removing the extension from file. |
|
64 |
transect<-readOGR(dirname(filename), basename(filename)) #reading shapefile |
|
65 |
trans_data<-extract(r_stack, transect) |
|
66 |
if (disp==FALSE){ |
|
67 |
png(file=paste(list_trans[[i]][2],".png",sep="")) |
|
68 |
} |
|
69 |
#Plot layer values for specific transect |
|
70 |
for (k in 1:ncol(trans_data[[1]])){ |
|
71 |
y<-trans_data[[1]][,k] |
|
72 |
x<-1:length(y) |
|
73 |
m<-match(k,m_layers) |
|
74 |
|
|
75 |
if (k==1 & is.na(m)){ |
|
76 |
plot(x,y,type="l",xlab="transect distance from coastal origin (km)", ylab=" maximum temperature (degree C)", |
|
77 |
,cex=1.2,col=t_col[k]) |
|
78 |
#axis(2) |
|
79 |
} |
|
80 |
if (k==1 & !is.na(m)){ |
|
81 |
plot(x,y,type="l",col=t_col[k],lty="dotted",axes=F) #plotting fusion profile |
|
82 |
#axis(4,xlab="",ylab="elevation(m)") |
|
83 |
axis(4,cex=1.2) |
|
84 |
} |
|
85 |
if (k!=1 & is.na(m)){ |
|
86 |
#par(new=TRUE) # new plot without erasing old |
|
87 |
lines(x,y,type="l",xlab="",ylab="",col=t_col[k],axes=F) #plotting fusion profile |
|
88 |
#axis(2,xlab="",ylab="tmax (in degree C)") |
|
89 |
} |
|
90 |
if (k!=1 & !is.na(m)){ |
|
91 |
par(new=TRUE) # key: ask for new plot without erasing old |
|
92 |
plot(x,y,type="l",col=t_col[k],xlab="",ylab="",lty="dotted",axes=F) #plotting fusion profile |
|
93 |
#axis(4,xlab="",ylab="elevation(m)") |
|
94 |
axis(4,cex=1.2) |
|
95 |
} |
|
96 |
} |
|
97 |
title(title_plot[i]) |
|
98 |
legend("topleft",legend=names(r_stack)[1:2], |
|
99 |
cex=1.2, col=t_col,lty=1,bty="n") |
|
100 |
legend("topright",legend=names(r_stack)[3], |
|
101 |
cex=1.2, col=t_col[3],lty="dotted",bty="n") |
|
102 |
if (disp==TRUE){ |
|
103 |
savePlot(file=paste(list_trans[[i]][2],".png",sep=""),type="png") |
|
104 |
} |
|
105 |
if (disp==FALSE){ |
|
106 |
dev.off() |
|
107 |
} |
|
108 |
list_trans_data[[i]]<-trans_data |
|
109 |
} |
|
110 |
names(list_trans_data)<-names(list_trans) |
|
111 |
return(list_trans_data) |
|
112 |
} |
|
41 |
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R" |
|
42 |
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_11252013.R" |
|
113 | 43 |
|
114 | 44 |
############################## |
115 | 45 |
#### Parameters and constants |
116 | 46 |
|
117 | 47 |
script_path<-"/home/parmentier/Data/IPLANT_project/env_layers_scripts/" #path to script |
118 |
source(file.path(script_path,function_analyses_paper)) #source all functions used in this script. |
|
48 |
source(file.path(script_path,function_analyses_paper1)) #source all functions used in this script. |
|
49 |
source(file.path(script_path,function_analyses_paper2)) #source all functions used in this script. |
|
119 | 50 |
|
120 | 51 |
#direct methods: gam, kriging, gwr |
121 | 52 |
in_dir1 <-"/data/project/layers/commons/Oregon_interpolation/output_data_365d_gam_daily_lst_comb5_11012013" |
... | ... | |
407 | 338 |
|
408 | 339 |
#######Figure 7a: Map of transects |
409 | 340 |
|
410 |
nb_transect<-3 |
|
341 |
## Transects image location in OR |
|
342 |
png(paste("Fig7_elevation_transect_paths_",date_selected,out_prefix,".png", sep=""), |
|
343 |
height=480*layout_m[1],width=480*layout_m[2]) |
|
344 |
|
|
345 |
plot(elev) |
|
346 |
for(i in 1:length(transect_list)){ |
|
347 |
filename<-sub(".shp","",transect_list[i]) #Removing the extension from file. |
|
348 |
transect<-readOGR(dirname(filename), basename(filename)) #reading shapefile |
|
349 |
plot(transect_list[i],add=TRUE) |
|
350 |
} |
|
351 |
title("Transect Oregon") |
|
352 |
dev.off() |
|
353 |
|
|
354 |
#### TRANSECT PROFILES |
|
355 |
nb_transect <- 3 |
|
411 | 356 |
list_transect2<-vector("list",nb_transect) |
357 |
list_transect3<-vector("list",nb_transect) |
|
358 |
list_transect4<-vector("list",nb_transect) |
|
359 |
|
|
412 | 360 |
rast_pred<-stack(lf[[2]]) #GAM_CAI |
413 |
rast_pred_selected<-subset(rast_pred,c(1,6)) #3 is referring to FSS, plot it first because it has the |
|
414 |
# the largest range. |
|
415 |
rast_pred2<-stack(rast_pred_selected,subset(s_raster,"elev_s")) |
|
361 |
rast_pred_selected2<-subset(rast_pred,c(1,6)) #3 is referring to FSS, plot it first because it has the |
|
362 |
rast_pred_selected3<-subset(rast_pred,c(1,2)) #3 is referring to FSS, plot it first because it has the |
|
363 |
rast_pred3<-stack(lf[[2]]) #GAM_CAI |
|
364 |
# the largest range. |
|
365 |
rast_pred2 <- stack(rast_pred_selected2,subset(s_raster,"elev_s")) |
|
366 |
rast_pred3 <- stack(rast_pred_selected3,subset(s_raster,"elev_s")) |
|
416 | 367 |
|
417 | 368 |
#layers_names<-layerNames(rast_pred2)<-c("lat*lon","lat*lon + elev + LST","elev") |
418 |
layers_names<-layerNames(rast_pred2)<-c("mod1","mod6","elev") |
|
369 |
layers_names<- names(rast_pred2)<-c("mod1","mod6","elev") |
|
370 |
layers_names<- names(rast_pred3)<-c("mod1","mod2","elev") |
|
419 | 371 |
pos<-c(1,2) # postions in the layer prection |
420 | 372 |
transect_list |
421 | 373 |
list_transect2[[1]]<-c(transect_list[1],paste("figure_3_tmax_elevation_transect1_OR_",date_selected, |
... | ... | |
425 | 377 |
list_transect2[[3]]<-c(transect_list[3],paste("figure_3_tmax_elevation_transect3_OR_",date_selected, |
426 | 378 |
paste("mod1_mod6",collapse="_"),out_prefix,sep="_")) |
427 | 379 |
|
380 |
list_transect3[[1]]<-c(transect_list[1],paste("figure_3_tmax_elevation_transect1_OR_",date_selected, |
|
381 |
paste("mod1_mod2",collapse="_"),out_prefix,sep="_")) |
|
382 |
list_transect3[[2]]<-c(transect_list[2],paste("figure_3_tmax_elevation_transect2_OR_",date_selected, |
|
383 |
paste("mod1_mod2",collapse="_"),out_prefix,sep="_")) |
|
384 |
list_transect3[[3]]<-c(transect_list[3],paste("figure_3_tmax_elevation_transect3_OR_",date_selected, |
|
385 |
paste("mod1_mod2",collapse="_"),out_prefix,sep="_")) |
|
386 |
|
|
428 | 387 |
names(list_transect2)<-c("transect_OR1","transect_OR2","transect_OR3") |
388 |
names(list_transect3)<-c("transect_OR1","transect_OR2","transect_OR3") |
|
429 | 389 |
|
430 | 390 |
names(rast_pred2)<-layers_names |
391 |
names(rast_pred3)<-layers_names |
|
392 |
|
|
431 | 393 |
title_plot2<-paste(names(list_transect2),date_selected,sep=" ") |
432 | 394 |
title_plot2<-paste(rep("Oregon transect on ",3), date_selected,sep="") |
395 |
title_plot3<-paste(names(list_transect3),date_selected,sep=" ") |
|
396 |
title_plot3<-paste(rep("Oregon transect on ",3), date_selected,sep="") |
|
397 |
|
|
433 | 398 |
#r_stack<-rast_pred |
434 | 399 |
m_layers_sc<-c(3) #elevation in the third layer |
400 |
#m_layers_sc<-c(4) #elevation in the third layer |
|
401 |
|
|
435 | 402 |
#title_plot2 |
436 | 403 |
#rast_pred2 |
437 |
debug(plot_transect_m2) |
|
404 |
#debug(plot_transect_m2)
|
|
438 | 405 |
trans_data2<-plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc) |
439 |
|
|
440 |
#png(filename=paste("Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480) |
|
441 |
#par(mfrow=c(1,2)) |
|
442 |
|
|
443 |
dev.off() |
|
444 |
|
|
445 |
## Transects image location in OR |
|
446 |
png(paste("Fig7_elevation_transect_paths_",date_selected,out_prefix,".png", sep=""), |
|
447 |
height=480*layout_m[1],width=480*layout_m[2]) |
|
448 |
|
|
449 |
plot(elev_s) |
|
450 |
#k<-1 #transect to plot |
|
451 |
list_transect2[[3]] |
|
452 |
#trans_file<-list_transect2[[k]][[1]] |
|
453 |
#filename<-sub(".shp","",trans_file) #Removing the extension from file. |
|
454 |
#transect<-readOGR(".", filename) #reading shapefile |
|
455 |
#plot(transect,add=TRUE) |
|
456 |
#title("Transect Oregon") |
|
457 |
#dev.off() |
|
406 |
trans_data3<-plot_transect_m2(list_transect3,rast_pred3,title_plot3,disp=FALSE,m_layers_sc) |
|
458 | 407 |
|
459 | 408 |
################################################ |
460 | 409 |
#Figure 9: Image differencing and land cover |
461 |
|
|
410 |
#Do for january and September... |
|
462 | 411 |
png(paste("Fig9_image_difference_",date_selected,out_prefix,".png", sep=""), |
463 | 412 |
height=480*layout_m[1],width=480*layout_m[2]) |
464 | 413 |
|
414 |
pred_temp <-subset(rast_pred,c(1,2,6)) #3 |
|
415 |
|
|
416 |
p <- levelplot(pred_temp_s,main=methods_names[i], ylab=NULL,xlab=NULL, |
|
417 |
par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m, |
|
418 |
par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5), |
|
419 |
names.attr=names_layers,col.regions=temp.colors,at=seq(min_val,max_val,by=0.25)) |
|
420 |
#col.regions=temp.colors(25)) |
|
421 |
print(p) |
|
422 |
dev.off() |
|
423 |
|
|
465 | 424 |
###################### END OF SCRIPT ####################### |
466 | 425 |
|
467 | 426 |
|
Also available in: Unified diff
multi-timescale paper analyses, generating figures and splitting files for functions