Project

General

Profile

« Previous | Next » 

Revision 829151c8

Added by Benoit Parmentier almost 11 years ago

multi-time scale paper analyses continuation

View differences:

climate/research/oregon/interpolation/multi_timescale_paper_interpolation.R
64 64
    transect<-readOGR(dirname(filename), basename(filename))                 #reading shapefile 
65 65
    trans_data<-extract(r_stack, transect)
66 66
    if (disp==FALSE){
67
      png(file=paste(list_trans[[i]]),".png",sep="")
67
      png(file=paste(list_trans[[i]][2],".png",sep=""))
68 68
    }
69 69
    #Plot layer values for specific transect
70 70
    for (k in 1:ncol(trans_data[[1]])){
......
95 95
      } 
96 96
    }
97 97
    title(title_plot[i])
98
    legend("topleft",legend=layerNames(r_stack)[1:2], 
98
    legend("topleft",legend=names(r_stack)[1:2], 
99 99
           cex=1.2, col=t_col,lty=1,bty="n")
100
    legend("topright",legend=layerNames(r_stack)[3], 
100
    legend("topright",legend=names(r_stack)[3], 
101 101
           cex=1.2, col=t_col[3],lty="dotted",bty="n")
102 102
    if (disp==TRUE){
103 103
      savePlot(file=paste(list_trans[[i]][2],".png",sep=""),type="png")
......
153 153
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"
154 154
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
155 155
y_var_name <- "dailyTmax"
156
out_prefix<-"analyses_11082013"
156
out_prefix<-"analyses_11252013"
157 157
ref_rast_name<- "/data/project/layers/commons/data_workflow/inputs/region_outlines_ref_files/mean_day244_rescaled.rst"                     #This is the shape file of outline of the study area. #local raster name defining resolution, exent, local projection--. set on the fly??
158 158
infile_reg_outline <- "/data/project/layers/commons/data_workflow/inputs/region_outlines_ref_files/OR83M_state_outline.shp"  #input region outline defined by polygon: Oregon
159 159
ref_rast_name <-"/data/project/layers/commons/data_workflow/inputs/region_outlines_ref_files/mean_day244_rescaled.rst"  #local raster name defining resolution, exent: oregon
......
178 178
s_raster <- brick(infile_covariates)
179 179
names(s_raster)<-covar_names
180 180

  
181
raster_prediction_obj_1 <-load_obj(file.path(in_dir1,raster_obj_file_1)) #comb5 gam_daily
182
raster_prediction_obj_2 <-load_obj(file.path(in_dir2,raster_obj_file_2)) #comb5 kriging_daily
183
raster_prediction_obj_3 <-load_obj(file.path(in_dir3,raster_obj_file_3)) #comb5 gwr_daily mod1 to mod3
184
raster_prediction_obj_3b <-load_obj(file.path(in_dir3b,raster_obj_file_3b)) #comb5 gwr_daily mod4 to mod7
181
#raster_prediction_obj_1 <-load_obj(file.path(in_dir1,raster_obj_file_1)) #comb5 gam_daily
182
#raster_prediction_obj_2 <-load_obj(file.path(in_dir2,raster_obj_file_2)) #comb5 kriging_daily
183
#raster_prediction_obj_3 <-load_obj(file.path(in_dir3,raster_obj_file_3)) #comb5 gwr_daily mod1 to mod3
184
#raster_prediction_obj_3b <-load_obj(file.path(in_dir3b,raster_obj_file_3b)) #comb5 gwr_daily mod4 to mod7
185 185
                             
186
raster_prediction_obj_4 <-load_obj(file.path(in_dir4,raster_obj_file_4)) #comb5 gam_CAI
187
raster_prediction_obj_5 <-load_obj(file.path(in_dir5,raster_obj_file_5)) #comb5 kriging_CAI
188
raster_prediction_obj_6 <-load_obj(file.path(in_dir6,raster_obj_file_6)) #comb5 gwr_CAI 
189
raster_prediction_obj_7 <-load_obj(file.path(in_dir7,raster_obj_file_7)) #comb5 gam_fss
190
raster_prediction_obj_8 <-load_obj(file.path(in_dir8,raster_obj_file_8)) #comb5 kriging_fss 
191
raster_prediction_obj_9 <-load_obj(file.path(in_dir9,raster_obj_file_9)) #comb5 gwr_fss
186
#raster_prediction_obj_4 <-load_obj(file.path(in_dir4,raster_obj_file_4)) #comb5 gam_CAI
187
#raster_prediction_obj_5 <-load_obj(file.path(in_dir5,raster_obj_file_5)) #comb5 kriging_CAI
188
#raster_prediction_obj_6 <-load_obj(file.path(in_dir6,raster_obj_file_6)) #comb5 gwr_CAI 
189
#raster_prediction_obj_7 <-load_obj(file.path(in_dir7,raster_obj_file_7)) #comb5 gam_fss
190
#raster_prediction_obj_8 <-load_obj(file.path(in_dir8,raster_obj_file_8)) #comb5 kriging_fss 
191
#raster_prediction_obj_9 <-load_obj(file.path(in_dir9,raster_obj_file_9)) #comb5 gwr_fss
192 192

  
193 193
############### BEGIN SCRIPT #################
194 194

  
......
229 229
                          rep("gwr",7))    
230 230
                             
231 231
#Check input covariates and model formula:
232
list_formulas <-raster_prediction_obj_2$method_mod_obj[[1]]$formulas #formulas for models run comb5
232
#list_formulas <-raster_prediction_obj_2$method_mod_obj[[1]]$formulas #formulas for models run comb5
233
list_formulas <-unlist(lapply(list_raster_obj_files[[1]],FUN=function(x){x<-load_obj(x);x$method_mod_obj[[1]]$formulas}))
233 234
#strsplit(list_formulas,"~")
234 235
                             
235
table4_paper$Forumulas<-rep(list_formulas,3)                             
236
table4_paper$Formulas<-rep(list_formulas,3)                             
236 237
table4_paper<-table4_paper[(c(5,4,1,2,3))]                             
237 238

  
238 239
#Testing siginificance between models
......
291 292
res_pix<-960
292 293
col_mfrow<-1
293 294
row_mfrow<-1
294
png(filename=paste("Figure1_contribution_covariates_study_area_",out_prefix,".png",sep=""),
295
png(filename=paste("Figure1_paper_study_area_",out_prefix,".png",sep=""),
295 296
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
296 297
par(mfrow=c(1,1))
297 298

  
......
303 304
plot(ghcn_dat_WGS84,add=T)
304 305
title_text <-c("Elevation (m) and meteorological"," stations in Oregon")
305 306
legend("topleft",legend=title_text,cex=2.1,bty="n")
306

  
307
#Add region label
307 308
par(mar = c(0,0,0,0)) # remove margin
308 309
#opar <- par(fig=c(0.9,0.95,0.8, 0.85), new=TRUE)
309 310
#opar <- par(fig=c(0.85,0.95,0.8, 0.9), new=TRUE)
......
324 325
################################################
325 326
######### Figure 3: LST averaging: daily mean compared to monthly mean
326 327

  
327
### CREATE FIGURE MEAN DAILY AND MEAN MONTHLY: AAG 2013  ####
328

  
329 328
lst_md<-raster(ref_rast_name)
330 329
projection(lst_md)<-projection(s_raster)
331 330
lst_mm_09<-subset(s_raster,"mm_09")
......
356 355
y_var_name <-"dailyTmax"
357 356
index<-244 #index corresponding to Sept 1
358 357

  
359
lf1 <- raster_prediction_obj_1$method_mod_obj[[index]][[y_var_name]] #select relevant raster images for the given dates
360
lf4 <- raster_prediction_obj_4$method_mod_obj[[index]][[y_var_name]]
361
lf7 <- raster_prediction_obj_7$method_mod_obj[[index]][[y_var_name]]
358
lf_list<-lapply(list_raster_obj_files[c("gam_daily","gam_CAI","gam_fss")],
359
                               FUN=function(x){x<-load_obj(x);x$method_mod_obj[[index]][[y_var_name]]})                           
360

  
361
#lf1 <- raster_prediction_obj_1$method_mod_obj[[index]][[y_var_name]] #select relevant raster images for the given dates
362
#lf4 <- raster_prediction_obj_4$method_mod_obj[[index]][[y_var_name]]
363
#lf7 <- raster_prediction_obj_7$method_mod_obj[[index]][[y_var_name]]
362 364

  
363 365
date_selected <- "20109101"
364 366
#methods_names <-c("gam","kriging","gwr")
365 367
methods_names <-c("gam_daily","gam_CAI","gam_FSS")
366 368

  
367 369
names_layers<-methods_names
368
lf <- (list(lf1,lf4[1:7],lf7[1:7]))
370
#lf <- (list(lf1,lf4[1:7],lf7[1:7]))
371
lf<-list(lf_list[[1]],lf_list[[2]][1:7],lf_list[[3]][1:7])
369 372

  
370 373
names_layers <-c("mod1 = lat*long","mod2 = lat*long + LST","mod3 = lat*long + elev","mod4 = lat*long + N_w*E_w",
371 374
                 "mod5 = lat*long + elev + DISTOC","mod6 = lat*long + elev + LST","mod7 = lat*long + elev + LST*FOREST")
......
390 393
  png(paste("Figure_",nb_fig[i],"_spatial_pattern_tmax_prediction_models_gam_levelplot_",date_selected,out_prefix,".png", sep=""),
391 394
    height=480*layout_m[1],width=480*layout_m[2])
392 395

  
393
  p <- levelplot(pred_temp_s,main="Interpolated Surfaces Model Comparison baseline 1", ylab=NULL,xlab=NULL,
396
  p <- levelplot(pred_temp_s,main=methods_names[i], ylab=NULL,xlab=NULL,
394 397
          par.settings = list(axis.text = list(font = 2, cex = 1.3),layout=layout_m,
395 398
                              par.main.text=list(font=2,cex=2),strip.background=list(col="white")),par.strip.text=list(font=2,cex=1.5),
396
          names.attr=names_layers,col.regions=temp.colors,at=seq(min_val,max_val,by=0.2))
399
          names.attr=names_layers,col.regions=temp.colors,at=seq(min_val,max_val,by=0.25))
397 400
  #col.regions=temp.colors(25))
398 401
  print(p)
399 402
  dev.off()
......
424 427

  
425 428
names(list_transect2)<-c("transect_OR1","transect_OR2","transect_OR3")
426 429

  
427
#X11(width=9,height=9)
428
#png(paste("fig3_elevation_transect1_path_CAI_fusion_",date_selected,out_prefix,".png", sep=""))
429
#plot(elev)
430
#k<-1  #transect to plot
431
#trans_file<-list_transect2[[k]][[1]]
432
#filename<-sub(".shp","",trans_file)             #Removing the extension from file.
433
#transect<-readOGR(".", filename)                 #reading shapefile 
434
#plot(transect,add=TRUE)
435
#title("Transect Oregon")
436
#dev.off()
437

  
438
layerNames(rast_pred2)<-layers_names
430
names(rast_pred2)<-layers_names
439 431
title_plot2<-paste(names(list_transect2),date_selected,sep=" ")
440 432
title_plot2<-paste(rep("Oregon transect on ",3), date_selected,sep="")
441 433
#r_stack<-rast_pred
442
m_layers_sc<-c(3)
434
m_layers_sc<-c(3) #elevation in the third layer
443 435
#title_plot2
444 436
#rast_pred2
445 437
debug(plot_transect_m2)
446 438
trans_data2<-plot_transect_m2(list_transect2,rast_pred2,title_plot2,disp=FALSE,m_layers_sc)
447 439

  
448
png(filename=paste("Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
449
par(mfrow=c(1,2))
440
#png(filename=paste("Comparison_daily_monthly_mean_lst",out_prefix,".png",sep=""),width=960,height=480)
441
#par(mfrow=c(1,2))
450 442

  
451 443
dev.off()
452 444

  
453
             
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()
458

  
459
################################################
460
#Figure 9: Image differencing and land cover  
461

  
462
png(paste("Fig9_image_difference_",date_selected,out_prefix,".png", sep=""),
463
    height=480*layout_m[1],width=480*layout_m[2])
464

  
454 465
###################### END OF SCRIPT #######################
455 466

  
456 467

  

Also available in: Unified diff