Project

General

Profile

« Previous | Next » 

Revision ff3c690f

Added by Benoit Parmentier almost 10 years ago

run 10 NEX assessment generation of mosaics figures for reg4, reg5, reg2

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: 12/15/2014            
8
#MODIFIED ON: 12/16/2014            
9 9
#Version: 3
10 10
#PROJECT: Environmental Layers project     
11
#COMMENTS: analyses for run 5 global using 6 specific tiles
11
#COMMENTS: analyses for run 10 global analyses, Europe 1000x300km
12 12
#################################################################################################
13 13

  
14 14
### Loading R library and packages        
......
743 743
lf_mosaics_reg5 <- mixedsort(list.files(path="/data/project/layers/commons/NEX_data/output_run10_global_analyses_11302014/mosaics/reg5",
744 744
           pattern="CAI_TMAX_clim_month_.*_mod1_all.tif", full.names=T))
745 745

  
746

  
747 746
#r_reg5 <- stack(lf_mosaics_reg5)
748 747
lf_m <- lf_mosaics_reg5[1:12]
749 748
reg_name <- "reg5"
......
771 770
  dev.off()
772 771
}
773 772

  
773
####
774 774

  
775
#Monthly
776
lf_m <- lf_mosaics_reg2[13:15]
777
lf_m <- lf_mosaics_reg2[1:12]
775 778

  
776

  
777
#####
778

  
779
lf_mosaics_reg4 <- mixedsort(list.files(path="/data/project/layers/commons/NEX_data/output_run10_global_analyses_11302014/mosaics/reg4",
780
           pattern="CAI_TMAX_clim_month_.*_mod2_all.tif",full.names=T))
781

  
782
lf_m <- lf_mosaics_reg4[1:12]
783
reg_name <- "reg4"
779
reg_name <- "reg2"
784 780
for(i in 1:length(lf_m)){
785 781
  r_test<- raster(lf_m[i])
786 782
  #r_test <- subset(r_reg5,1)
787 783

  
788
  r_test_mask_high <- r_test < 100
789
  NAvalue(r_test_mask_high) <- 0
790
  r_test_mask_low <- r_test > -100
791
  NAvalue(r_test_mask_low) <- 0
792
  r3 <- overlay(r_test, r_test_mask_high, r_test_mask_low, fun=function(x,y,z){return(x*y*z)})
784
  #r_test_mask_high <- r_test < 100
785
  #r_test_mask_high <- r_test[r_test < 100]
786
  
787
  #r_test_mask_high <- r_test < 100
788

  
789
  m <- c(-Inf, -100, NA,  
790
         -100, 100, 1, 
791
         100, Inf, NA)
792
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
793
  rc <- reclassify(r_test, rclmat,filename="rc.tif",dataType="FLT4S",overwrite=T)
794
  r_pred <- mask(r_test,rc,filename=paste("CAI_TMAX_clim_month_",i,"_mod1_all_",reg_name,"_masked.tif",sep=""),overwrite=TRUE)
795
  #r <- raster(r_test_mask_high,dataType="INT2U")
796
  #r3 <- clamp(r_test,-100,100)
797
  #NAvalue(r_test_mask_high) <- 0
798
  
799
  #r_test_mask_low <- r_test > -100
800
  #NAvalue(r_test_mask_low) <- 0
801
  #r3 <- overlay(r_test, r_test_mask_high, r_test_mask_low, fun=function(x,y,z){return(x*y*z)})
793 802
  #writeRaster(r3,file=paste("CAI_TMAX_clim_month_",i,"_mod1_all_",reg_name,"_masked.tif",sep=""),overwrite=TRUE)
794 803
  
795 804
  res_pix <- 1200
......
798 807
  col_mfrow <- 1
799 808
  row_mfrow <- 1
800 809
  
801
  png(filename=paste("Figure9_clim_mosaics_month","_",i,"_",reg_name,"_",out_prefix,".png",sep=""),
810
  png(filename=paste("Figure9_clim_mosaics_day_test","_",i,"_",reg_name,"_",out_prefix,".png",sep=""),
802 811
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
803 812

  
804
  plot(r3,main=paste("climatology month ", i, " ", reg_name,sep=""),cex.main=1.5)
813
  plot(r_pred,main=paste("climatology month ", i, " ", reg_name,sep=""),cex.main=1.5)
805 814
  dev.off()
806 815
}
807 816

  
808
####
817
#daily
818
lf_m <- lf_mosaics_reg2[13:length(lf_mosaics_reg2)]
819
#lf_m <- lf_mosaics_reg2[1:12]
809 820

  
810
lf_m <- lf_mosaics_reg5[13:15]
811
reg_name <- "reg5"
821
reg_name <- "reg2"
812 822
for(i in 1:length(lf_m)){
813 823
  r_test<- raster(lf_m[i])
814
  #r_test <- subset(r_reg5,1)
815 824

  
816
  r_test_mask_high <- r_test < 100
817
  NAvalue(r_test_mask_high) <- 0
818
  r_test_mask_low <- r_test > -100
819
  NAvalue(r_test_mask_low) <- 0
820
  r3 <- overlay(r_test, r_test_mask_high, r_test_mask_low, fun=function(x,y,z){return(x*y*z)})
821
  #writeRaster(r3,file=paste("CAI_TMAX_clim_month_",i,"_mod1_all_",reg_name,"_masked.tif",sep=""),overwrite=TRUE)
825
  m <- c(-Inf, -100, NA,  
826
         -100, 100, 1, 
827
         100, Inf, NA)
828
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
829
  rc <- reclassify(r_test, rclmat,filename="rc.tif",dataType="FLT4S",overwrite=T)
830
  raster_name <- unlist(strsplit(basename(lf_m[i]),"_"))
831
  date_proc <- raster_name[5]
832
  #paste(raster_name[1:7],collapse="_")
833
  r_pred <- mask(r_test,rc,filename=paste("CAI_TMAX_clim_month_mod1_all_",reg_name,"_",date_proc,"_masked.tif",sep=""),overwrite=TRUE)
822 834
  
823 835
  res_pix <- 1200
824 836
  #res_pix <- 480
......
826 838
  col_mfrow <- 1
827 839
  row_mfrow <- 1
828 840
  
829
  png(filename=paste("Figure9_clim_mosaics_day_test","_",i,"_",reg_name,"_",out_prefix,".png",sep=""),
841
  png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_prefix,".png",sep=""),
830 842
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
831 843

  
832
  plot(r3,main=paste("climatology month ", i, " ", reg_name,sep=""),cex.main=1.5)
844
  plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5)
833 845
  dev.off()
834 846
}
835 847

  
836
######################
837
### Figure 9: Plot the number of stations in a processing tile
838

  
839
# #data_tb <- merge(df_tile_processed,summary_metrics_v,by="tile_id") #keep only the common id, id tiles with pred ac
840
# #data_tb <- merge(df_tile_processed,summary_metrics_v,by="tile_id",all=T) #keep all
841
# 
842
# mod1_data_tb <- merge(df_tile_processed,subset(summary_metrics_v,pred_mod=="mod1"),by="tile_id",all=T) #keep all
843
# mod2_data_tb <- merge(df_tile_processed,subset(summary_metrics_v,pred_mod=="mod2"),by="tile_id",all=T) #keep all
844
# mod_kr_data_tb <- merge(df_tile_processed,subset(summary_metrics_v,pred_mod=="mod_kr"),by="tile_id",all=T) #keep all
845
# 
846
# ##First create an image of the tiles, use ratify?? with tile id as the raster id for the attribute table??
847
# #Transform table text file into a raster image
848
# #coord_names <- c("XCoord","YCoord")
849
# coord_names <- c("lon.x","lat.x")
850
# #l_r_ast <- rasterize_df_fun(df_tile_processed,coord_names,proj_str,out_suffix,out_dir=".",file_format,NA_flag_val,tolerance_val=0.000120005)
851
# out_suffix_str <- paste("mod1_",out_suffix)
852
# mod1_l_rast <- rasterize_df_fun(mod1_data_tb,coord_names,proj_str=CRS_WGS84,out_suffix_str,out_dir=".",file_format,NA_flag_val,tolerance_val=0.000120005)
853
# mod1_stack <- stack(mod1_l_rast)
854
# names(mod1_stack) <- names(mod1_data_tb)
855
# 
856
# out_suffix_str <- paste("mod2_",out_suffix)
857
# mod2_l_rast <- rasterize_df_fun(mod2_data_tb,coord_names,proj_str=CRS_WGS84,out_suffix_str,out_dir=".",file_format,NA_flag_val,tolerance_val=0.000120005)
858
# mod2_stack <- stack(mod2_l_rast)
859
# names(mod2_stack) <- names(mod2_data_tb)
860
# 
861
# out_suffix_str <- paste("mod_kr_",out_suffix)
862
# mod_kr_l_rast <- rasterize_df_fun(mod_kr_data_tb,coord_names,proj_str=CRS_WGS84,out_suffix_str,out_dir=".",file_format,NA_flag_val,tolerance_val=0.000120005)
863
# mod_kr_stack <- stack(mod_kr_l_rast)
864
# names(mod_kr_stack) <- names(mod_kr_data_tb)
865
# 
866
# #Number of daily predictions 
867
# p0 <- levelplot(mod1_stack,layer=21,margin=F,
868
#                 main=paste("number_daily_predictions_for_","mod1",sep=""))
869
# p<- p0+p_shp
870

  
871
###########
872
## Figure 9a: number of daily predictions
873 848

  
874
#res_pix <- 1200
875
#res_pix <- 480
876
#col_mfrow <- 1
877
#row_mfrow <- 1
878

  
879
#png(filename=paste("Figure9a_raster_map_number_daily_predictions_forr_","mod1","_",out_prefix,".png",sep=""),
880
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
881

  
882
#print(p)
883

  
884
#dev.off()
885

  
886
## Figure 9a
887
#p0 <- levelplot(mod2_stack,layer=21,margin=F)
888
#p <- p0+p_shp
889

  
890
#res_pix <- 1200
891
#res_pix <- 480
892
#col_mfrow <- 1
893
#row_mfrow <- 1
894
#png(filename=paste("Figure9a_raster_map_number_daily_predictions_for_","mod2","_",out_prefix,".png",sep=""),
895
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
849
#### for reg5
896 850

  
897
#print(p)
898

  
899
#dev.off()
900

  
901
#plot(mod_kr_stack,y=21)
902

  
903
########
904
###Figure 9b: RMSE plots
905
##
906
#p0 <- levelplot(mod1_stack,layer=10,margin=F,col.regions=matlab.like(25),
907
#                main="Average RMSE for mod1")
908
#p<- p0+p_shp
909

  
910
#res_pix <- 1200
911
#res_pix <- 480
912
#col_mfrow <- 1
913
#row_mfrow <- 1
914
#png(filename=paste("Figure9b_raster_map_rmse_predictions_for_","mod1","_",out_prefix,".png",sep=""),
915
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
851
lf_mosaics_reg5 <- mixedsort(list.files(path="/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/reg5",
852
           pattern="CAI_TMAX_clim_month_.*_mod1_all.tif", full.names=T))
916 853

  
917
#print(p)
854
reg_name <- "reg5_1500x4500"
855
#daily
856
lf_m <- lf_mosaics_reg5[13:length(lf_mosaics_reg5)]
918 857

  
919
#dev.off()
858
for(i in 1:length(lf_m)){
859
  r_test<- raster(lf_m[i])
920 860

  
921
#print(p)
922
#p0 <- levelplot(mod2_stack,layer=10,margin=F,col.regions=matlab.like(25),
923
#                main="Average RMSE for mod2")
924
#p<- p0+p_shp
925
#print(p)
861
  m <- c(-Inf, -100, NA,  
862
         -100, 100, 1, 
863
         100, Inf, NA)
864
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
865
  rc <- reclassify(r_test, rclmat,filename="rc.tif",dataType="FLT4S",overwrite=T)
866
  raster_name <- unlist(strsplit(basename(lf_m[i]),"_"))
867
  date_proc <- raster_name[5]
868
  #paste(raster_name[1:7],collapse="_")
869
  r_pred <- mask(r_test,rc,filename=paste("CAI_TMAX_clim_month_mod1_all_",reg_name,"_",date_proc,"_masked.tif",sep=""),overwrite=TRUE)
870
  
871
  res_pix <- 1200
872
  #res_pix <- 480
926 873

  
927
#res_pix <- 1200
928
#res_pix <- 480
929
#col_mfrow <- 1
930
#row_mfrow <- 1
931
#png(filename=paste("Figure9b_raster_map_rmse_predictions_for_","mod2","_",out_prefix,".png",sep=""),
932
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
874
  col_mfrow <- 1
875
  row_mfrow <- 1
876
  
877
  png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_prefix,".png",sep=""),
878
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
933 879

  
934
#print(p)
880
  plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5)
881
  dev.off()
882
}
935 883

  
936
#dev.off()
884
### for reg4
937 885

  
938
#plot(mod1_stack,y=10)
939
#plot(mod2_stack,y=10)
940
#plot(mod_kr_stack,y=10)
886
reg_name <- "reg2"
887
for(i in 1:length(lf_m)){
888
  r_test<- raster(lf_m[i])
941 889

  
942
########## Figure 10: map of daily predictions accuracy
890
  m <- c(-Inf, -100, NA,  
891
         -100, 100, 1, 
892
         100, Inf, NA)
893
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
894
  rc <- reclassify(r_test, rclmat,filename="rc.tif",dataType="FLT4S",overwrite=T)
895
  raster_name <- unlist(strsplit(basename(lf_m[i]),"_"))
896
  date_proc <- raster_name[5]
897
  #paste(raster_name[1:7],collapse="_")
898
  r_pred <- mask(r_test,rc,filename=paste("CAI_TMAX_clim_month_mod1_all_",reg_name,"_",date_proc,"_masked.tif",sep=""),overwrite=TRUE)
899
  
900
  res_pix <- 1200
901
  #res_pix <- 480
943 902

  
944
## Can make maps of daily and accuracy metrics!!!
903
  col_mfrow <- 1
904
  row_mfrow <- 1
905
  
906
  png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_prefix,".png",sep=""),
907
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
945 908

  
946
#mod1_tb <- subset(tb,pred_mod=="mod1")
909
  plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5)
910
  dev.off()
911
}
947 912

  
948
## loop or create image for specific day
949
#proj_str<- CRS_WGS84
950
#file_format <- ".rst"
951
#NA_value <- -9999
952
#NA_flag_val <- NA_value
953
#out_suffix <-out_prefix  
954 913

  
955
#first need to join x and y coord
956
# date_selected <- "20100101"
957
# mod_selected <- "mod1"
958
# var_selected <- "rmse"
959
# #test2_data_tb <- merge(df_tile_processed,test2,by="tile_id",all=T) #keep all
960
# 
961
# #l_date_selected <- unique(tb$date)
962
# idx <- seq(as.Date('2010-01-01'), as.Date('2010-12-31'), 'day')
963
# #idx <- seq(as.Date('2010-01-01'),by="day", length=365)
964
# 
965
# #idx <- seq(as.Date('20100101'), as.Date('20101231'), 'day')
966
# #date_l <- strptime(idx[1], "%Y%m%d") # interpolation date being processed
967
# l_date_selected <- format(idx, "%Y%m%d") # interpolation date being processed
968
# tb_dat <- tb
969
# proj_str <- CRS_WGS84
970
# list_param_raster_from_tb <- list(tb_dat,df_tile_processed,l_date_selected,
971
#                                   mod_selected,var_selected,out_suffix,
972
#                                   proj_str,file_format,NA_value,NA_flag_val)
973
# 
974
# names(list_param_raster_from_tb) <- c("tb_dat","df_tile_processed","date_selected",
975
#                                       "mod_selected","var_selected","out_suffix",
976
#                                       "proj_str","file_format","NA_value","NA_flag_val")
977
# #undebug(create_raster_from_tb_diagnostic)
978
# rast <- create_raster_from_tb_diagnostic (i,list_param=list_param_raster_from_tb)
979
# l_rast <- lapply(1:length(l_date_selected),FUN=create_raster_from_tb_diagnostic,list_param=list_param_raster_from_tb)
980
# r_mod1_rmse <- stack(l_rast)
981
# list_param_raster_from_tb$var_selected <- "n"
982
# l_rast_n<- lapply(1:length(l_date_selected),FUN=create_raster_from_tb_diagnostic,list_param=list_param_raster_from_tb)
983
# r_mod1_n <- stack(l_rast_n)
984
# 
985
# ##now stack for mod2
986
# 
987
# list_param_raster_from_tb$mod_selected <- "mod2"
988
# list_param_raster_from_tb$var_selected <- "rmse"
989
# l_rast <- lapply(1:length(l_date_selected),FUN=create_raster_from_tb_diagnostic,list_param=list_param_raster_from_tb)
990
# r_mod2_rmse <- stack(l_rast)
991
# list_param_raster_from_tb$var_selected <- "n"
992
# l_rast_n<- lapply(1:length(l_date_selected),FUN=create_raster_from_tb_diagnostic,list_param=list_param_raster_from_tb)
993
# r_mod2_n <- stack(l_rast_n)
994
# 
995
# #r_mod2_n <- stack(list.files(pattern="r_nn_mod2.*.rst"))
996
# #r_mod1_n <- stack(list.files(pattern="r_nn_mod1.*.rst"))
997
# 
998
# l_rast_n[[1]]
999
# #"./r_nn_mod2_20101231_run7_global_analyses_10042014.rst"
1000
# 
1001
# # Create a raster stack with time series tag
1002
# r_mod2_rmse <- setZ(r_mod2_rmse, idx)
1003
# names(r_mod2_rmse) <- l_date_selected
1004
# r_mod2_n <- setZ(r_mod2_n, idx)
1005
# names(r_mod2_n) <- l_date_selected
1006
# 
1007
# writeRaster(r_mod2_n,by=F)
1008
# 
1009
# levelplot(r_mod2_rmse,layers=1:12,panel=panel.levelplot.raster, col.regions=matlab.like(25))+p_shp
1010
# 
1011
# p_hist <- histogram(r_mod2_rmse,FUN=as.yearmon)
1012
# p_hist2 <- p_hist
1013
# print(p_hist)
1014
# p_hist$x.limits <- rep(list(c(-2,6)),12)
1015
# print(p_hist)
1016
# p_bw <- bwplot(r_mod2_rmse,FUN=as.yearmon)
1017
# print(p_bw)
1018
# p_bw2 <- p_bw
1019
# p_bw2$y.limits <- c(-2,6)
1020
# print(p_bw2)
1021
# r_mod2_rmse_m <- zApply(r_mod2_rmse,by=as.yearmon,fun="mean")
1022
# p_lev_rmse_m <- levelplot(r_mod2_rmse_m,panel=panel.levelplot.raster,col.regions=matlab.like(25)) + p_shp
1023
# print(p_lev_rmse_m)
1024
# 
1025
# ## analysis of the daily nmber of validation stations per tile
1026
# r_mod2_n_m <- zApply(r_mod2_n,by=as.yearmon,fun="mean")
1027
# p_lev_n_m <- levelplot(r_mod2_n_m,panel=panel.levelplot.raster,col.regions=matlab.like(25))+p_shp
1028
# print(p_lev_n_m)
1029
# 
1030
# p_bw_n2 <- bwplot(r_mod2_n,FUN=as.yearmon,do.out=F)
1031
# print(p_bw_n)
1032
# p_bw_n$y.limits <- c(0,16)
1033
# print(p_bw_n)
1034
# p_ho <- hovmoller(r_mod2_rmse)
1035
# 
1036
# p_lev_n <- levelplot(r_mod2_n,layers=1:12,panel=panel.levelplot.raster, col.regions=matlab.like(25))+p_shp
1037
# 
1038
# print(p_lev_n)
1039
# 
1040
# ### mod1
1041
# 
1042
# #as(r_mod2_rmse)
1043
# 
1044
# #Make this a function...
1045
# #test <- subset(tb,pred_mod=="mod1" & date=="20100101",select=c("tile_id","n","mae","rmse","me","r","m50"))
1046
# 
1047
# plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1048
# mod_selected <- "mod2"
1049
# plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1050
# mod_selected <- "mod1"
1051
# date_selected  <- "20100901"
1052
# plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1053
# 
1054
# list_date_selected <- c("20100101","20100901")
1055
# for (i in 1:length(list_date_selected)){
1056
#   mod_selected <- "mod1"
1057
#   date_selected  <- list_date_selected[i]
1058
#   var_selected <- "rmse"
1059
#   plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1060
#   var_selected <- "n"
1061
#   plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1062
# }
1063
# 
1064
# list_date_selected <- c("20100101","20100901")
1065
# for (i in 1:length(list_date_selected)){
1066
#   mod_selected <- "mod2"
1067
#   date_selected  <- list_date_selected[i]
1068
#   var_selected <- "rmse"
1069
#   plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1070
#   var_selected <- "n"
1071
#   plot_raster_tb_diagnostic(reg_layer,tb_dat,df_tile_processed,date_selected,mod_selected,var_selected,out_suffix)
1072
# }
1073
# 
1074
# 
1075
# # dd <- merge(df_tile_processed,pred_data_month_info,by="tile_id")
1076
# # coordinates(dd) <- c(dd$x,dd$y)
1077
# # 
1078 914

  
1079 915
######################
1080
### Figure 9: Plot the number of stations in a processing tile
1081

  
1082
## Get ID from tile number...
1083
#ID_str <- unlist(lapply(1:nrow(df_tile_processed),function(i){unlist(strsplit(as.character(df_tile_processed$tile_id[i]),"_"))[2]}))
1084

  
1085
#combined_shp$tile_id <- df_tile_processed$tile_id
1086
 
1087
#r <- raster(lf_pred_list[i])
916
### Figure 10: Plot the difference in mosaics for processing tiles at 1500x4500 and 1000x3500
1088 917

  
1089
#plot(combined_shp)
1090 918

  
1091
#p0 <- spplot(combined_shp, "Stations",col.regions=matlab.like(100))
1092
#p1 <- spplot(usa_map,"ISO",colorkey=FALSE) #Use ISO instead of NAME_1 to see no color?
1093
#p2 <- spplot(can_map,"ISO",colorkey=FALSE) #Use ISO instead of NAME_1 to see no color?
1094
#p3 <- spplot(mex_map,"ISO",colorkey=FALSE) #Use ISO instead of NAME_1 to see no color?
1095

  
1096
#p0 +p1+p2+p3
919
reg_name <- "reg4"
920
for(i in 1:length(lf_m)){
921
  r_test<- raster(lf_m[i])
1097 922

  
1098
### Now plot number of training for monthly data
923
  m <- c(-Inf, -100, NA,  
924
         -100, 100, 1, 
925
         100, Inf, NA)
926
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
927
  rc <- reclassify(r_test, rclmat,filename="rc.tif",dataType="FLT4S",overwrite=T)
928
  raster_name <- unlist(strsplit(basename(lf_m[i]),"_"))
929
  date_proc <- raster_name[5]
930
  #paste(raster_name[1:7],collapse="_")
931
  r_pred <- mask(r_test,rc,filename=paste("CAI_TMAX_clim_month_mod1_all_",reg_name,"_",date_proc,"_masked.tif",sep=""),overwrite=TRUE)
932
  
933
  res_pix <- 1200
934
  #res_pix <- 480
1099 935

  
1100
#df_dat <- subset(pred_data_month_info, pred_mod == "mod1" & date =="20100115")
1101
#shp_dat <-merge(combined_shp,df_dat,by="tile_id")
1102
#shp_dat <-merge(x=combined_shp,y=df_dat,by="tile_id",all.x=T) #if tile is missing then add rows with NA
1103
#shp_dat <- merge(shp_dat,df_tile_processed,by="tile_id")
1104
#coordinates(shp_dat) <- cbind(shp_dat$lon,shp_dat$lat) 
1105
#proj4string(shp_dat) <- CRS_WGS84
936
  col_mfrow <- 1
937
  row_mfrow <- 1
1106 938
  
1107
#test <- overlay(combined_shp,shp_dat)
1108
#pol <- SpatialPolygons(combined_shp@polygons,proj4string=CRS(CRS_WGS84))
1109
#spp <- SpatialPolygonsDataFrame(pol,data=shp_dat)
939
  png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_prefix,".png",sep=""),
940
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
1110 941

  
1111
#p0 <- spplot(spp, "n_mod",col.regions=matlab.like(100))
1112
#p1 <- spplot(reg_layer,"ISO",colorkey=FALSE) #Use ISO instead of NAME_1 to see no color?
1113
#p0 + p1 + p2 + p3
942
  plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5)
943
  dev.off()
944
}
1114 945

  
1115 946
##################### END OF SCRIPT ######################

Also available in: Unified diff