Revision 6a845b96
Added by Benoit Parmentier about 10 years ago
climate/research/oregon/interpolation/global_run_scalingup_assessment_part2.R | ||
---|---|---|
845 | 845 |
dev.off() |
846 | 846 |
} |
847 | 847 |
|
848 |
#################### IMAGE DIFFERENCING BETWEEN 1000x3000 and 1500x4500 predictions for reg4 and reg5 |
|
849 |
|
|
850 |
#### Use previous results for differencing |
|
851 |
### for reg4_1500x4500: use "mod2 in this case... |
|
852 |
|
|
853 |
out_prefix_str <- "reg4_1500x4500" |
|
854 |
lf_mosaics_reg4_1500x4500 <- mixedsort( |
|
855 |
list.files(path= |
|
856 |
"/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/reg4_1500x4500", |
|
857 |
pattern=".*._mod2_all_mean.tif$",full.names=T) |
|
858 |
) |
|
859 |
lf_m <- lf_mosaics_reg4_1500x4500 |
|
860 |
out_dir_str <- "/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/" |
|
861 |
|
|
862 |
reg_name <- "reg4_1500x4500" |
|
863 |
#lapply() |
|
864 |
#list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir=out_dir_str,out_suffix=out_prefix) |
|
865 |
list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_prefix) |
|
866 |
|
|
867 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
868 |
#debug(plot_daily_mosaics) |
|
869 |
#test<- plot_daily_mosaics(1,list_param=list_param_plot_daily_mosaics)#,mc.preschedule)#=FALSE,mc.cores = 6) |
|
870 |
|
|
871 |
lf_m_mask_reg4_1500x4500 <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
872 |
|
|
873 |
### for reg5_1500x4500: use "mod1 in this case |
|
874 |
|
|
875 |
out_prefix_str <- "reg5_1500x4500" |
|
876 |
lf_mosaics_reg5 <- mixedsort( |
|
877 |
list.files(path= |
|
878 |
"/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/reg5_1500x4500", |
|
879 |
pattern=".*._mod1_all_mean.tif$",full.names=T) |
|
880 |
) |
|
881 |
lf_m <- lf_mosaics_reg5 |
|
882 |
out_dir_str <- "/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/" |
|
883 |
reg_name <- "reg5_1500x4500" |
|
884 |
#lapply() |
|
885 |
list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_prefix) |
|
886 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
887 |
|
|
888 |
lf_m_mask_reg5_1500x4500 <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
889 |
|
|
890 |
### for reg5_1500x4500: use "mod1 in this case, this is Africa |
|
891 |
|
|
892 |
out_prefix_str <- "reg5_1000x3000" |
|
893 |
lf_mosaics_reg5 <- mixedsort( |
|
894 |
list.files(path= |
|
895 |
"/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/reg5_1000x4500", |
|
896 |
pattern=".*._mod1_all_mean.tif$",full.names=T) |
|
897 |
) |
|
898 |
lf_m <- lf_mosaics_reg5 |
|
899 |
out_dir_str <- "/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/" |
|
900 |
reg_name <- "reg5_1500x4500" |
|
901 |
#lapply() |
|
902 |
list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_prefix) |
|
903 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
848 | 904 |
|
849 |
#### for reg5
|
|
905 |
lf_m_mask_reg5_1500x4500 <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6)
|
|
850 | 906 |
|
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)) |
|
853 | 907 |
|
854 |
reg_name <- "reg5_1500x4500" |
|
855 |
#daily |
|
856 |
lf_m <- lf_mosaics_reg5[13:length(lf_mosaics_reg5)] |
|
857 | 908 |
|
858 |
for(i in 1:length(lf_m)){ |
|
859 |
r_test<- raster(lf_m[i]) |
|
860 | 909 |
|
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 |
|
910 |
### for reg4_1000x3000: use "mod1 in this case |
|
873 | 911 |
|
874 |
col_mfrow <- 1 |
|
875 |
row_mfrow <- 1 |
|
912 |
out_prefix_str <- "reg4_1000x3000" |
|
913 |
lf_mosaics_reg5 <- mixedsort( |
|
914 |
list.files(path= |
|
915 |
"/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/reg5_1000x3000", |
|
916 |
pattern=".*._mod1_all_mean.tif$",full.names=T) |
|
917 |
) |
|
918 |
lf_m <- lf_mosaics_reg5 |
|
919 |
out_dir_str <- "/data/project/layers/commons/NEX_data/output_run10_global_analyses_12152014/mosaics/" |
|
920 |
reg_name <- "reg5_1000x4500" |
|
921 |
#lapply() |
|
922 |
list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str,out_suffix=out_prefix) |
|
923 |
#lf_m_mask_reg4_1500x4500 <- mclapply(1:2,FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
924 |
|
|
925 |
lf_m_mask_reg5_1000x4500 <- mclapply(1:length(lf_m),FUN=plot_daily_mosaics,list_param=list_param_plot_daily_mosaics,mc.preschedule=FALSE,mc.cores = 6) |
|
926 |
|
|
927 |
|
|
928 |
plot_daily_mosaics <- function(i,list_param_plot_daily_mosaics){ |
|
929 |
#Purpose: |
|
930 |
#This functions mask mosaics files for a default range (-100,100 deg). |
|
931 |
#It produces a masked tif in a given dataType format (FLT4S) |
|
932 |
#It creates a figure of mosaiced region being interpolated. |
|
933 |
#Author: Benoit Parmentier |
|
934 |
#Parameters: |
|
935 |
#lf_m: list of files |
|
936 |
#reg_name:region name with tile size included |
|
937 |
#To do: |
|
938 |
#Add filenames |
|
939 |
#Add range |
|
940 |
#Add output dir |
|
941 |
#Add dataType_val option |
|
876 | 942 |
|
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) |
|
943 |
##### BEGIN ######## |
|
944 |
|
|
945 |
#Parse the list of parameters |
|
946 |
lf_m <- list_param_plot_daily_mosaics$lf_m |
|
947 |
reg_name <- list_param_plot_daily_mosaics$reg_name |
|
948 |
out_dir_str <- list_param_plot_daily_mosaics$out_dir_str |
|
949 |
out_suffix <- list_param_plot_daily_mosaics$out_suffix |
|
879 | 950 |
|
880 |
plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5) |
|
881 |
dev.off() |
|
882 |
} |
|
883 | 951 |
|
884 |
### for reg4
|
|
952 |
#list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str)
|
|
885 | 953 |
|
886 |
reg_name <- "reg2" |
|
887 |
for(i in 1:length(lf_m)){
|
|
954 |
|
|
955 |
#rast_list <- vector("list",length=length(lf_m))
|
|
888 | 956 |
r_test<- raster(lf_m[i]) |
889 | 957 |
|
890 | 958 |
m <- c(-Inf, -100, NA, |
891 | 959 |
-100, 100, 1, |
892 |
100, Inf, NA) |
|
960 |
100, Inf, NA) #can change the thresholds later
|
|
893 | 961 |
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]
|
|
962 |
rc <- reclassify(r_test, rclmat,filename=paste("rc_tmp_",i,".tif",sep=""),dataType="FLT4S",overwrite=T)
|
|
963 |
file_name <- unlist(strsplit(basename(lf_m[i]),"_"))
|
|
964 |
date_proc <- file_name[7] #specific tot he current naming of files
|
|
897 | 965 |
#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) |
|
966 |
#add filename option later |
|
967 |
extension_str <- extension(filename(r_test)) |
|
968 |
raster_name_tmp <- gsub(extension_str,"",basename(filename(r_test))) |
|
969 |
raster_name <- file.path(out_dir_str,paste(raster_name_tmp,"_",date_proc,"_masked.tif",sep="")) |
|
970 |
r_pred <- mask(r_test,rc,filename=raster_name,overwrite=TRUE) |
|
899 | 971 |
|
900 | 972 |
res_pix <- 1200 |
901 | 973 |
#res_pix <- 480 |
... | ... | |
903 | 975 |
col_mfrow <- 1 |
904 | 976 |
row_mfrow <- 1 |
905 | 977 |
|
906 |
png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_prefix,".png",sep=""),
|
|
978 |
png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_suffix,".png",sep=""),
|
|
907 | 979 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
908 | 980 |
|
909 | 981 |
plot(r_pred,main=paste("climatology month ",date_proc , " ", reg_name,sep=""),cex.main=1.5) |
910 | 982 |
dev.off() |
983 |
|
|
984 |
return(raster_name) |
|
985 |
|
|
911 | 986 |
} |
912 | 987 |
|
913 | 988 |
|
914 |
|
|
915 | 989 |
###################### |
916 | 990 |
### Figure 10: Plot the difference in mosaics for processing tiles at 1500x4500 and 1000x3500 |
917 | 991 |
|
Also available in: Unified diff
NEX assessment minor changes