Project

General

Profile

« Previous | Next » 

Revision 6926110f

Added by Benoit Parmentier over 10 years ago

multi timescale paper, revisions draft2 major reorganizations of figures and analyses

View differences:

climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R
7 7
#Analyses, figures, tables and data for the  paper are also produced in the script.
8 8
#AUTHOR: Benoit Parmentier 
9 9
#CREATED ON: 10/31/2013  
10
#MODIFIED ON: 03/06/2014            
10
#MODIFIED ON: 03/18/2014            
11 11
#Version: 3
12 12
#PROJECT: Environmental Layers project                                     
13 13
#################################################################################################
......
37 37
library(gridExtra)
38 38
#Additional libraries not used in workflow
39 39
library(pgirmess)                            # Krusall Wallis test with mulitple options, Kruskalmc {pgirmess}  
40
library(colorRamps)
40 41

  
41 42
#### FUNCTION USED IN SCRIPT
42 43

  
43 44
function_analyses_paper1 <-"contribution_of_covariates_paper_interpolation_functions_10222013.R" #first interp paper
44
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_12252013.R"
45
function_analyses_paper2 <-"multi_timescales_paper_interpolation_functions_03182014.R"
45 46

  
46 47
##############################
47 48
#### Parameters and constants  
......
110 111
                                 "gam_fss","kriging_fss","gwr_fss")
111 112

  
112 113
y_var_name <- "dailyTmax"
113
out_prefix<-"analyses_03062013"
114
out_prefix<-"analyses_03142013"
114 115
out_dir<-"/home/parmentier/Data/IPLANT_project/paper_multitime_scale__analyses_tables"
115 116
out_dir <-paste(out_dir,"_",out_prefix,sep="")
116 117

  
......
251 252
#######################################################
252 253
####### PART 2: generate figures for paper #############
253 254

  
254
#Figure annex: LST climatology production: daily mean compared to monthly mean: moved to appendix
255

  
256
#figure 1: Study area OR
257
#Figure 2. Accuracy and monthly hold out for FSS and CAI procedures and GWR, Kriging and GAM methods.
255
#figure 1: Study area Oregon state with GHCND stations
256
#Figure 2. Accuracy and monthly hold out for CAI procedures and GWR, Kriging and GAM methods.
258 257
#Figure 3. Overtraining tendency, difference between training and testing
259 258
#Figure 4: Spatial pattern of prediction for one day (3 maps)
260
#Figure 5: Transect location (transect map)
261
#Figure 6: Transect profiles for one day 
262
#Figure 7: Image differencing and land cover: spatial patterns   
263
#Figure 8: LST and Tmax at stations, elevation and land cover.
264
#Figure 9: Spatial lag profiles for predicted surfaces 
265
#Figure 10: Daily deviation
266
#Figure 11: Spatial correlogram at stations, LST and elevation every 5 lags
259
#Figure 5: Spatial lag profiles for predicted surfaces 
260
#Figure 6: Granularity, Moran's I and standard deviation averaged monthly 
261
#Figure 7: Daily deviation and long term surfaces
262
#Figure 8: LST and air temperature, elevation and land cover across OR
263

  
264
#ANNEX FIGURES: (end of script)
265

  
266
#Figure annex 1: LST averages daily and monthly for January 1 and January
267
#Figure annex 2: Transect location (transect map)
268
#Figure annex 3: Transect profiles for one day 
267 269

  
268 270
################################################
269 271
######### Figure 1: Oregon study area, add labeling names to  Willamette Valley an Mountain Ranges?
......
279 281
interp_area <- readOGR(dsn=dirname(infile_reg_outline),sub(".shp","",basename(infile_reg_outline)))
280 282
interp_area_WGS84 <-spTransform(interp_area,CRS_locs_WGS84)         # Project from WGS84 to new coord. system
281 283

  
282
usa_map <- getData('GADM', country='USA', level=1) #Get US map
284
#usa_map <- getData('GADM', country='USA', level=1) #Get US map
285
usa_map <- getData('GADM', country='USA') #Get US map, this is not working right now
286

  
283 287
usa_map_2 <- usa_map[usa_map$NAME_1!="Alaska",] #remove Alaska
284 288
usa_map_2 <- usa_map_2[usa_map_2$NAME_1!="Hawaii",] #remove Hawai 
285 289
usa_map_OR <- usa_map_2[usa_map_2$NAME_1=="Oregon",] #get OR
......
316 320
box()
317 321
dev.off()
318 322

  
319
################################################
320
######### Figure Annex: LST averaging: daily mean compared to monthly mean
321

  
322
#This is now moved in Annex
323

  
324
lst_md <- raster(ref_rast_name)
325
projection(lst_md)<-projection(s_raster)
326
lst_mm_09<-subset(s_raster,"mm_09")
327

  
328
lst_md<-raster(ref_rast_d001)
329
lst_md<- lst_md - 273.16
330
lst_mm_01<-subset(s_raster,"mm_01")
331

  
332
png(filename=paste("Figure_annex1_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
333
par(mfrow=c(1,2))
334
plot(lst_md)
335
plot(interp_area,add=TRUE)
336
title("Mean for January 1")
337
plot(lst_mm_01)
338
plot(interp_area,add=TRUE)
339
title("Mean for month of January")
340
dev.off()
341 323

  
342 324
################################################
343 325
######### Figure 3. RMSE multi-timescale mulitple hold out for FSS and CAI
......
373 355
plot_names <- names(list_tb) #this is the default names for the plots
374 356
#now replace names for relevant figure used later on.
375 357
plot_names[7:12] <- c("RMSE for gam_FSS","RMSE for kriging_FSS","RMSE for gwr_FSS",
376
              o "RMSE for gam_CAI","RMSE for kriging_CAI","RMSE for gwr_CAI")
358
               "RMSE for gam_CAI","RMSE for kriging_CAI","RMSE for gwr_CAI")
377 359
#Quick function to explore accuracy make this a function to create solo figure...and run only a subset...
378 360

  
379 361
#list_plots <- plot_accuracy_by_holdout_fun(list_tb,ac_metric,plot_names,names_mod)
......
383 365
names(tb_obj$list_avg_tb[selected_df]) #names of method  and validation set selected
384 366
avg_tb_ac <- do.call(rbind.fill,tb_obj$list_avg_tb[selected_df])
385 367

  
386
layout_m<-c(1,1.5) #one row two columns
368
## We use only CAI results
369

  
370
avg_tb_ac <- subset(avg_tb_ac, method_interp %in% c("gam_CAI","kriging_CAI","gwr_CAI"))
371

  
372
#avg_tb_ac <- avg_tb_ac[, avg_tb_ac$method_interp %in% c("gam_CAI","kriging_CAI","gwr_CAI")]
373

  
374
layout_m<-c(1,2.5) #one row two columns
387 375

  
388 376
png(paste("Figure2_paper_accuracy_",ac_metric,"_prop_month","_",out_prefix,".png", sep=""),
389 377
    height=480*layout_m[1],width=480*layout_m[2])
......
392 380
            group=pred_mod,data=avg_tb_ac, #group by model (covariates)
393 381
            main="RME by monthly hold-out proportions and  interpolation methods",
394 382
            type="b",as.table=TRUE,
395
            index.cond=list(c(1,5,3,2,6,4)),    #this provides the order of the panels)
396
            pch=1:length(avg_tb$pred_mod),
383
            index.cond=list(c(1,3,2)),    #this provides the order of the panels)
384
            pch=1:length(avg_tb_ac$pred_mod),
397 385
            par.settings=list(superpose.symbol = list(
398
            pch=1:length(avg_tb$pred_mod))),
386
            pch=1:length(avg_tb_ac$pred_mod))),
399 387
            auto.key=list(columns=1,space="right",title="Model",cex=1),
400 388
            #auto.key=list(columns=5),
401 389
            xlab="Monthly Hold out proportion",
402 390
            ylab="RMSE (°C)")
403 391
print(p)
392

  
404 393
dev.off()
405 394

  
406 395
################################################
......
439 428
                                         "gam_CAI","kriging_CAI","gwr_CAI")
440 429

  
441 430
## Now create boxplots...
442
layout_m<-c(2,2) #one row two columns
431
layout_m<-c(1,2) #one row two columns
443 432

  
444 433
png(paste("Figure3_paper_boxplot_overtraining_",out_prefix,".png", sep=""),
445 434
    height=480*layout_m[1],width=480*layout_m[2])
......
449 438

  
450 439
#monthly CAI
451 440
boxplot(list_m_diff$kriging_CAI$rmse,list_m_diff$gam_CAI$rmse,list_m_diff$gwr_CAI$rmse,
452
        ylim=c(-9,1), outline=TRUE,
441
        ylim=c(-6,1), outline=TRUE,
453 442
        names=c("kriging_CAI","gam_CAI","gwr_CAI"),ylab="RMSE (°C)",xlab="Interpolation Method",
454 443
        main="Difference between training and testing for monhtly rmse")
455 444
legend("topleft",legend=c("a"),bty="n") #bty="n", don't put box around legend
456 445

  
457 446
#monthly fss
458
boxplot(list_m_diff$kriging_fss$rmse,list_m_diff$gam_fss$rmse,list_diff$gwr_fss$rmse,
459
        ylim=c(-9,1),outline=TRUE,
460
        names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method",
461
        main="Difference between training and testing for monhtly rmse")
462
legend("topleft",legend=c("c"),bty="n")
447
#boxplot(list_m_diff$kriging_fss$rmse,list_m_diff$gam_fss$rmse,list_diff$gwr_fss$rmse,
448
#        ylim=c(-9,1),outline=TRUE,
449
#        names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method",
450
#        main="Difference between training and testing for monhtly rmse")
451
#legend("topleft",legend=c("c"),bty="n")
463 452

  
464 453
#daily CAI
465 454
boxplot(list_diff$kriging_CAI$rmse,list_diff$gam_CAI$rmse,list_diff$gwr_CAI$rmse,
466
        ylim=c(-12,1.5),outline=TRUE,
455
        ylim=c(-6,1.5),outline=TRUE,
467 456
        names=c("kriging_CAI","gam_CAI","gwr_CAI"),ylab="RMSE (°C)",xlab="Interpolation Method",
468 457
        main="Difference between training and testing daily rmse")
469 458
legend("topleft",legend=c("b"),bty="n")
470 459

  
471 460

  
472 461
#daily fss
473
boxplot(list_diff$kriging_fss$rmse,list_diff$gam_fss$rmse,list_diff$gwr_fss$rmse,
474
        ylim=c(-12,1.5),outline=TRUE,
475
        names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method",
476
        main="Difference between training and testing daily rmse")
477
legend("topleft",legend=c("d"),bty="n")
462
#boxplot(list_diff$kriging_fss$rmse,list_diff$gam_fss$rmse,list_diff$gwr_fss$rmse,
463
#        ylim=c(-12,1.5),outline=TRUE,
464
#        names=c("kriging_FSS","gam_FSS","gwr_FSS"),ylab="RMSE (°C)",xlab="Interpolation Method",
465
#        main="Difference between training and testing daily rmse")
466
#legend("topleft",legend=c("d"),bty="n")
478 467

  
479 468
dev.off()
480 469

  
......
492 481
#methods_names <-c("gam","kriging","gwr")
493 482
methods_names <-c("gam_daily","gam_CAI","gam_FSS")
494 483

  
495
names_layers<-methods_names
484
names_layers<-methods_names[1:2]
496 485
#lf <- (list(lf1,lf4[1:7],lf7[1:7]))
497
lf<-list(lf_list[[1]],lf_list[[2]][1:7],lf_list[[3]][1:7])
486
#lf<-list(lf_list[[1]],lf_list[[2]][1:7],lf_list[[3]][1:7])
487
lf<-list(lf_list[[1]],lf_list[[2]][1:7])
498 488

  
499
names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
489
names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + elev + N_w*E_w",
500 490
                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
501
nb_fig<- c("4a","4b","4c")
491
nb_fig<- c("4a","4b")
502 492
list_plots_spt <- vector("list",length=length(lf))
503 493
for (i in 1:length(lf)){
504 494
  pred_temp_s <-stack(lf[[i]])
......
520 510
  png(paste("Figure_",nb_fig[i],"_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
521 511
    height=480*layout_m[1],width=480*layout_m[2])
522 512

  
523
  p <- levelplot(pred_temp_s,main=methods_names[i], ylab=NULL,xlab=NULL,
524
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
525
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
513
  p <- levelplot(pred_temp_s,main=methods_names[i], 
514
                 ylab=NULL,xlab=NULL,
515
          par.settings = list(axis.text = list(font = 2, cex = 2),layout=layout_m,
516
                              par.main.text=list(font=2,cex=2.5),strip.background=list(col="white")),par.strip.text=list(font=2,cex=2),
526 517
          names.attr=names_layers,col.regions=temp.colors(no_brks),at=seq(min_val,max_val,by=0.1))
527 518
  #col.regions=temp.colors(25))
528 519
  print(p)
......
539 530

  
540 531
p1 <- list_plots_spt[[1]]
541 532
p2 <- list_plots_spt[[2]]
542
p3 <- list_plots_spt[[3]]
543

  
544
grid.arrange(p1,p2,p3,ncol=1)
545
dev.off()
546

  
547
################################################
548
#Figure 5 and Figure 6: Spatial transects for one day (maps)
549

  
550
#######Figure 5: Map of transects
551

  
552
## Transects image location in OR  
553
layout_m<-c(1,1)
554
png(paste("Figure5_paper_elevation_transect_paths_",out_prefix,".png", sep=""),
555
    height=480*layout_m[1],width=480*layout_m[2])
556
vx_text <- c(395770.1,395770.1,395770.1) #location of labels
557
vy_text  <-c(473000,297045.9,112611.5)
558

  
559
plot(elev)
560
for(i in 1:length(transect_list)){
561
  filename<-sub(".shp","",transect_list[i])             #Removing the extension from file.
562
  transect<-readOGR(dirname(filename), basename(filename))                 #reading shapefile 
563
  #transect2 <- elide(transect, shift=c(0, -24000))
564
  #plot(transect2,add=TRUE)
565
  #writeOGR(transect2,dsn=".",layer="transect_OR_1_12282013",driver="ESRI Shapefile")
566
  plot(transect,add=TRUE)
567
}
568
text(x=vx_text,y=vy_text,labels=c("Transect 1","Transect 2","Transect 3"))
569
title("Transect Oregon")
570
dev.off()
571

  
572
######Figure 6: TRANSECT PROFILES
573
nb_transect <- 3
574
list_transect2<-vector("list",nb_transect)
575
list_transect3<-vector("list",nb_transect)
576
list_transect4<-vector("list",nb_transect)
577

  
578
#names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
579
#                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
580

  
581
rast_pred<-stack(lf[[2]]) #GAM_CAI
582
rast_pred_selected2<-subset(rast_pred,c(1,2,6)) #3 is referring to FSS, plot it first because it has the
583
rast_pred_selected3<-subset(rast_pred,c(1,3,6)) #3 is referring to FSS, plot it first because it has the
584
                                          # the largest range.
585
rast_pred2 <- stack(rast_pred_selected2,subset(s_raster,"elev_s"))
586
rast_pred3 <- stack(rast_pred_selected3,subset(s_raster,"elev_s"))
587

  
588
#layers_names<-layerNames(rast_pred2)<-c("lat*lon","lat*lon + elev + LST","elev")
589
layers_names2 <- names(rast_pred2)<-c("mod1","mod2","mod6","elev")
590
layers_names3 <- names(rast_pred3)<-c("mod1","mod3","mod6","elev")
591
#pos<-c(1,2) # postions in the layer prection
592
#transect_list
593
list_transect2[[1]]<-c(transect_list[1],paste("Figure6a_paper_tmax_elevation_transect1_OR_",date_selected,
594
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
595
list_transect2[[2]]<-c(transect_list[2],paste("Figure6b_tmax_elevation_transect2_OR_",date_selected,
596
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
597
list_transect2[[3]]<-c(transect_list[3],paste("Figure6c_paper_tmax_elevation_transect3_OR_",date_selected,
598
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
599

  
600
list_transect3[[1]]<-c(transect_list[1],paste("Figure6a_tmax_elevation_transect1_OR_",date_selected,
601
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
602
list_transect3[[2]]<-c(transect_list[2],paste("Figure6b_tmax_elevation_transect2_OR_",date_selected,
603
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
604
list_transect3[[3]]<-c(transect_list[3],paste("Figure6c_tmax_elevation_transect3_OR_",date_selected,
605
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
606

  
607
names(list_transect2)<-c("Oregon Transect 1","Oregon Transect 2","Oregon Transect 3")
608
names(list_transect3)<-c("Oregon Transect 1","Oregon Transect 2","Oregon Transect 3")
609

  
610
names(rast_pred2)<-layers_names2
611
names(rast_pred3)<-layers_names3
612

  
613
title_plot2<-paste(names(list_transect2),"on",date_selected,sep=" ")
614
#title_plot2<-paste(names(list_transect2),"on",date_selected,sep=" ")
615

  
616
#title_plot2<-paste(rep("Oregon transect on ",3), date_selected,sep="")
617
#title_plot3<-paste(names(list_transect3),date_selected,sep=" ")
618
#title_plot3<-paste(rep("Oregon transect on ",3), date_selected,sep="")
619

  
620
#r_stack<-rast_pred
621
#m_layers_sc<-c(3) #elevation in the third layer
622
m_layers_sc<-c(4) #elevation in the third layer
623

  
624
#title_plot2
625
#rast_pred2
626
#debug(plot_transect_m2)
627
trans_data2 <- plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc)
628
trans_data3 <- plot_transect_m2(list_transect3,rast_pred3,title_plot2,disp=FALSE,m_layers_sc)
629

  
630
################################################
631
#Figure7: Spatial pattern: Image differencing  
632
#Do for january and September...?
633

  
634
#names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
635
#                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
636

  
637
methods_name <-c("gam_daily","gam_CAI","gam_fss")
638
index<-244 #index corresponding to Sept 1
639
y_var_name <-"dailyTmax"
640
ref_mod <- 3 #mod3
641
alt_mod <- 6 #mod6
642
file_format <- ".rst"
643
NA_flag_val <- -9999
644

  
645
list_param_diff <- list(index,list_raster_obj_files,methods_name,y_var_name,ref_mod,alt_mod,NA_flag_val,file_format,out_dir,out_prefix)
646
names(list_param_diff) <- c("index","list_raster_obj_files","methods_name","y_var_name","ref_mod","alt_mod","NA_flag_val","file_format","out_dir","out_prefix")
647

  
648
#diff_list <- mclapply(1:365, list_param=list_param_diff, FUN=diff_date_rast_pred_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
649

  
650
diff_pred_date1_list<- diff_date_rast_pred_fun(1,list_param_diff)
651
diff_pred_date2_list<- diff_date_rast_pred_fun(244,list_param_diff)
652
r_stack_diff <-stack(c(diff_pred_date1_list,diff_pred_date2_list))
653
names(r_stack_diff) <- c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS")
654
temp.colors <- colorRampPalette(c('blue', 'white', 'red'))
655
#temp.colors <- colorRampPalette(c('blue', 'white', 'red'))
656
layout_m<-c(2,3) #one row two columns
657
png(paste("Figure7_paper_difference_image_",out_prefix,".png", sep=""),
658
    height=480*layout_m[1],width=480*layout_m[2])
659
#plot(r_stack_diff,col=temp.colors(25))
660
#r_diff1<-subset(r_stack_diff,1:3)
661
#r_diff2<-subset(r_stack_diff,4:6)
662
#p1<-levelplot(r_diff1, col.regions=matlab.like(100)) #January
663
#p2<-levelplot(r_diff2,col.regions=matlab.like(100)) #January
664

  
665
#p1<-levelplot(r_stack_diff,layers=1:3, col.regions=matlab.like(100)) #January
666
#p2<-levelplot(r_stack_diff,layers=4:6, col.regions=matlab.like(100)) #January
667
#grid.arrange(p1,p2,ncol=1)
668
levelplot(r_stack_diff,col.regions=matlab.like(100),
669
          ylab=NULL,xlab=NULL,
670
          par.settings = list(axis.text = list(font = 2, cex = 2),layout=layout_m,
671
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
672
) #January
673
dev.off()
674
###
675

  
676
#scales=list(log="e",x=list(cex=.3),y=list(cex=.3)) #change font size
677

  
678
####################################################################
679
#Figure 10: LST and Tmax at stations, elevation and land cover.
680

  
681
LC_subset <- c("LC1","LC5","LC6","LC7","LC9","LC11")  
682
LC_names <- c("LC1_forest", "LC5_shrub", "LC6_grass", "LC7_crop", "LC9_urban","LC11_barren")
683
LC_s <- subset(s_raster,LC_subset)
684
names(LC_s) <- LC_names
685
plot(LC_s)
686

  
687
avl<-c(0,10,1,10,20,2,20,30,3,30,40,4,40,50,5,50,60,6,60,70,7,70,80,8,80,90,9,90,100,10)#Note that category 1 does not include 0!!
533
#p3 <- list_plots_spt[[3]]
688 534

  
689
stat_list <- extract_diff_by_landcover(r_stack_diff,s_raster,LC_subset,LC_names,avl)
690

  
691
#r_subset_name <- "elev_s"
692
#r_names <- c("elev_s")
693
#stat_list_elev <- extract_diff_by_landcover(r_stack_diff,s_raster,LC_subset,LC_names,avl)
694
#write_out_raster_fun(s_raster,out_suffix=out_prefix,out_dir=out_dir,NA_flag_val=-9999,file_format=".rst")
695

  
696
#show correlation with LST by day over the year, ok writeout s_raster of coveriate??
697

  
698
title_plots_list <-c("Jan_Daily","Jan_CAI","Jan_FSS","Sept_Daily","Sept_CAI","Sept_FSS")
699
#reorder the list
700
order_list<- c(1,4,2,5,3,6)
701

  
702
## Now create plots
703
layout_m<-c(3,2) #one row two columns
704
#savePlot(paste("fig6_diff_prediction_tmax_difference_land cover",mf_selected,mc_selected,date_selected,out_prefix,".png", sep="_"), type="png")
535
#grid.arrange(p1,p2,p3,ncol=1)
536
grid.arrange(p1,p2,ncol=1)
705 537

  
706
png(paste("Figure10_paper_diff_prediction_tmax_difference_land cover,ac_metric","_",out_prefix,".png", sep=""),
707
      height=480*layout_m[1],width=480*layout_m[2])
708
par(mfrow=layout_m)    
709
#funciton plot
710
for (i in 1:length(stat_list$avg)){
711
  #i=i+1
712
  index <- order_list[i]
713
  zones_stat <- as.data.frame(stat_list$avg[[index]])
714
  zones_stat$zones <- 0:10
715

  
716
  plot(zones_stat$zones,zones_stat[,1],type="b",ylim=c(-4.5,6),
717
       ylab="",xlab="",axes=FALSE)
718
  #mtext("difference between mod3 and mod6 (degree C)",line=3,side=2,cex=1.2,font=2) #Add ylab with distance 3 from box
719
  #mtext("land cover percent classes",side=1,cex=1.2,line=3,font=2)
720
  lines(zones_stat$zones,zones_stat[,2],col="red",lty="dashed",pch=2) #shrub
721
  points(zones_stat$zones,zones_stat[,2],col="red",lty="dashed",pch=2) #shrub
722
  lines(zones_stat$zones,zones_stat[,3],col="green",lty="dotted",pch=3) #grass
723
  points(zones_stat$zones,zones_stat[,3],col="green",lty="dotted",pch=3) #grass
724
  lines(zones_stat$zones,zones_stat[,4],col="blue",lty="dashed",pch=4) #crop
725
  points(zones_stat$zones,zones_stat[,4],col="blue",lty="dashed",pch=4) #crop
726
  lines(zones_stat$zones,zones_stat[,5],col="darkgreen",lty="dashed",pch=5)
727
  points(zones_stat$zones,zones_stat[,5],col="darkgreen",lty="dashed",pch=5)
728
  lines(zones_stat$zones,zones_stat[,6],col="purple",lty="dashed",pch=6)
729
  points(zones_stat$zones,zones_stat[,6],col="purple",lty="dashed",pch=6)
730

  
731
  breaks_lab<-zones_stat$zones
732
  #make it slanted...
733
  tick_lab<-c("0","1-10","","20-30","","40-50","","60-70","","80-90","90-100") #Not enough space for  
734
  #tick_lab<-c("0","10-20","30-40","60-70","80-90","90-100")
735
  axis(side=1,las=1,tick=TRUE,
736
       at=breaks_lab,labels=tick_lab, cex.axis=1.2,font=2) #reduce number of labels to Jan and June
737
  #text(tick_lab, par(\u201cusr\u201d)[3], labels = tick_lab, srt = 45, adj = c(1.1,1.1), xpd = TRUE, cex=.9)
738
  axis(2,cex.axis=1.4,font=2)
739
  box()
740
  legend("topleft",legend=names(zones_stat)[-7], 
741
        cex=1.4, col=c("black","red","green","blue","darkgreen","purple"),bty="n",
742
        lty=1,pch=1:7)
743
  title(paste(title_plots_list[index],sep=""),cex=1.6, font=2)
744
  #title(paste("Prediction tmax difference (",mf_selected,"-",mc_selected,") and land cover ",sep=""),cex=1.4,font=2) 
745
}
746 538
dev.off()
747 539

  
748 540

  
749 541
################################################
750
#### Figure 11: Spatial lag profiles  
542
#### Figure 5: Spatial lag profiles  
751 543
#This figure is generated to show the spatial Moran'I for 10 spatial 
752 544
#for Jan 1 and Sept 1 in 2010 for all models (1 to 7) and methods
753 545

  
......
758 550
lf_moran_list_date2 <-lapply(list_raster_obj_files[c("gam_daily","gam_CAI","gam_fss")],
759 551
                               FUN=function(x){x<-load_obj(x);x$method_mod_obj[[index]][[y_var_name]]})                           
760 552

  
761
#date_selected <- "20100901"
762 553
#date_selected <- "20100101"
763 554
#methods_names <-c("gam","kriging","gwr")
764
methods_names <-c("gam_daily","gam_CAI","gam_FSS")
555
methods_names <-c("gam_daily","gam_CAI","gam_FSS") #drop gam FSS later
765 556

  
766 557
names_layers<-methods_names
767 558
#Subset images to eliminate mod_kr
768
lf1 <- list(lf_moran_list_date1[[1]],lf_moran_list_date1[[2]][1:7],lf_moran_list_date1[[3]][1:7])
769
lf2 <- list(lf_moran_list_date2[[1]],lf_moran_list_date2[[2]][1:7],lf_moran_list_date2[[3]][1:7])
770
names(lf1)<-c("gam_daily","gam_CAI","gam_FSS")
771
names(lf2)<-c("gam_daily","gam_CAI","gam_FSS")
559
lf1 <- list(lf_moran_list_date1[[1]],lf_moran_list_date1[[2]][1:7]) #,lf_moran_list_date1[[3]][1:7])
560
lf2 <- list(lf_moran_list_date2[[1]],lf_moran_list_date2[[2]][1:7]) #,lf_moran_list_date2[[3]][1:7])
561
names(lf1)<-c("gam_daily","gam_CAI") #,"gam_FSS")
562
names(lf2)<-c("gam_daily","gam_CAI") #,"gam_FSS")
772 563

  
773 564
### Now extract Moran's I for a range of lag using a list of images
774 565

  
......
779 570

  
780 571
list_moran_df1 <- calculate_moranI_profile(list_lf[[1]],nb_lag) #for January 1
781 572
list_moran_df2 <- calculate_moranI_profile(list_lf[[2]],nb_lag) #for September 1
782
names(list_moran_df1)<-c("gam_daily","gam_CAI","gam_FSS")
783
names(list_moran_df2)<-c("gam_daily","gam_CAI","gam_FSS")
573
names(list_moran_df1)<-c("gam_daily","gam_CAI")#,"gam_FSS")
574
names(list_moran_df2)<-c("gam_daily","gam_CAI")#,"gam_FSS")
784 575

  
785 576
#Run accross two dates...
786 577
#list_moran lapply(list_lf,FUN=calculate_moranI_profile,nb_lag=nb_lag)
......
792 583
                  c("Spatial lag profile on September 1, 2010"))
793 584
#name used in the panel!!!
794 585
names_panel_plot <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + elev + N_w*E_w",
795
                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
586
                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOR")
796 587
layout_m<-c(2,4) # works if set to this?? ok set the resolution...
797 588
list_moran_df <- list(list_moran_df1,list_moran_df2)
798 589
list_param_plot_moranI_profile_fun <- list(list_moran_df,list_title_plot,names_panel_plot,layout_m)
......
817 608
#    height=480,width=480)
818 609
    #height=480*6,width=480*4)
819 610

  
820
p1 <- list_moranI_plots[[1]]
611
#p1 <- list_moranI_plots[[1]]
821 612
p2 <- list_moranI_plots[[2]]
613
#grid.arrange(p2,ncol=1)
614
print(p2)
615
#grid.arrange(p1,p2,ncol=1)
616
dev.off()
822 617

  
823
grid.arrange(p1,p2,ncol=1)
618
##################################################
619
####### Figure 6: Granularity -MoranI and std averaged monthly over 2010  
620

  
621
#get the  list of all prediction for a specific method
622
#list_lf <-extract_list_from_list_obj(load_obj(list_raster_obj_files$gam_CAI)$method_mod_obj,"dailyTmax") #getting objet
623
list_lf_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,"dailyTmax") #getting objet
624
#list_lf_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"dailyTmax") #getting objet
625
list_lf_gam_daily <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_daily"]])$method_mod_obj,"dailyTmax") #getting objet
626

  
627
nb_lag <- 10
628
list_filters<-lapply(1:nb_lag,FUN=autocor_filter_fun,f_type="queen") #generate lag 10 filters
629
list_param_stat_moran_CAI <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
630
list_param_stat_moran_gam_daily <- list(filter=list_filters[[10]],lf_list=list_lf_gam_daily)
631
#tt <- stat_moran_std_raster_fun(1,list_param=list_param_stat_moran)
632
tt <- mclapply(1:11, list_param=list_param_stat_moran_CAI, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
633
tt_gam_daily <- mclapply(1:365, list_param=list_param_stat_moran_gam_daily, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
634
#save(tt_gam_daily,file=file.path(out_dir,"moran_std_tt_gam_daily.RData"))
635

  
636
#Takes 1 hour to get the average moran's I for the whole year so load moran_std_tt_fss2.RData
637
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_fss)
638
#tt_fss <- mclapply(1:365, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
639
#tt_gam_daily <- mclapply(1:365, list_param=list_param_stat_moran_dam_daily, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
640

  
641
#save(tt_fss,file=file.path(out_dir,"moran_std_tt_fss.RData"))
642
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
643
tt_CAI <- mclapply(1:365, list_param=list_param_stat_moran_CAI, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
644
#save(tt_CAI,file=file.path(out_dir,"moran_std_tt_CAI.RData"))
645

  
646
tx2<- do.call(rbind,tt_CAI)
647
#tt_fss2 <- load_obj("moran_std_tt_fss2.RData")
648
#tx<- do.call(rbind,tt_fss2)
649

  
650
dates<-unique(raster_obj$tb_diagnostic_v$date)
651
dates_proc<-strptime(dates, "%Y%m%d")   # interpolation date being processed
652
dates_proc <- as.data.frame(dates_proc)
653
dates_proc$index <- 1:365
654
tx <- merge(tx2,dates_proc,by="index")
655
tx$month <- as.integer(strftime(tx$dates_proc, "%m"))          # current month of the date being processed
656
names(tx) <- c("index","moranI","std","pred_mod","date","month")
657
t<-melt(tx,
658
          #measure=mod_var, 
659
          id=c("pred_mod","month"),
660
          na.rm=F)
661
#t$value<-as.numeric(t$value) #problem with char!!!
662
tb_mod_m_avg2 <-cast(t,pred_mod+month~variable,mean) #monthly mean for every model
663

  
664
#mo<-as.integer(strftime(date_proc, "%m"))          # current month of the date being processed
665
#day<-as.integer(strftime(date_proc, "%d"))
666
#year<-as.integer(strftime(date_proc, "%Y"))
667
# end of pasted
668

  
669
tb_mod_m_avg <- subset(tb_mod_m_avg2,pred_mod!=c("mod_kr"))
670

  
671
p_moranI <- xyplot(moranI~month, # |set up pannels using method_interp
672
            group=pred_mod,data=tb_mod_m_avg, #group by model (covariates)
673
            main="Moran's I in daily predictions average by model and month",
674
            type="b",as.table=TRUE,
675
            #index.cond=list(c(1,3,2)),    #this provides the order of the panels)
676
            pch=1:length(tb_mod_m_avg$pred_mod),
677
            par.settings=list(superpose.symbol = list(
678
            pch=1:length(tb_mod_m_avg$pred_mod))),
679
            auto.key=list(columns=1,space="right",title="Model",cex=1),
680
            #auto.key=list(columns=5),
681
            xlab="Month",
682
            ylab="Moran I")
683
#print(p)
684

  
685
p_std <- xyplot(std~month, # |set up pannels using method_interp
686
            group=pred_mod,data=tb_mod_m_avg, #group by model (covariates)
687
            main="Standard devation in daily predictions average by model and month",
688
            type="b",as.table=TRUE,
689
            #index.cond=list(c(1,3,2)),    #this provides the order of the panels)
690
            pch=1:length(tb_mod_m_avg$pred_mod),
691
            par.settings=list(superpose.symbol = list(
692
            pch=1:length(tb_mod_m_avg$pred_mod))),
693
            auto.key=list(columns=1,space="right",title="Model",cex=1),
694
            #auto.key=list(columns=5),
695
            xlab="Month",
696
            ylab="Standard Deviation")
697

  
698
#xyplot(moranI~month,data=tb_mod_m_avg,groups=pred_mod,type="b")
699
#title("Spatial variation in FSS surfaces")
700
layout_m <- c(1,2)
701
png(paste("Figure6_paper_moranI_std__predictions_models_levelplot_",out_prefix,".png", sep=""),
702
    height=480*layout_m[1],width=480*layout_m[2])
703
    #height=3*480*layout_m[1],width=2*480*layout_m[2])
704
    #height=480*6,width=480*4)
705
#png(paste("Figure11_paper_spatial_correlogram_prediction_models_levelplot_",out_prefix,".png", sep=""),
706
#    height=480,width=480)
707
    #height=480*6,width=480*4)
708

  
709
#p1 <- list_moranI_plots[[1]]
710
#p2 <- list_moranI_plots[[2]]
711

  
712
grid.arrange(p_moranI,p_std,ncol=2)
824 713
dev.off()
825 714

  
715
#x<-subset(tb_mod_m_avg,pred_mod=="mod7")
716
#x2<-subset(tb_mod_m_avg,pred_mod=="mod2")
717
#x3<-subset(tb_mod_m_avg,pred_mod=="mod3")
718

  
719
##Now plot Figure 13c
720
# plot(x$month,x$moranI,ylim=c(0.72,1),ylab="Lag 10 Moran's I autocorrelation",
721
#      xlab="Month",
722
#      type="b",col="black",lty="solid",pch=1)
723
# lines(x2$month,x2$moranI,col="red",type="b")
724
# lines(x3$month,x3$moranI,col="blue",type="b")
725
# 
726
# par(new=TRUE)              # key: ask for new plot without erasing old
727
# plot(x$month,x$std,type="b",col="black",lty="dashed",pch=2,axes=F,
728
#      xlab="",ylab="")
729
#   #axis(4,xlab="",ylab="elevation(m)")  
730
# axis(4,cex=1.2)
731
# legend("topleft",legend=c("Moran's I","Stand Dev."), cex=0.8, col=c("black","black"),
732
#        lty=1:2,pch=1:2,bty="n")
733

  
734

  
735

  
826 736
################################################
827
#Figure 12: Monthly climatology, Daily deviation and bias
737
#Figure 7: Monthly climatology, Daily deviation 
828 738

  
829 739
#The list of files for 365 days in 2010...
830 740
lf_delta_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"delta") #getting objet
......
842 752
names(temp_day_s) <- c("Monhtly Climatology","Daily Devation","Daily Prediction")
843 753

  
844 754
layout_m <- c(1,3)
845
png(paste("Figure12_paper_climatology_daily_deviation_daily_prediction_model7_levelplot_",out_prefix,".png", sep=""),
755
png(paste("Figure7_paper_climatology_daily_deviation_daily_prediction_model7_levelplot_",out_prefix,".png", sep=""),
846 756
    height=480*layout_m[1],width=480*layout_m[2])
847 757
    #height=3*480*layout_m[1],width=2*480*layout_m[2])
848 758
    #height=480*6,width=480*4)
849
#par(mfrow=layout_m)    
850 759

  
851
#plot(temp_day_s,col=  temp.colors(25),nr=layout_m,nc=layout_m,
852
#     cex=1.5) #use nr to choose number of columns in layout!!
760
no_brks=25
761
names_layers <- c("Monthly Climatology","Daily deviation","Daily prediction")
762
list_p <- vector("list",length=length(names_layers))
763
for(i in 1:length(names_layers)){
764
  list_p[[i]] <- levelplot(temp_day_s,layer=i, margin=FALSE,
765
                 ylab=NULL,xlab=NULL,
766
                 par.settings = list(axis.text = list(font = 2, cex = 1.5),
767
                              par.main.text=list(font=2,cex=2.5),strip.background=list(col="white")),par.strip.text=list(font=2,cex=2),
768
                 main=names_layers[i],col.regions=temp.colors(no_brks))
853 769

  
854
p1 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=1)
855
p2 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=2)
856
p3 <- levelplot(temp_day_s,col.region=temp.colors(25),layer=3)
857
grid.arrange(p1,p2,p3,ncol=3)
770
}
771
#,legend.shrink=2)
772
grid.arrange(list_p[[1]],list_p[[2]] ,list_p[[3]] ,ncol=3)
858 773
dev.off()
859 774

  
860

  
861
##################################################
862
####### Figure 13 : Disussion section
775
######################################
776
####### Figure 8 : Disussion section
863 777

  
864 778
############################
865 779
#Get Tmax and LST averages
866 780

  
867
names_tmp<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12")
781
names_tmp<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08",
782
             "mm_09","mm_10","mm_11","mm_12")
868 783
LST_s<-subset(s_raster,names_tmp)
869 784
names_tmp<-c("nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08",
870 785
             "nobs_09","nobs_10","nobs_11","nobs_12")
......
882 797
## open device for plottging
883 798
layout_m<-c(2,2) # works if set to this?? ok set the resolution...
884 799

  
885
png(paste("Figure13_paper_TMax_and_LST_relationship_",out_prefix,".png", sep=""),
800
png(paste("Figure8_paper_TMax_and_LST_relationship_",out_prefix,".png", sep=""),
886 801
    height=480*layout_m[1],width=480*layout_m[2])
887 802
par(mfrow=layout_m)    
888 803

  
889
##################################################
890
####### Figure 13a: spatial variation -MoranI and  std  
804
#######################################
805
####### Figure 8a: LST and monthly air temperature  
891 806

  
892
#Use data from accuraccy with no monthly hold out
807
#Use data from accuracy with no monthly hold out
893 808
raster_obj <- load_obj(list_raster_obj_files$gam_CAI)
894 809
data_month <- (raster_obj$method_mod_obj[[1]]$data_month_s)
895 810
dates<-unique(raster_obj$tb_diagnostic_v$date)
......
911 826

  
912 827
statistics_LST_s<- LST_stat$avg #extracted earlier!!!
913 828

  
914
##Now plot Figure 13a
915
plot(TMax_avgm,type="b",ylim=c(-10,50),col="black",xlab="month",ylab="tmax (degree C)")
916
lines(1:12,LST_avgm$LST,type="b",col="black",lty="dashed",pch=2)
829
##Now plot Figure 8a
830
plot(TMax_avgm,type="b",ylim=c(-10,50),col="red",xlab="month",
831
     ylab="tmax (degree C)",cex=2,cex.lab=1.5) #,cex.axis=1.8)
832
lines(1:12,LST_avgm$LST,type="b",col="green",lty="dashed",pch=2,cex=2)
917 833
#lines(1:12,statistics_LST_s$mean,type="b",col="darkgreen")
918
lines(1:12,LST_avgm_min$LST,type="b",col="black",lty="dashed",pch=3)
919
lines(1:12,LST_avgm_max$LST,type="b",col="black",lty="dashed",pch=4)
920
text(1:12,LST_avgm$LST,month.abb,cex=0.8,pos=2)
921
legend("topleft",legend=c("TMax","LST","LST min","LST max"), cex=1, col=c("black","black","black","black"),
834
lines(1:12,LST_avgm_min$LST,type="b",col="black",lty="dashed",pch=3,cex=2)
835
lines(1:12,LST_avgm_max$LST,type="b",col="black",lty="dashed",pch=4,cex=2)
836
#text(1:12,LST_avgm$LST,month.abb,cex=0.8,pos=2)
837
legend("topleft",legend=c("TMax","LST","LST min","LST max"), cex=1.5, 
838
       col=c("red","green","black","black"),
922 839
              lty=c("solid","dashed","dashed","dashed"),pch=1:4,bty="n")
923
title(paste("Monthly mean tmax and LST at stations in Oregon", "2010",sep=" "))           
840
title("Monthly mean tmax and LST at stations in Oregon",cex=2.4)           
924 841

  
925
##################################################
926
####### Figure 13b: spatial variation -MoranI and  std  
927
#LST for area with FOrest 50> and grass >50
842
##############################
843
####### Figure 8b: spatial variation -MoranI and  std  
844
#LST for area with Forest 50> and grass >50
928 845

  
929 846
#Account for forest
930 847
data_month_all_forest<-data_month_all[data_month_all$LC1>=50,]
......
936 853
LST_avgm_grass <-aggregate(LST~month,data=data_month_all_grass,mean)
937 854
LST_avgm_urban <-aggregate(LST~month,data=data_month_all_urban,mean)
938 855

  
939
##Now plot Figure 13b
940
plot(TMax_avgm,type="b",ylim=c(-7,50),col="black",xlab="month",ylab="tmax (degree C)")
941
lines(1:12,LST_avgm$LST,type="b",col="black",lty="dashed",pch=2)
942
lines(LST_avgm_forest,type="b",col="black",lty="dotted",pch=3)
943
lines(LST_avgm_grass,type="b",col="black",lty="dotdash",pch=4)
856
##Now plot Figure 8b
857
plot(TMax_avgm,type="b",ylim=c(-7,50),col="red",xlab="month",
858
     ylab="tmax (degree C)",cex=2,cex.lab=1.5)#,cex.axis=1.8)
859
lines(1:12,LST_avgm$LST,type="b",col="green",lty="dashed",pch=2,cex=2)
860
lines(LST_avgm_forest,type="b",col="black",lty="dotted",pch=3,cex=2)
861
lines(LST_avgm_grass,type="b",col="black",lty="dotdash",pch=4,cex=2)
944 862
#lines(LST_avgm_urban,type="b",col="black",lty="longdash",pch=4)
945
legend("topleft",legend=c("TMax","LST","LST_forest","LST_grass"), cex=0.8, col=c("black","black","black","black","black"),
863
legend("topleft",legend=c("TMax","LST","LST_forest","LST_grass"), cex=1.5, 
864
       col=c("red","green","black","black","black"),
946 865
       lty=1:4,pch=1:4,bty="n")
947
title(paste("Monthly average tmax for stations in Oregon ", "2010",sep=""))
948

  
949
##################################################
950
####### Figure 13c: spatial variation -MoranI and  std  
866
title("Monthly average tmax for stations in Oregon ",cex=2.4)
951 867

  
952
#get the  list of all prediction for a specific method
953
#list_lf <-extract_list_from_list_obj(load_obj(list_raster_obj_files$gam_CAI)$method_mod_obj,"dailyTmax") #getting objet
954
list_lf_gam_CAI <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_CAI"]])$method_mod_obj,"dailyTmax") #getting objet
955
list_lf_gam_fss <-extract_list_from_list_obj(load_obj(list_raster_obj_files[["gam_fss"]])$method_mod_obj,"dailyTmax") #getting objet
868
########################################
869
####### Figure 8c: LST, TMax and RMSE for GAM_CAI (monthly averages)
956 870

  
957
nb_lag <- 10
958
list_filters<-lapply(1:nb_lag,FUN=autocor_filter_fun,f_type="queen") #generate lag 10 filters
959
list_param_stat_moran_CAI <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
960
#tt <- stat_moran_std_raster_fun(1,list_param=list_param_stat_moran)
961
tt <- mclapply(1:11, list_param=list_param_stat_moran_CAI, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
962

  
963
#Takes 1 hour to get the average moran's I for the whole year so load moran_std_tt_fss2.RData
964
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_fss)
965
#tt_fss <- mclapply(1:365, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
966
#save(tt_fss,file=file.path(out_dir,"moran_std_tt_fss.RData"))
967
#list_param_stat_moran <- list(filter=list_filters[[10]],lf_list=list_lf_gam_CAI)
968
#tt_CAI <- mclapply(1:365, list_param=list_param_stat_moran, FUN=stat_moran_std_raster_fun,mc.preschedule=FALSE,mc.cores = 11) #This is the end bracket from mclapply(...) statement
969
#save(tt_CAI,file=file.path(out_dir,"moran_std_tt_CAI.RData"))
970

  
971
#tx<- do.call(rbind,tt_fss)
972
tt_fss2 <- load_obj("moran_std_tt_fss2.RData")
973
tx<- do.call(rbind,tt_fss2)
974

  
975
dates<-unique(raster_obj$tb_diagnostic_v$date)
976
dates_proc<-strptime(dates, "%Y%m%d")   # interpolation date being processed
977
dates_proc <- as.data.frame(dates_proc)
978
dates_proc$index <- 1:365
979
tx2 <- merge(tx,dates_proc,by="index")
980
tx2$month <- as.integer(strftime(tx2$dates_proc, "%m"))          # current month of the date being processed
981
names(tx2) <- c("index","moranI","std","pred_mod","date","month")
982
t<-melt(tx2,
983
          #measure=mod_var, 
984
          id=c("pred_mod","month"),
985
          na.rm=F)
986
#t$value<-as.numeric(t$value) #problem with char!!!
987
tb_mod_m_avg <-cast(t,pred_mod+month~variable,mean) #monthly mean for every model
988

  
989
#mo<-as.integer(strftime(date_proc, "%m"))          # current month of the date being processed
990
#day<-as.integer(strftime(date_proc, "%d"))
991
#year<-as.integer(strftime(date_proc, "%Y"))
992
# end of pasted
993
x<-subset(tb_mod_m_avg,pred_mod=="mod7")
994

  
995
##Now plot Figure 13c
996
plot(x$month,x$moranI,ylim=c(0.72,0.92),ylab="Lag 10 Moran's I autocorrelation",
997
     xlab="Month",
998
     type="b",col="black",lty="solid",pch=1)
871
##Now plot Figure 8c
872
plot(TMax_avgm,type="b",ylim=c(-7,40),col="red",xlab="month",
873
     ylab="tmax (degree C)",cex=2,cex.lab=1.5)#,cex.axis=1.8)
874
lines(1:12,LST_avgm$LST,type="b",col="green",lty="dashed",pch=2,cex=2)
999 875
par(new=TRUE)              # key: ask for new plot without erasing old
1000
plot(x$month,x$std,type="b",col="black",lty="dashed",pch=2,axes=F,
1001
     xlab="",ylab="")
1002
  #axis(4,xlab="",ylab="elevation(m)")  
1003
axis(4,cex=1.2)
1004
legend("topleft",legend=c("Moran's I","Stand Dev."), cex=0.8, col=c("black","black"),
1005
       lty=1:2,pch=1:2,bty="n")
876
plot(1:12,table5[,2],type="b",pch=3,col="black",xlab="",ylab="",lty="dotted",
877
     ,ylim=c(0.5,2),axes=F) #plotting fusion profile
878
     #axis(4,xlab="",ylab="elevation(m)")  
879
     axis(4,cex=2)
1006 880

  
1007
title("Spatial variation in FSS surfaces")
881
#lines(LST_avgm_grass,type="b",col="black",lty="dotdash",pch=4)
882
#lines(LST_avgm_urban,type="b",col="black",lty="longdash",pch=4)
883
legend("topleft",legend=c("TMax","LST","RMSE Clim"), cex=1.5, 
884
       col=c("red","green","black"),
885
       lty=1:3,pch=1:3,bty="n")
886
title("Predictions error for GAM_CAI Climatology in relation to LST and TMax",
887
      cex=2.4)
1008 888

  
1009
##################################################
1010
####### Figure 13d: correlation between elevation and LST
889
########################################
890
####### Figure 8d: correlation between elevation and LST
1011 891

  
1012 892
LST_s <- subset(s_raster,c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12"))
1013 893
elev <- subset(s_raster,"elev_s")
......
1017 897

  
1018 898
r_tmp1 <-stack(LST_s,elev)
1019 899
names(r_tmp1) <- c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12","elev")
1020
x_cor_tmp1 <-layerStats(r_tmp,stat="pearson",na.rm=T)
900
x_cor_tmp1 <-layerStats(r_tmp1,stat="pearson",na.rm=T)
1021 901

  
1022 902
r_tmp2 <-stack(LST_s,LC1)
1023 903
names(r_tmp2) <- c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12","LC1")
1024 904
x_cor_tmp2 <-layerStats(r_tmp2,stat="pearson",na.rm=T)
1025 905

  
1026
##Now plot Figure 13d
906
##Now plot Figure 8d
1027 907
plot(1:12,x_cor_tmp1[[1]][1:12,13],ylim=c(-0.8,0.5),
1028 908
     type="b",lty="solid",pch=1,
1029
     ylab="Pearson corelation",xlab="month",main="Correlation between LST-elevation and LST-Forest")
1030
lines(1:12,x_cor_tmp2[[1]][1:12,13],type="b",lty="dashed",pch=2)
909
     ylab="Pearson corelation",xlab="month",
910
     cex=2,cex.lab=1.5)#,cex.axis=1.8)
911
lines(1:12,x_cor_tmp2[[1]][1:12,13],type="b",lty="dashed",pch=2,cex=2)
1031 912

  
1032
legend("topleft",legend=c("Correlation LST-Elevation","Correlation LST-Forest"), cex=1.1, col=c("black","black"),
913
legend("topleft",legend=c("Correlation LST-Elevation","Correlation LST-Forest"), 
914
       cex=1.5, col=c("black","black"),
1033 915
       lty=1:2,pch=1:2,bty="n")
916
title("Correlation between LST-elevation and LST-Forest",cex=2.4)
917
#closing file for figure 8
918
dev.off()
919

  
920
################################################
921
############ GENERATE ANNEX FIGURES 
922

  
923
##########################
924
#######Figure Annex 1: LST averaging: daily mean compared to monthly mean
925

  
926
lst_md <- raster(ref_rast_name)
927
projection(lst_md)<-projection(s_raster)
928
lst_mm_09<-subset(s_raster,"mm_09")
1034 929

  
1035
#closing file for figure 13
930
lst_md<-raster(ref_rast_d001)
931
lst_md<- lst_md - 273.16
932
lst_mm_01<-subset(s_raster,"mm_01")
933

  
934
png(filename=paste("Figure_annex1_paper_Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
935
par(mfrow=c(1,2))
936
plot(lst_md)
937
plot(interp_area,add=TRUE)
938
title("Mean for January 1")
939
plot(lst_mm_01)
940
plot(interp_area,add=TRUE)
941
title("Mean for month of January")
1036 942
dev.off()
1037 943

  
944
############################################
945
######Figure annex 2: Map of transects
946

  
947
## Transects image location in OR  
948
layout_m<-c(1,1)
949
png(paste("Figure_annex2_paper_elevation_transect_paths_",out_prefix,".png", sep=""),
950
    height=480*layout_m[1],width=480*layout_m[2])
951
vx_text <- c(395770.1,395770.1,395770.1) #location of labels
952
vy_text  <-c(473000,297045.9,112611.5)
953

  
954
plot(elev)
955
for(i in 1:length(transect_list)){
956
  filename<-sub(".shp","",transect_list[i])             #Removing the extension from file.
957
  transect<-readOGR(dirname(filename), basename(filename))                 #reading shapefile 
958
  #transect2 <- elide(transect, shift=c(0, -24000))
959
  #plot(transect2,add=TRUE)
960
  #writeOGR(transect2,dsn=".",layer="transect_OR_1_12282013",driver="ESRI Shapefile")
961
  plot(transect,add=TRUE)
962
}
963
text(x=vx_text,y=vy_text,labels=c("Transect 1","Transect 2","Transect 3"))
964
title("Transect Oregon")
965
dev.off()
966

  
967
##############################
968
######Figure annex 3: TRANSECT PROFILES
969

  
970
nb_transect <- 3
971
list_transect2<-vector("list",nb_transect)
972
list_transect3<-vector("list",nb_transect)
973
list_transect4<-vector("list",nb_transect)
974

  
975
#names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
976
#                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
977

  
978
rast_pred<-stack(lf[[2]]) #GAM_CAI
979
rast_pred_selected2<-subset(rast_pred,c(1,2,6)) #3 is referring to FSS, plot it first because it has the
980
rast_pred_selected3<-subset(rast_pred,c(1,3,6)) #3 is referring to FSS, plot it first because it has the
981
                                          # the largest range.
982
rast_pred2 <- stack(rast_pred_selected2,subset(s_raster,"elev_s"))
983
rast_pred3 <- stack(rast_pred_selected3,subset(s_raster,"elev_s"))
984

  
985
#layers_names<-layerNames(rast_pred2)<-c("lat*lon","lat*lon + elev + LST","elev")
986
layers_names2 <- names(rast_pred2)<-c("mod1","mod2","mod6","elev")
987
layers_names3 <- names(rast_pred3)<-c("mod1","mod3","mod6","elev")
988
#pos<-c(1,2) # postions in the layer prection
989
#transect_list
990
list_transect2[[1]]<-c(transect_list[1],paste("Figure_annex3a_paper_tmax_elevation_transect1_OR_",date_selected,
991
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
992
list_transect2[[2]]<-c(transect_list[2],paste("Figure_annex3b_tmax_elevation_transect2_OR_",date_selected,
993
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
994
list_transect2[[3]]<-c(transect_list[3],paste("Figure_annex3c_paper_tmax_elevation_transect3_OR_",date_selected,
995
                                           paste("mod1_2_6",collapse="_"),out_prefix,sep="_"))
996

  
997
list_transect3[[1]]<-c(transect_list[1],paste("Figure_annex3a_tmax_elevation_transect1_OR_",date_selected,
998
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
999
list_transect3[[2]]<-c(transect_list[2],paste("Figure_annex3b_tmax_elevation_transect2_OR_",date_selected,
1000
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
1001
list_transect3[[3]]<-c(transect_list[3],paste("Figure_annex3c_tmax_elevation_transect3_OR_",date_selected,
1002
                                           paste("mod1_3_6",collapse="_"),out_prefix,sep="_"))
1003

  
1004
names(list_transect2)<-c("Oregon Transect 1","Oregon Transect 2","Oregon Transect 3")
1005
names(list_transect3)<-c("Oregon Transect 1","Oregon Transect 2","Oregon Transect 3")
1006

  
1007
names(rast_pred2)<-layers_names2
1008
names(rast_pred3)<-layers_names3
1009

  
1010
title_plot2<-paste(names(list_transect2),"on",date_selected,sep=" ")
1011
#title_plot2<-paste(names(list_transect2),"on",date_selected,sep=" ")
1012

  
1013
#title_plot2<-paste(rep("Oregon transect on ",3), date_selected,sep="")
1014
#title_plot3<-paste(names(list_transect3),date_selected,sep=" ")
1015
#title_plot3<-paste(rep("Oregon transect on ",3), date_selected,sep="")
1016

  
1017
#r_stack<-rast_pred
1018
#m_layers_sc<-c(3) #elevation in the third layer
1019
m_layers_sc<-c(4) #elevation in the third layer
1020

  
1021
#title_plot2
1022
#rast_pred2
1023
#debug(plot_transect_m2)
1024
trans_data2 <- plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc)
1025
trans_data3 <- plot_transect_m2(list_transect3,rast_pred3,title_plot2,disp=FALSE,m_layers_sc)
1038 1026

  
1039 1027
###################### END OF SCRIPT #######################
1040 1028

  

Also available in: Unified diff