Project

General

Profile

« Previous | Next » 

Revision e81e5dff

Added by Benoit Parmentier about 10 years ago

proof paper RS contribution of covar, modification to 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: 08/08/2014            
7
#MODIFIED ON: 09/03/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<-"_07182014"
72
out_prefix<-"_09032014"
73 73
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_contribution_covar_analyses_tables_fig"
74 74
#setwd(out_dir)
75 75

  
......
330 330
#temp.colors <- matlab.like(no_brks)
331 331
temp.colors <- colorRampPalette(c('blue', 'khaki', 'red'))
332 332

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

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

  
346
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!!!
347
              main="(a) Mean for 1 January") #use axes=F to remove lat and lon or coordinates
348
p_shp <- layer(sp.polygons(interp_area, lwd=0.8, col='black'))
349
#title("(a) Mean for 1 January")
350

  
351
p1 <- p+p_shp
352
#plot(interp_area,add=TRUE)
353
p <-levelplot(lst_mm_01,col.regions=temp.colors(25),axes=FALSE,margin=F,scales = list(draw = FALSE),
354
              main="(b) Mean for month of January") #use axes=F to remove lat and lon or coordinates
355

  
356
p2 <- p+p_shp
357

  
358
#plot(lst_mm_01,col=temp.colors(25),axes=F)
359
#plot(interp_area,add=TRUE)
360
#title("(b) Mean for month of January")
361
grid.arrange(p1,p2,ncol=2)
362

  
341 363
dev.off()
342 364

  
343 365
## Calucate the proprotion of missing pixel for January 1 mean climatotology image
......
391 413
plot_dst_MAE(list_param_plot)
392 414

  
393 415
metric_name <-"mae_tb"
394
title_plot <- "MAE and distance to closest fitting station"
416
title_plot <- "(a) MAE and distance to closest fitting station"
395 417
y_lab_text <- "MAE (°C)"
396 418
add_CI <- c(TRUE,TRUE,TRUE)
397 419
#Now set up plotting device
......
416 438
barplot(l1$n_tb$res_mod1,names.arg=limit_val,
417 439
        ylab="Number of observations",
418 440
        xlab="Distance to closest fitting station (km)")
419
title("Number of observation in term of distance bins")
441
title("(b) Number of observations in term of distance bins")
420 442
box()
421 443
dev.off()
422 444

  
......
484 506

  
485 507
#debug(plot_prop_metrics)
486 508
plot_prop_metrics(list_param_plot)
487
title(main="MAE for hold out and methods",
509
title(main="(a) MAE for hold out and methods",
488 510
      xlab="Hold out validation/testing proportion",
489 511
      ylab="MAE (°C)")
490 512

  
......
493 515
list_param_plot<-list(list_prop_obj,col_t,pch_t,legend_text,mod_name,metric_name,add_CI,CI_bar)
494 516
names(list_param_plot)<-c("list_prop_obj","col_t","pch_t","legend_text","mod_name","metric_name","add_CI","CI_bar")
495 517
plot_prop_metrics(list_param_plot)
496
title(main="RMSE for hold out and methods",
518
title(main="(b) RMSE for hold out and methods",
497 519
      xlab="Hold out validation/testing proportion",
498 520
      ylab="RMSE (°C)")
499 521

  
......
645 667
legend("top",legend=legend_text_data, 
646 668
       cex=0.9, lty=c(1,2),bty="n")
647 669

  
648
title(main="Training and testing RMSE for hold out and methods",
670
title(main="(a) Training and testing RMSE for hold out and methods",
649 671
      xlab="Hold out validation/testing proportion",
650 672
      ylab="RMSE (°C)")
651 673

  
652 674

  
653 675
boxplot(diff_mae_data_mult[-4]) #plot differences in training and testing accuracies for three methods
654 676

  
655
title(main="Difference between training and testing MAE",
677
title(main="(b) Difference between training and testing MAE",
656 678
      xlab="Interpolation method",
657 679
      ylab="MAE (°C)")
658 680

  
......
727 749
lines(1:12,tb3_month$mae,col=c("blue"),type="b")
728 750
lines(1:12,tb4_month$mae,col=c("black"),type="b")
729 751
axis(1,at=1:12,labels=xlab_tick)
730
title(main="Monthly average MAE")
752
title(main="(a) Monthly average MAE")
731 753
legend("topleft",legend=legend_text, 
732 754
       cex=0.9, pch=c(pch_t),col=c(col_t),lty=c(1,1,1),bty="n")
733 755

  
734 756
#Second plot
735 757
ylab_text<-"MAE (°C)"
736 758
xlab_text<-"Month"
737
boxplot(mae~month,data=month_data_list$gam,main="Monthly MAE boxplot", xlab=xlab_text,ylab=ylab_text,outline=FALSE)
759
boxplot(mae~month,data=month_data_list$gam,main="(b) Monthly MAE boxplot", xlab=xlab_text,ylab=ylab_text,outline=FALSE)
738 760
dev.off()
739 761

  
740 762
#Now generate table 5
......
888 910
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
889 911
          strip=strip.custom(factor.levels=names_layers),
890 912
          xlab=list(label="Spatial lag neighbor", cex=2,font=2),
891
          ylab=list(label="Moran's I", cex=2, font=2))
913
          ylab=list(label="Moran's I", cex=2, font=2),
914
          as.table=TRUE) #as.table controls the order  of the pannels!!
892 915
print(p)
893 916

  
894 917
dev.off()
......
933 956

  
934 957
png(paste("Figure_8a_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
935 958
    height=480*layout_m[1],width=480*layout_m[2])
959
#X11(height=7*layout_m[1],width=7*layout_m[2])
936 960

  
937
p<-levelplot(pred_temp_s,main="Interpolated Surfaces Model Comparison", ylab=NULL,xlab=NULL,
961
names_layers <-c("mod1 = s(lat,long)+s(elev)","mod4 = s(lat,long)+s(LST)")
962

  
963
p<-levelplot(pred_temp_s,main="(a) Interpolated Surfaces Model Comparison", ylab=NULL,xlab=NULL,
938 964
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
939 965
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
940 966
          names.attr=names_layers,col.regions=temp.colors,at=seq(max_val,min_val,by=0.01))
941 967
#col.regions=temp.colors(25))
942 968
print(p)
969

  
970
#savePlot(paste("Figure_8a_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""), 
971
#         type="png")
972

  
943 973
#col.regions=temp.colors(25))
944 974
dev.off()
945 975

  
946 976

  
947 977
diff<-raster(lf1$mod1)-raster(lf1$mod4)
948
names_layers <- c("difference=mod1-mod4")
978
names_layers <- c("mod1-mod4")
979
diff<-stack(diff)
949 980
names(diff) <- names_layers
950 981

  
951 982

  
952 983
png(paste("Figure_8b_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
953
    height=480*layout_m[1],width=480*layout_m[2])
984
    height=530*1,width=534*1)
954 985

  
955
plot(diff,col=temp.colors(100),main=names_layers)
956
#levelplot(diff,main="Interpolated Surfaces Model Comparison", ylab=NULL,xlab=NULL,
957
#          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=c(1,1),
958
#                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
959
#          names.attr=names_layers,col.regions=temp.colors)
960
dev.off
986
#plot(diff,col=temp.colors(100),main=names_layers)
987
levelplot(diff,main="(b) Difference  between models", ylab=NULL,xlab=NULL,
988
          margin=F,
989
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=c(1,1),
990
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
991
          names.attr=names_layers,col.regions=temp.colors)
992

  
993
dev.off()
961 994

  
962 995
###############################
963 996
########## Prepare table 6
......
1075 1108
plot(tb_sig_p_val_rec2)
1076 1109
#Now prepare 
1077 1110
s_table_LST_mod4 <- subset(s.table_term_tb,mod_name=="mod4" & term_name=="s(LST)")
1078
tb_mod4_LST_rec3 <- aggregate(s_table_LST_mod4$p_val_rec3~s_table_term_mod4$month,FUN=mean)
1111
#tb_mod4_LST_rec3 <- aggregate(s_table_LST_mod4$p_val_rec3~s_table_term_mod4$month,FUN=mean)
1112
tb_mod4_LST_rec3 <- aggregate(s_table_LST_mod4$p_val_rec3~s_table_LST_mod4$month,FUN=mean)
1113

  
1079 1114
plot(tb_mod4_LST_rec3,type="l",ylim=c(0.2,1))
1080 1115
s_table_elev_mod4 <- subset(s.table_term_tb,mod_name=="mod4" & term_name=="s(elev_s)")
1081 1116
#tb_mod4_elev_rec3 <- aggregate(tb_mod4_elev_rec3$p_val_rec2 ~ tb_mod4_elev_rec3$month,FUN=mean)
1117

  
1082 1118
plot(tb_mod4_elev_rec3)
1083 1119
lines(tb_mod4_elev_rec3)
1084 1120
test1 <- subset(s.table_term_tb,mod_name=="mod1" & term_name=="s(elev_s)")
......
1139 1175
          type="b",
1140 1176
          ylab=list(label="\u0394RMSE between mod1 and mod4",cex=1.5),
1141 1177
          xlab=list(label="Month",cex=1.5),
1142
          main=list(label="Proportion of significant LST term in mod4",cex=1.8))
1178
          main=list(label="(a) Proportion of significant LST term in mod4",cex=1.8))
1143 1179
p_prop <- update(p_prop,par.settings = list(axis.text = list(font = 2, cex = 1.3),
1144 1180
                par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5))
1145 1181

  
......
1148 1184
          type="b",
1149 1185
          ylab=list(label="\u0394RMSE between mod1 and mod4",cex=1.5),
1150 1186
          xlab=list(label="Month",cex=1.5),
1151
          main=list(label="Monthly \u0394RMSE betwen mod1 and mod4",cex=1.8),
1187
          main=list(label="(b) Monthly \u0394RMSE betwen mod1 and mod4",cex=1.8),
1152 1188
          par.settings = list(axis.text = list(font = 2, cex = 1.3),
1153 1189
          par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5))
1154 1190
p_dif <- update(p_dif, panel = function(...) {
......
1166 1202
          ylim=c(-1,1),
1167 1203
          ylab=list(label="Pearson Correlation",cex=1.5),
1168 1204
          xlab=list(label="Month",cex=1.5),
1169
          main=list(label="Pearson Correlation",cex=1.8),
1205
          main=list(label="(c) Pearson Correlation",cex=1.8),
1170 1206
          auto.key = list("topright", corner = c(0,1),# col=c("black","red"),
1171 1207
                     border = FALSE, lines = TRUE,cex=1.2))
1172 1208
p_cor <- update(p_cor, panel = function(...) {
......
1223 1259
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,
1224 1260
         ylim=c(0,9),
1225 1261
         ylab=list(label="Semivariance",cex=1.5),
1226
         xlab=list(label="Distance (meter)",cex=1.5),
1227
         main=list(label="Mod1 January 1, 2010",cex=1.8),
1262
         xlab=list(label="Distance (m)",cex=1.5),
1263
         main=list(label="(a) Mod1 1 January 2010",cex=1.8),
1228 1264
         par.settings = list(axis.text = list(font = 2, cex = 1.3), #control the font size!!
1229 1265
                par.main.text=list(font=2,cex=2),strip.background=list(col="white")),
1230 1266
                par.strip.text=list(font=2,cex=1.5)
......
1233 1269
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,
1234 1270
         ylim=c(0,9),
1235 1271
         ylab=list(label="Semivariance",cex=1.5),
1236
         xlab=list(label="Distance (meter)",cex=1.5),
1237
         main=list(label="Mod1 September 1, 2010",cex=1.8),
1272
         xlab=list(label="Distance (m)",cex=1.5),
1273
         main=list(label="(b) Mod1 1 September 2010",cex=1.8),
1238 1274
         par.settings = list(axis.text = list(font = 2, cex = 1.3),
1239 1275
                par.main.text=list(font=2,cex=2),strip.background=list(col="white")),
1240 1276
                par.strip.text=list(font=2,cex=1.5)
......
1271 1307
          col=c("grey"),
1272 1308
          ylab=list(label="Percent of total",cex=1.5),
1273 1309
          xlab=list(label="Variogram model",cex=1.5),
1274
          main=list(label="Variogram model type",cex=1.8))
1310
          main=list(label="(a) Variogram model type",cex=1.8))
1275 1311

  
1276 1312
p_bw1<- bwplot(tb_variogram$range~tb_variogram$month,do.out=F,ylim=c(0,250000),
1277 1313
         ylab=list(label="Range of variograms",cex=1.5),
1278 1314
         xlab=list(label="Month",cex=1.5),
1279
         main=list(label="Mod1 range",cex=1.8))
1315
         main=list(label="(b) Mod1 range",cex=1.8))
1280 1316
p_bw2<-bwplot(tb_variogram$Nug~tb_variogram$month,do.out=F,ylim=c(0,12),
1281 1317
         ylab=list(label="Nugget of variograms",cex=1.5),
1282 1318
         xlab=list(label="Month",cex=1.5),
1283
         main=list(label="Mod1 Nugget",cex=1.8))
1319
         main=list(label="(c) Mod1 Nugget",cex=1.8))
1284 1320
p_bw3<-bwplot(tb_variogram$psill~tb_variogram$month,do.out=F,ylim=c(0,30),
1285 1321
         ylab=list(label="Sill of variograms",cex=1.5),
1286 1322
         xlab=list(label="Month",cex=1.5),
1287
         main=list(label="Mod1 sill",cex=1.8))
1323
         main=list(label="(d) Mod1 sill",cex=1.8))
1288 1324
#grid.arrange(p1,p2,p3,ncol=1)
1289 1325
grid.arrange(p_hist,p_bw1,p_bw2,p_bw3,ncol=2)
1290 1326

  
......
1306 1342
day<-as.integer(strftime(date_proc, "%d"))
1307 1343
year<-as.integer(strftime(date_proc, "%Y"))
1308 1344
datelabel=format(ISOdate(year,mo,day),"%b %d, %Y")
1309

  
1345
datelabel <- format(ISOdate(year,mo,day),"%d-%m-%Y")
1310 1346
#height=480*6,width=480*4)
1311 1347
list_p <- vector("list", length(names_mod))
1312 1348
for (k in 1:length(names_mod)){
......
1379 1415
grid.arrange(list_p[[10]],
1380 1416
             ncol=3)  
1381 1417
dev.off() 
1418

  
1382 1419
###########################################
1383 1420
### Figure 12: map of MAE by stations over 365 days to summarize residuals information
1384 1421

  
......
1439 1476
elev <- subset(s_raster,"elev_s")
1440 1477
list_p_mae <- vector("list", 3)
1441 1478
names_var <- c("mod1","mod2","mod5")
1479
plot_nb <- c("(a)","(b)","(c)")
1442 1480
for (k in 1:length(names_var)){
1443 1481
  
1444 1482
  model_name <- names_var[k]
1483
  nb_p <- plot_nb[k]
1445 1484
  res_model_name <- paste("res",model_name,sep="_")
1485
  
1446 1486
  #res_model_name <- "res_mod1"
1447 1487
  p1 <- levelplot(elev,scales = list(draw = FALSE), colorkey = FALSE,par.settings = GrTheme)
1448 1488
  #tt <- na.omit(data_v_mae)
1449 1489
  #df_tmp=subset(data_v_mae,data_v_mae$res_mod1!="NaN")
1450 1490
  df_tmp=subset(data_v_mae,data_v_mae[[res_model_name]]!="NaN")
1451 1491
  
1452
  p2 <- bubble(df_tmp,res_model_name, main=paste("Average MAE per station for ",model_name,sep=""),
1492
  p2 <- bubble(df_tmp,res_model_name, main=paste(nb_p," Average MAE per station for ",model_name,sep=""),
1453 1493
               col=matlab.like(5),na.rm=TRUE)
1454 1494
  p3 <- p2 + p1 + p2 #to force legend...
1455 1495
  #print(p3)
......
1459 1499
}
1460 1500

  
1461 1501
layout_m<-c(1,3) # works if set to this?? ok set the resolution...
1462
png(paste("Figure12_paper_","average_MAE_",date_selected,"_",out_prefix,".png", sep=""),
1502
png(paste("Figure12_paper_","average_MAE_","_",out_prefix,".png", sep=""),
1463 1503
    height=480*layout_m[1],width=480*layout_m[2])
1504
X11(height=7*layout_m[1],width=7*layout_m[2])
1464 1505

  
1465 1506
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")
1466 1509
      
1467 1510
dev.off()   
1468 1511

  
......
1494 1537
p_bw1<-bwplot(data_v_ag$res_mod1~elev_rcstat,do.out=F,ylim=c(-15,15),
1495 1538
         ylab=list(label="Residuals (deg C)",cex=1.5),
1496 1539
         xlab=list(label="Elevation classes (meter)",cex=1.5),
1497
         main=list(label="Residuals vs elev for mod1=lat*lon",cex=1.8),
1540
         main=list(label="(a) Residuals vs elev for mod1=lat*lon",cex=1.8),
1498 1541
         scales = list(x = list(at = c(1, 2, 3, 4), #provide tick location and labels
1499 1542
                               labels = c("0-500","500-1000","1000-1500","1500-2000"))),
1500 1543
                       par.settings = list(axis.text = list(font = 2, cex = 1.3), #control the font size!!
......
1505 1548
p_bw2 <- bwplot(data_v_ag$res_mod5~elev_rcstat,do.out=F,ylim=c(-15,15),
1506 1549
         ylab=list(label="Residuals (deg C)",cex=1.5),
1507 1550
         xlab=list(label="Elevation classes (meter)",cex=1.5),
1508
         main=list(label="Residuals vs elev for mod5=lat*lon+LST",cex=1.8),
1551
         main=list(label="(b) Residuals vs elev for mod5=lat*lon+LST",cex=1.8),
1509 1552
         scales = list(x = list(at = c(1, 2, 3, 4), 
1510 1553
                               labels = c("0-500","500-1000","1000-1500","1500-2000"))),
1511 1554
         par.settings = list(axis.text = list(font = 2, cex = 1.3), #control the font size!!
......
1516 1559
p_bw3 <- bwplot(data_v_ag$res_mod2~elev_rcstat,do.out=F,ylim=c(-15,15),
1517 1560
         ylab=list(label="Residuals (deg C)",cex=1.5),
1518 1561
         xlab=list(label="Elevation classes (meter)",cex=1.5),
1519
         main=list(label="Residuals vs elev for mod2=lat*lon+elev",cex=1.8),
1562
         main=list(label="(c) Residuals vs elev for mod2=lat*lon+elev",cex=1.8),
1520 1563
         scales = list(x = list(at = c(1, 2, 3, 4), 
1521 1564
                               labels = c("0-500","500-1000","1000-1500","1500-2000"))),
1522 1565
         par.settings = list(axis.text = list(font = 2, cex = 1.3), #control the font size!!

Also available in: Unified diff