Project

General

Profile

« Previous | Next » 

Revision a2adeaa4

Added by Benoit Parmentier almost 10 years ago

NEX assessment part 2 1000x3000km plotting screened daily mosaics

View differences:

climate/research/oregon/interpolation/global_run_scalingup_assessment_part2.R
5 5
#Analyses, figures, tables and data are also produced in the script.
6 6
#AUTHOR: Benoit Parmentier 
7 7
#CREATED ON: 03/23/2014  
8
#MODIFIED ON: 02/10/2015            
8
#MODIFIED ON: 02/16/2015            
9 9
#Version: 4
10 10
#PROJECT: Environmental Layers project     
11 11
#COMMENTS: analyses for run 10 global analyses, Europe, Australia, 1000x300km
......
323 323
interpolation_method <- c("gam_CAI")
324 324
#out_prefix<-"run10_global_analyses_01282015"
325 325
#out_prefix <- "output_run10_1000x3000_global_analyses_02102015"
326
out_prefix <- "run10_1000x3000_global_analyses_02102015"
326
out_prefix <- "run10_1000x3000_global_analyses_02162015"
327 327

  
328 328
mosaic_plot <- FALSE
329 329

  
......
346 346
#out_dir <-paste(out_dir,"_",out_prefix,sep="")
347 347
create_out_dir_param <- FALSE
348 348
#out_dir <-"/data/project/layers/commons/NEX_data/output_run10_global_analyses_01282015/"
349
out_dir <- "/data/project/layers/commons/NEX_data/output_run10_1000x3000_global_analyses_02102015"
349
out_dir <- "/data/project/layers/commons/NEX_data/output_run10_1000x3000_global_analyses_02162015"
350 350
if(create_out_dir_param==TRUE){
351 351
  out_dir <- create_dir_fun(out_dir,out_prefix)
352 352
  setwd(out_dir)
......
408 408

  
409 409
#drop 3b
410 410
tb_all <- tb
411
tb <- subset(tb,reg!="reg3b")
411
#tb <- subset(tb,reg!="reg3b")
412 412

  
413 413
summary_metrics_v_all <- summary_metrics_v 
414
summary_metrics_v <- subset(summary_metrics_v,reg!="reg3b")
414
#summary_metrics_v <- subset(summary_metrics_v,reg!="reg3b")
415 415

  
416
tb_s_all <- tb_s
417
tb_s_all <- subset(tb_s,reg!="reg3b")
416
#tb_s_all <- tb_s
417
#tb_s_all <- subset(tb_s,reg!="reg3b")
418 418

  
419
tb_month_s_all <- tb_month_s
420
tb_month_s <- subset(tb_month_s,reg!="reg3b")
419
#tb_month_s_all <- tb_month_s
420
#tb_month_s <- subset(tb_month_s,reg!="reg3b")
421 421

  
422
df_tile_processed_all <- df_tile_processed
423
df_tile_processed <- subset(df_tile_processed,reg!="reg3b")
422
#df_tile_processed_all <- df_tile_processed
423
#df_tile_processed <- subset(df_tile_processed,reg!="reg3b")
424 424

  
425 425
#pred_data_month_info_all <- pred_data_month_info
426 426
#pred_data_month_info <- subset(pred_data_month_info,reg!="reg3b")
......
752 752
}
753 753

  
754 754
## Number of tiles with information:
755
sum(df_tile_processed$metrics_v) #number of tiles with raster object
756
length(df_tile_processed$metrics_v) #number of tiles in the region
757
sum(df_tile_processed$metrics_v)/length(df_tile_processed$metrics_v) #62.5% of tiles with info
755
sum(df_tile_processed$metrics_v) #188,number of tiles with raster object
756
length(df_tile_processed$metrics_v) #214,number of tiles in the region
757
sum(df_tile_processed$metrics_v)/length(df_tile_processed$metrics_v) #87.85% of tiles with info
758 758

  
759 759
#coordinates
760 760
#coordinates(summary_metrics_v) <- c("lon","lat")
......
890 890
#####################################################
891 891
#### Figure 9: plotting mosaics of regions ###########
892 892
## plot mosaics...
893
l_reg_name <- unique(df_tile_processed$reg)
893
#l_reg_name <- unique(df_tile_processed$reg)
894 894
#lf_mosaics_reg5 <- mixedsort(list.files(path="/data/project/layers/commons/NEX_data/output_run10_global_analyses_11302014/mosaics/reg5",
895 895
#           pattern="CAI_TMAX_clim_month_.*_mod1_all.tif", full.names=T))
896
lf_mosaics_reg <- vector("list",length=length(l_reg_name))
897
for(i in 1:length(l_reg_name)){
898
    lf_mosaics_reg[[i]] <- try(mixedsort(
899
    list.files(
900
    path=file.path(out_dir,"mosaics"),
901
    #pattern="reg6_.*._CAI_TMAX_clim_month_.*._mod1_all_mean.tif",
902
    pattern=paste(l_reg_name[i],".*._CAI_TMAX_clim_month_.*._mod1_all_mean.tif",sep=""), 
903
    full.names=T))
904
  )
905
}
906
names(lf_mosaics_reg) <- l_reg_name
896
#lf_mosaics_reg <- vector("list",length=length(l_reg_name))
897
#for(i in 1:length(l_reg_name)){
898
#    lf_mosaics_reg[[i]] <- try(mixedsort(
899
#    list.files(
900
#    path=file.path(out_dir,"mosaics"),
901
#    #pattern="reg6_.*._CAI_TMAX_clim_month_.*._mod1_all_mean.tif",
902
#    pattern=paste(l_reg_name[i],".*._CAI_TMAX_clim_month_.*._mod1_all_mean.tif",sep=""), 
903
#    full.names=T))
904
#  )
905
#}
906
#names(lf_mosaics_reg) <- l_reg_name
907 907

  
908 908
#This part should be automated...
909 909
#plot Australia
......
932 932

  
933 933
  lf_mosaics_mask_reg[[i]] <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 10)
934 934
}
935

  
935 936
################## WORLD MOSAICS NEEDS MAJOR CLEAN UP OF CODE HERE
936 937
##make functions!!
937 938
###Combine mosaics with modified code from Alberto
......
982 983
################## PLOTTING WORLD MOSAICS ################
983 984

  
984 985
lf_world_pred <- list.files(pattern="world.*2010090.*.tif$")
986
lf_raster_fname <- list.files(pattern="world.*2010*.*02162015.tif$",full.names=T)
987

  
988
prefix_str <- "Figure10_clim_world_mosaics_day_"
989
l_dates <-day_to_mosaic
990
screenRast=TRUE
991
list_param_plot_screen_raster <- list(lf_raster_fname,screenRast,l_dates,out_dir,prefix_str,out_suffix)
992
names(list_param_plot_screen_raster) <- c("lf_raster_fname","screenRast","l_dates","out_dir_str","prefix_str","out_suffix_str")
993

  
994
#debug(plot_screen_raster_val)
995

  
996
#plot_screen_raster_val(1,list_param_plot_scre
997
en_raster)
998
world_m_list <- mclapply(1:10, list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = 5) #This is the end bracket from mclapply(...) statement
999
world_m_list <- mclapply(11:30, list_param=list_param_plot_screen_raster, plot_screen_raster_val,mc.preschedule=FALSE,mc.cores = 7) #This is the end bracket from mclapply(...) statement
1000

  
1001
plot_screen_raster_val<-function(i,list_param){
1002
  ##USAGE###
1003
  #Screen raster list and produced plot as png.
1004
  fname <-list_param$lf_raster_fname[i]
1005
  screenRast <- list_param$screenRast
1006
  l_dates<- list_param$l_dates
1007
  out_dir_str <- list_param$out_dir_str
1008
  prefix_str <-list_param$prefix_str
1009
  out_suffix_str <- list_param$out_suffix_str
1010
  
1011
  ### START SCRIPT ####
1012
  date_proc <- l_dates[i]
1013
  
1014
  if(screenRast==TRUE){
1015
    r_test <- raster(fname)
985 1016

  
986
r_test <- raster(lf_world_pred[6])
987
m <- c(-Inf, -100, NA,  
1017
    m <- c(-Inf, -100, NA,  
988 1018
         -100, 100, 1, 
989 1019
         100, Inf, NA) #can change the thresholds later
990
rclmat <- matrix(m, ncol=3, byrow=TRUE)
991
rc <- reclassify(r_test, rclmat,filename=paste("rc_tmp_",i,".tif",sep=""),dataType="FLT4S",overwrite=T)
992
#file_name <- unlist(strsplit(basename(lf_m[i]),"_"))
1020
    rclmat <- matrix(m, ncol=3, byrow=TRUE)
1021
    rc <- reclassify(r_test, rclmat,filename=paste("rc_tmp_",i,".tif",sep=""),dataType="FLT4S",overwrite=T)
1022
    #file_name <- unlist(strsplit(basename(lf_m[i]),"_"))
1023
    extension_str <- extension(filename(r_test))
1024
    raster_name_tmp <- gsub(extension_str,"",basename(filename(r_test)))
1025
    raster_name <- file.path(out_dir_str,paste(raster_name_tmp,"_masked.tif",sep=""))
993 1026
  
994
#date_proc <- file_name[7] #specific tot he current naming of files
995
#date_proc <- l_dates[i]
996
date_proc<- "2010010905"
1027
    r_pred <- mask(r_test,rc,filename=raster_name,overwrite=TRUE)
1028
  }else{
1029
    r_pred <- raster(fname)
1030
  }
1031
  
1032
  #date_proc <- file_name[7] #specific tot he current naming of files
1033
  #date_proc<- "2010010101"
997 1034

  
998
#paste(raster_name[1:7],collapse="_")
999
#add filename option later
1000
extension_str <- extension(filename(r_test))
1001
raster_name_tmp <- gsub(extension_str,"",basename(filename(r_test)))
1002
raster_name <- file.path(out_dir_str,paste(raster_name_tmp,"_masked.tif",sep=""))
1003
r_pred <- mask(r_test,rc,filename=raster_name,overwrite=TRUE)
1035
  #paste(raster_name[1:7],collapse="_")
1036
  #add filename option later
1004 1037

  
1005
res_pix <- 1200
1006
#res_pix <- 480
1038
  res_pix <- 960
1039
  #res_pix <- 480
1007 1040

  
1008
col_mfrow <- 1
1009
row_mfrow <- 1
1041
  col_mfrow <- 1
1042
  row_mfrow <- 1
1010 1043
  
1011
png(filename=paste("Figure10_clim_world_mosaics_day_","_",date_proc,"_",tile_size,"_",out_suffix,".png",sep=""),
1044
#  png(filename=paste("Figure10_clim_world_mosaics_day_","_",date_proc,"_",tile_size,"_",out_suffix,".png",sep=""),
1045
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
1046
  png(filename=paste(prefix_str,"_",date_proc,"_",tile_size,"_",out_suffix_str,".png",sep=""),
1012 1047
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
1013 1048

  
1014 1049
  plot(r_pred,main=paste("Predicted on ",date_proc , " ", tile_size,sep=""),cex.main=1.5)
1015
dev.off()
1050
  dev.off()
1051

  
1052
}
1016 1053

  
1017 1054

  
1018 1055
#lf_world_mask_reg <- vector("list",length=length(lf_world_pred))

Also available in: Unified diff