Project

General

Profile

« Previous | Next » 

Revision d5606ef2

Added by Benoit Parmentier over 10 years ago

proof RS paper contribution of covar, increasing resolution of figures

View differences:

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: 09/03/2014            
7
#MODIFIED ON: 09/11/2014            
8 8
#Version: 5
9 9
#PROJECT: Environmental Layers project                                     
10 10
#################################################################################################
......
69 69
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"
70 70
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
71 71
y_var_name <- "dailyTmax"
72
out_prefix<-"_09032014"
72
out_prefix<-"_09112014"
73 73
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_contribution_covar_analyses_tables_fig"
74 74
#setwd(out_dir)
75 75

  
......
270 270
interp_area_WGS84 <-spTransform(interp_area,CRS_locs_WGS84)         # Project from WGS84 to new coord. system
271 271

  
272 272
usa_map <- getData('GADM', country='USA', level=1) #Get US map
273
#usa_map <- getData('GADM', country='USA') #Get US map
274
#usa_map <- getData(name=GADM) #Get US map
275
#usa_map <- load_obj(list.files(pattern="^USA.*.RData"))
273 276
usa_map_2 <- usa_map[usa_map$NAME_1!="Alaska",] #remove Alaska
274 277
usa_map_2 <- usa_map_2[usa_map_2$NAME_1!="Hawaii",] #remove Hawai 
275 278
usa_map_OR <- usa_map_2[usa_map_2$NAME_1=="Oregon",] #get OR
......
279 282

  
280 283
#set up the output file to plot
281 284
res_pix<-960
285
res_pix<-1200
286

  
282 287
col_mfrow<-1
283 288
row_mfrow<-1
284 289
png(filename=paste("Figure1_contribution_covariates_study_area_",out_prefix,".png",sep=""),
......
299 304
#opar <- par(fig=c(0.85,0.95,0.8, 0.9), new=TRUE)
300 305
#opar <- par(fig=c(0.8,0.95,0.75, 0.9), new=TRUE)
301 306
#opar <- par(fig=c(0.75,0.95,0.7, 0.9), new=TRUE)
302
opar <- par(fig=c(0.65,0.9,0.8, 0.92), new=TRUE)
307
#opar <- par(fig=c(0.65,0.9,0.8, 0.92), new=TRUE)
308
opar <- par(fig=c(0.66,0.91,0.82, 0.93), new=TRUE)
303 309

  
304 310
plot(usa_map_2,border="black") #border and lwd are options of graphics package polygon object
305 311
plot(usa_map_OR,col="dark grey",add=T)
......
330 336
#temp.colors <- matlab.like(no_brks)
331 337
temp.colors <- colorRampPalette(c('blue', 'khaki', 'red'))
332 338

  
333
png(filename=paste("Figure_3_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=980,height=480)
339
png(filename=paste("Figure_3_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),
340
    width=1200,height=600)
334 341
par(mfrow=c(1,2))
335 342
plot(lst_md,col=temp.colors(25),axes=F) #use axes=F to remove lat and lon or coordinates
336 343
plot(interp_area,add=TRUE)
......
340 347
title("(b) Mean for month of January")
341 348
dev.off()
342 349

  
343
png(filename=paste("Figure_3_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=980,height=480)
350
png(filename=paste("Figure_3_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=1000,height=500)
344 351
par(mfrow=c(1,2))
345 352

  
346 353
p <-levelplot(lst_md,col.regions=temp.colors(25),axes=F,margin=F,scales = list(draw = FALSE), #use list(draw=F) so as  not to dispaly coordinates!!!
......
417 424
y_lab_text <- "MAE (°C)"
418 425
add_CI <- c(TRUE,TRUE,TRUE)
419 426
#Now set up plotting device
420
res_pix<-480
427
#res_pix<- 960
428
#res_pix<- 480
429
res_pix <- 600 #it will be time 2
421 430
col_mfrow<-2
422 431
row_mfrow<-1
423 432
png_file_name<- paste("Figure_4_accuracy_and_distance_to_closest_fitting_station_",out_prefix,".png", sep="")
......
492 501
##### plot figure 5 for paper
493 502
####
494 503

  
495
res_pix<-480
504
#res_pix<-480
505
#res_pix<-960
506
res_pix<- 600 #width will be time 2
496 507
col_mfrow<-2
497 508
row_mfrow<-1
498 509
png_file_name<- paste("Figure_5_proportion_of_holdout_and_accuracy_",out_prefix,".png", sep="")
......
616 627
###############
617 628
#### plot figure 6
618 629
#set up the output file to plot
619
res_pix<-480
630
res_pix <- 600
620 631
col_mfrow<-2
621 632
row_mfrow<-1
622 633
png_file_name<- paste("Figure_6_overtraining_tendency_and_holdout_proportion_",out_prefix,".png", sep="")
......
727 738
y_range<-range(unlist(month_data_list))
728 739

  
729 740
#Now plot figure 14
730
res_pix<-480
741
res_pix<-500
731 742
col_mfrow<-2
732 743
#row_mfrow<-2
733 744
row_mfrow<-1
......
863 874
layout_m<-c(4,3) #one row two columns
864 875

  
865 876
png(paste("Figure_7a_spatial_pattern_tmax_prediction_models_baseline1_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
866
    height=480*layout_m[1],width=480*layout_m[2])
877
    height=500*layout_m[1],width=500*layout_m[2])
867 878

  
868 879
p<- levelplot(pred_temp_s,main="Interpolated Surfaces Model Comparison baseline 1", ylab=NULL,xlab=NULL,
869 880
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
......
903 914
layout_m<-c(4,3) #one row two columns
904 915

  
905 916
png(paste("Figure_7b_spatial_correlogram_tmax_prediction_models_baseline1_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
906
    height=480*layout_m[1],width=480*layout_m[2])
917
    height=500*layout_m[1],width=500*layout_m[2])
907 918

  
908 919
p<-xyplot(data ~ lag | which, dd,type="b",
909 920
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
......
955 966
layout_m<-c(1,2) #one row two columns
956 967

  
957 968
png(paste("Figure_8a_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
958
    height=480*layout_m[1],width=480*layout_m[2])
969
    height=510*layout_m[1],width=510*layout_m[2])
959 970
#X11(height=7*layout_m[1],width=7*layout_m[2])
960 971

  
961 972
names_layers <-c("mod1 = s(lat,long)+s(elev)","mod4 = s(lat,long)+s(LST)")
......
973 984
#col.regions=temp.colors(25))
974 985
dev.off()
975 986

  
976

  
977 987
diff<-raster(lf1$mod1)-raster(lf1$mod4)
978 988
names_layers <- c("mod1-mod4")
979 989
diff<-stack(diff)
......
981 991

  
982 992

  
983 993
png(paste("Figure_8b_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
984
    height=530*1,width=534*1)
994
    height=510*1,width=510*1)
985 995

  
986 996
#plot(diff,col=temp.colors(100),main=names_layers)
987
levelplot(diff,main="(b) Difference  between models", ylab=NULL,xlab=NULL,
997
p_diff<- levelplot(diff,main="(b) Difference  between models", ylab=NULL,xlab=NULL,
988 998
          margin=F,
989 999
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=c(1,1),
990 1000
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
991 1001
          names.attr=names_layers,col.regions=temp.colors)
1002
print(p_diff)
1003
dev.off()
992 1004

  
1005
layout_m <- c(1,3)
1006
png(paste("Figure_8_spatial_pattern_tmax_prediction_models_gam_levelplot_and_difference_",date_selected,out_prefix,".png", sep=""),
1007
    height=500*layout_m[1],width=500*layout_m[2])
1008
grid.arrange(p,p_diff,ncol=3)
993 1009
dev.off()
994 1010

  
995 1011
###############################
......
1163 1179
names(tb_mod4_LST_rec3) <- c("month","p_val_rec3")
1164 1180
tb_mod4_LST_rec3$month <- 1:12
1165 1181

  
1166
res_pix<-480
1182
res_pix <- 500
1167 1183
layout_m <- c(1,3) # works if set to this?? ok set the resolution...      
1168 1184
#date_selected <- c("20100101","20100901")
1169 1185
png(paste("Figure_15_paper_","LST_elev_",out_prefix,".png", sep=""),
......
1300 1316
layout_m <- c(2,2) # works if set to this?? ok set the resolution...      
1301 1317
#date_selected <- c("20100101","20100901")
1302 1318
png(paste("Figure10_paper_","_variogram_",out_prefix,".png", sep=""),
1303
    height=480*layout_m[1],width=480*layout_m[2])
1319
    height=500*layout_m[1],width=500*layout_m[2])
1304 1320
    #height=480*6,width=480*4)
1305 1321
     
1306 1322
p_hist <-histogram(tb_variogram$model,
......
1378 1394

  
1379 1395
layout_m<-c(4,3) # works if set to this?? ok set the resolution...
1380 1396
png(paste("Figure_11_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
1381
    height=480*layout_m[1],width=480*layout_m[2])
1397
    height=500*layout_m[1],width=500*layout_m[2])
1382 1398

  
1383 1399
grid.arrange(list_p[[1]],list_p[[2]],list_p[[3]],
1384 1400
             list_p[[4]],list_p[[5]],list_p[[6]],
......
1389 1405

  
1390 1406
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1391 1407
png(paste("Figure_11a_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
1392
    height=480*layout_m[1],width=480*layout_m[2])
1408
    height=520*layout_m[1],width=520*layout_m[2])
1393 1409

  
1394 1410
grid.arrange(list_p[[1]],list_p[[2]],list_p[[3]],
1395 1411
             ncol=3)  
1396 1412
dev.off() 
1397 1413
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1398 1414
png(paste("Figure_11b_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
1399
    height=480*layout_m[1],width=480*layout_m[2])
1415
    height=520*layout_m[1],width=520*layout_m[2])
1400 1416

  
1401 1417
grid.arrange(list_p[[4]],list_p[[5]],list_p[[6]],
1402 1418
             ncol=3)  
1403 1419
dev.off() 
1404 1420
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1405 1421
png(paste("Figure_11c_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
1406
    height=480*layout_m[1],width=480*layout_m[2])
1422
    height=520*layout_m[1],width=520*layout_m[2])
1407 1423

  
1408 1424
grid.arrange(list_p[[7]],list_p[[8]],list_p[[9]],
1409 1425
             ncol=3)  
1410 1426
dev.off() 
1411 1427
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1412 1428
png(paste("Figure_11d_paper_","_residuals_",date_selected,"_",out_prefix,".png", sep=""),
1413
    height=480*layout_m[1],width=480*layout_m[2])
1429
    height=520*layout_m[1],width=520*layout_m[2])
1414 1430

  
1415 1431
grid.arrange(list_p[[10]],
1416 1432
             ncol=3)  
......
1500 1516

  
1501 1517
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1502 1518
png(paste("Figure12_paper_","average_MAE_","_",out_prefix,".png", sep=""),
1503
    height=480*layout_m[1],width=480*layout_m[2])
1504
X11(height=7*layout_m[1],width=7*layout_m[2])
1519
    height=500*layout_m[1],width=500*layout_m[2])
1520
#X11(height=7*layout_m[1],width=7*layout_m[2])
1505 1521

  
1506 1522
grid.arrange(list_p_mae[[1]],list_p_mae[[2]],list_p_mae[[3]],ncol=3)
1507
savePlot(paste("Figure12_paper_","average_MAE_","_",out_prefix,".png", sep=""), 
1508
         type="png")
1523
#savePlot(paste("Figure12_paper_","average_MAE_","_",out_prefix,".png", sep=""), 
1524
#         type="png")
1509 1525
      
1510 1526
dev.off()   
1511 1527

  
......
1531 1547

  
1532 1548
layout_m <- c(1,3) # works if set to this?? ok set the resolution...      
1533 1549
png(paste("Figure_13_paper_","residuals_MAE_",out_prefix,".png", sep=""),
1534
    height=480*layout_m[1],width=480*layout_m[2])
1550
    height=500*layout_m[1],width=500*layout_m[2])
1535 1551
    #height=480*6,width=480*4)
1536 1552

  
1537 1553
p_bw1<-bwplot(data_v_ag$res_mod1~elev_rcstat,do.out=F,ylim=c(-15,15),
......
1601 1617
#max_val<- -10
1602 1618
#min_val <- 0
1603 1619
layout_m<-c(1,3) #one row, three columns
1604
res_pix <- 480
1620
res_pix <- 500
1605 1621
png(paste("Figure_0a_graphic_abstact_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
1606 1622
    height=res_pix*layout_m[1],width=res_pix*layout_m[2])
1607 1623

  
......
1646 1662
dd$lag <- mydata$lag 
1647 1663

  
1648 1664
layout_m<-c(1,3) #one row three columns
1649
res_pix <-  480
1665
res_pix <-  500
1650 1666
png(paste("Figure_0b_graphic_abstract_spatial_correlogram_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
1651 1667
    height=res_pix*layout_m[1],width=res_pix*layout_m[2])
1652 1668

  

Also available in: Unified diff