8 |
8 |
# 5)runGAMFusion <- function(i,list_param) : daily step for fusion method, perform daily prediction
|
9 |
9 |
#
|
10 |
10 |
#AUTHOR: Benoit Parmentier
|
11 |
|
#DATE: 09/04/2013
|
|
11 |
#DATE: 10/03/2013
|
12 |
12 |
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--
|
13 |
13 |
|
14 |
14 |
##Comments and TODO:
|
... | ... | |
57 |
57 |
return(list_fitted_models)
|
58 |
58 |
}
|
59 |
59 |
|
|
60 |
#Function to glue all methods together...still need to separate fit and training for gwr and kriging, ok for now
|
|
61 |
interpolate_area_fun <- function(method_interp,list_models,s_raster,list_out_filename,data_df){
|
|
62 |
##Function to fit and predict an interpolation surface
|
|
63 |
##Author: Benoit Parmentier
|
|
64 |
##Function depends on other functions!!!
|
|
65 |
#inpputs:
|
|
66 |
#method_interp: interpolation method with value "gam","gwr","kriging"
|
|
67 |
#list_models: models to fit and predict as string (i.e.vector char)
|
|
68 |
#s_raster: stack with covariate variables, must match in name the data.frame input
|
|
69 |
#data_df: spatial point data.frame with covariates, must be projected match names of covariates
|
|
70 |
#list_out_filename: list of char containing output names for models
|
|
71 |
|
|
72 |
#Conver to formula object
|
|
73 |
list_formulas<-lapply(list_models,as.formula,env=.GlobalEnv) #mulitple arguments passed to lapply!!
|
|
74 |
cname<-paste("mod",1:length(list_formulas),sep="") #change to more meaningful name?
|
|
75 |
|
|
76 |
names(list_out_filename)<-cname
|
|
77 |
|
|
78 |
##Now carry out prediction
|
|
79 |
if(method_interp=="gam"){
|
|
80 |
|
|
81 |
#First fitting
|
|
82 |
mod_list<-fit_models(list_formulas,data_df) #only gam at this stage
|
|
83 |
names(mod_list)<-cname
|
|
84 |
|
|
85 |
#if raster provided then predict surface
|
|
86 |
if(!is.null(s_raster)){
|
|
87 |
#Second predict values for raster image...by providing fitted model list, raster brick and list of output file names
|
|
88 |
rast_pred_list<-predict_raster_model(mod_list,s_raster,list_out_filename)
|
|
89 |
names(rast_pred_list)<-cname
|
|
90 |
}
|
|
91 |
}
|
|
92 |
|
|
93 |
if(method_interp%in%c("gwr","kriging")){
|
|
94 |
|
|
95 |
#Call funciton to fit and predict gwr and/or kriging
|
|
96 |
#month_prediction_obj<-predict_auto_krige_raster_model(list_formulas,s_raster,data_month,list_out_filename)
|
|
97 |
rast_prediction_obj<-predict_autokrige_gwr_raster_model(method_interp,list_formulas,s_raster,data_df,list_out_filename)
|
|
98 |
|
|
99 |
mod_list <-rast_prediction_obj$list_fitted_models
|
|
100 |
rast_pred_list <-rast_prediction_obj$list_rast_pred
|
|
101 |
names(rast_pred_list)<-cname
|
|
102 |
}
|
|
103 |
|
|
104 |
#Now prepare to return object
|
|
105 |
interp_area_obj <-list(mod_list,list_formulas,rast_pred_list)
|
|
106 |
names(interp_area_obj) <- c("mod_list","list_formulas","rast_pred_list")
|
|
107 |
return(interp_area_obj)
|
|
108 |
}
|
|
109 |
|
60 |
110 |
####
|
61 |
111 |
#TODO:
|
62 |
112 |
#Add log file and calculate time and sizes for processes-outputs
|
... | ... | |
502 |
552 |
#6)y_var_name: name of the variable predicted - dailyTMax, dailyTMin
|
503 |
553 |
#7)out_prefix
|
504 |
554 |
#8)out_path
|
505 |
|
#
|
|
555 |
#9)list_models2 : interpolation model's formulas as string
|
|
556 |
#10)interp_methods2: "gam","gwr","kriging"
|
|
557 |
#11)s_raster: stack for covariates and toher variables
|
|
558 |
|
506 |
559 |
#The output is a list of four shapefile names produced by the function:
|
507 |
560 |
#1) list_temp: y_var_name
|
508 |
561 |
#2) rast_clim_list: list of files for temperature climatology predictions
|
... | ... | |
525 |
578 |
out_prefix<-list_param$out_prefix
|
526 |
579 |
dst<-list_param$dst #monthly station dataset
|
527 |
580 |
out_path <-list_param$out_path
|
|
581 |
list_models2 <-list_param$list_models2
|
|
582 |
interp_method2 <- list_param$interp_method2
|
|
583 |
s_raster <- list_param$s_raster
|
528 |
584 |
|
529 |
585 |
sampling_month_obj <- list_param$sampling_month_obj
|
530 |
586 |
daily_dev_sampling_dat <- list_param$daily_dev_sampling_dat
|
... | ... | |
568 |
624 |
day<-as.integer(strftime(date_proc, "%d"))
|
569 |
625 |
year<-as.integer(strftime(date_proc, "%Y"))
|
570 |
626 |
|
|
627 |
#Adding layer LST to the raster stack
|
|
628 |
#names(s_raster)<-covar_names
|
|
629 |
pos<-match("LST",names(s_raster)) #Find the position of the layer with name "LST", if not present pos=NA
|
|
630 |
s_raster<-dropLayer(s_raster,pos) # If it exists drop layer
|
|
631 |
LST<-subset(s_raster,LST_month)
|
|
632 |
names(LST)<-"LST"
|
|
633 |
s_raster<-addLayer(s_raster,LST) #Adding current month
|
|
634 |
|
571 |
635 |
#Now get monthly data...
|
572 |
636 |
|
573 |
637 |
ghcn.month.subsets<-sampling_month_obj$ghcn_data
|
... | ... | |
671 |
735 |
#only one delta in this case!!!
|
672 |
736 |
#list(mod)
|
673 |
737 |
|
674 |
|
model_name<-paste("mod_stat_kr",sep="_")
|
675 |
|
daily_delta_xy<-as.matrix(cbind(dmoday$x,dmoday$y))
|
676 |
|
fitdelta<-Krig(daily_delta_xy,daily_delta,theta=1e5) #use TPS or krige
|
677 |
|
mod_krtmp2 <- fitdelta
|
678 |
|
#names(mod_krtmp2)[k] <- model_name
|
679 |
|
#data_s$daily_delta<-daily_delta
|
680 |
|
#rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
681 |
|
rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
682 |
|
rast_clim_mod <- stack(rast_clim_list)
|
683 |
|
names(rast_clim_mod) <- names(rast_clim_list)
|
684 |
|
rast_clim_month <- subset(rast_clim_mod,1) #example layer to interpolate to
|
685 |
|
|
686 |
|
daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the bias surface...
|
|
738 |
if(is.null(list_models2)){ #change here...
|
|
739 |
|
|
740 |
list_daily_delta_rast <- vector("list",length=1) #only one delta surface in this case!!
|
|
741 |
list_mod_krtmp2 <- vector("list",length=1) #only one delta model in this case!!
|
|
742 |
|
|
743 |
model_name<-paste("mod_stat_kr",sep="_")
|
|
744 |
daily_delta_xy<-as.matrix(cbind(dmoday$x,dmoday$y))
|
|
745 |
fitdelta<-Krig(daily_delta_xy,daily_delta,theta=1e5) #use TPS or krige
|
|
746 |
mod_krtmp2 <- fitdelta
|
|
747 |
#names(mod_krtmp2)[k] <- model_name
|
|
748 |
#data_s$daily_delta<-daily_delta
|
|
749 |
#rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
|
750 |
rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
|
751 |
rast_clim_mod <- stack(rast_clim_list)
|
|
752 |
names(rast_clim_mod) <- names(rast_clim_list)
|
|
753 |
rast_clim_month <- subset(rast_clim_mod,1) #example layer to interpolate to
|
|
754 |
|
|
755 |
daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the of the daily devation
|
|
756 |
#there is only one daily devation (delta) sruface in this case
|
|
757 |
|
|
758 |
#To many I/O out of swap memory on atlas
|
|
759 |
#Saving kriged surface in raster images
|
|
760 |
data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
761 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
|
762 |
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
|
763 |
writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
|
764 |
|
|
765 |
list_daily_delta_rast[[1]] <- raster_name_delta
|
|
766 |
list_mod_krtmp2[[1]] <- mod_krtmp2
|
|
767 |
}
|
687 |
768 |
|
688 |
|
#To many I/O out of swap memory on atlas
|
689 |
|
#Saving kriged surface in raster images
|
690 |
|
data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
691 |
|
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
692 |
|
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
693 |
|
writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
|
769 |
if(!is.null(list_models2)){ #change here...
|
|
770 |
list_daily_delta_rast <- vector("list",length=1) #several delta surfaces in this case but stored as one list!!
|
|
771 |
list_mod_krtmp2 <- vector("list",length=1) #several delta model in this case but stored as one list!!
|
|
772 |
|
|
773 |
dev_mod_name<-paste("dev_mod",1:length(list_models2),sep="") #change to more meaningful name?
|
|
774 |
model_name<-paste("mod_stat_",sep="_")
|
|
775 |
#Now generate file names for the predictions...
|
|
776 |
list_out_filename<-vector("list",length(list_models2))
|
|
777 |
names(list_out_filename)<- dev_mod_name
|
|
778 |
|
|
779 |
##Change name...
|
|
780 |
for (j in 1:length(list_out_filename)){
|
|
781 |
#j indicate which month is predicted, var indicates TMIN or TMAX
|
|
782 |
data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
783 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],
|
|
784 |
"_",interp_method2,"_",dev_mod_name[j],sep="")
|
|
785 |
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
|
786 |
|
|
787 |
list_out_filename[[j]]<-raster_name_delta
|
|
788 |
}
|
|
789 |
|
|
790 |
#Now call function
|
|
791 |
|
|
792 |
#for (j in 1:length(list_models2)){
|
|
793 |
dmoday$y_var <- daily_delta
|
|
794 |
#coordinates(data_s)<-cbind(data_s$x,data_s$y)
|
|
795 |
#proj4string(data_s)<-proj_str
|
|
796 |
#coordinates(data_v)<-cbind(data_v$x,data_v$y)
|
|
797 |
#proj4string(data_v)<-proj_str
|
|
798 |
|
|
799 |
interp_area_obj <-interpolate_area_fun(interp_method2,list_models2,s_raster,list_out_filename,dmoday)
|
|
800 |
rast_pred_list <- interp_area_obj$rast_pred_list
|
|
801 |
rast_pred_list <-rast_pred_list[!sapply(rast_pred_list,is.null)] #remove NULL elements in list
|
|
802 |
list_daily_delta_rast[[1]] <-rast_pred_list
|
|
803 |
#names(list_daily_delta_rast) <- names(daily_delta_df)
|
|
804 |
list_mod_krtmp2[[1]] <-interp_area_obj$mod_list
|
|
805 |
}
|
694 |
806 |
}
|
695 |
807 |
|
696 |
808 |
if(use_clim_image==TRUE){
|
... | ... | |
739 |
851 |
|
740 |
852 |
names(extract_data_s) <- paste(names(extract_data_s),"_m",sep="") # "m" for monthly predictions...
|
741 |
853 |
dmoday <-spCbind(dmoday,extract_data_s) #contains the predicted clim at locations
|
742 |
|
|
|
854 |
dmoday <-spCbind(dmoday,daily_delta_df) #contains the predicted clim at locations
|
743 |
855 |
#Now krige forevery model !! loop
|
744 |
856 |
list_mod_krtmp2 <- vector("list",length=nlayers(rast_clim_mod))
|
745 |
857 |
list_daily_delta_rast <- vector("list",length=nlayers(rast_clim_mod))
|
746 |
|
|
|
858 |
names(list_daily_delta_rast) <- names(daily_delta_df)
|
|
859 |
names(list_mod_krtmp2) <- names(daily_delta_df)
|
747 |
860 |
for(k in 1:nlayers(rast_clim_mod)){
|
748 |
861 |
|
749 |
|
daily_delta <- daily_delta_df[[k]]
|
|
862 |
daily_delta <- daily_delta_df[[k]] #Current daily deviation being process: the reference monthly prediction varies...
|
750 |
863 |
#model_name<-paste("mod_kr","day",sep="_")
|
751 |
864 |
model_name<- names(daily_delta_df)[k]
|
752 |
865 |
|
753 |
|
daily_delta_xy<-as.matrix(cbind(dmoday$x,dmoday$y))
|
754 |
|
fitdelta<-Krig(daily_delta_xy,daily_delta,theta=1e5) #use TPS or krige
|
755 |
|
list_mod_krtmp2[[k]] <-fitdelta
|
756 |
|
names(list_mod_krtmp2)[k] <- model_name
|
757 |
|
#data_s$daily_delta<-daily_delta
|
758 |
|
#rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
759 |
|
rast_clim_month <- subset(rast_clim_mod,1) #example layer to interpolate to
|
|
866 |
if(is.null(list_models2)){
|
|
867 |
daily_delta_xy<-as.matrix(cbind(dmoday$x,dmoday$y))
|
|
868 |
fitdelta<-Krig(daily_delta_xy,daily_delta,theta=1e5) #use TPS or krige
|
|
869 |
list_mod_krtmp2[[k]] <-fitdelta
|
|
870 |
names(list_mod_krtmp2)[k] <- model_name
|
|
871 |
#data_s$daily_delta<-daily_delta
|
|
872 |
#rast_clim_list<-rast_clim_yearlist[[index_m]] #select relevant monthly climatology image ...
|
|
873 |
rast_clim_month <- subset(rast_clim_mod,1) #example layer to interpolate to
|
|
874 |
|
|
875 |
daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the bias surface...
|
|
876 |
|
|
877 |
#list_daily_delta_rast[[k]] <- raster_name_delta
|
|
878 |
|
|
879 |
data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
880 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
|
881 |
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
|
882 |
|
|
883 |
writeRaster(delta_rast_s, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
|
884 |
#writeRaster(r_spat, NAflag=NA_flag_val,filename=raster_name,bylayer=TRUE,bandorder="BSQ",overwrite=TRUE)
|
|
885 |
|
|
886 |
#raster_name_delta <- list_daily_delta_rast
|
|
887 |
#mod_krtmp2 <- list_mod_krtmp2
|
|
888 |
list_daily_delta_rast[[k]] <- raster_name_delta
|
|
889 |
|
|
890 |
}
|
760 |
891 |
|
761 |
|
daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the bias surface...
|
|
892 |
if (!is.null(list_models2)){
|
|
893 |
|
|
894 |
#list_formulas<-lapply(list_models,as.formula,env=.GlobalEnv) #mulitple arguments passed to lapply!!
|
|
895 |
dev_mod_name<-paste("dev_mod",1:length(list_models2),sep="") #change to more meaningful name?
|
|
896 |
|
|
897 |
#Now generate file names for the predictions...
|
|
898 |
list_out_filename<-vector("list",length(list_models2))
|
|
899 |
names(list_out_filename)<- dev_mod_name
|
|
900 |
|
|
901 |
##Change name...
|
|
902 |
for (j in 1:length(list_out_filename)){
|
|
903 |
#j indicate which month is predicted, var indicates TMIN or TMAX
|
|
904 |
data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
905 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],
|
|
906 |
"_",interp_method2,"_",dev_mod_name[j],sep="")
|
|
907 |
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
|
908 |
|
|
909 |
list_out_filename[[j]]<-raster_name_delta
|
|
910 |
}
|
|
911 |
|
|
912 |
#Now call function
|
|
913 |
|
|
914 |
#for (j in 1:length(list_models2)){
|
|
915 |
dmoday$y_var <- daily_delta
|
|
916 |
#coordinates(data_s)<-cbind(data_s$x,data_s$y)
|
|
917 |
#proj4string(data_s)<-proj_str
|
|
918 |
#coordinates(data_v)<-cbind(data_v$x,data_v$y)
|
|
919 |
#proj4string(data_v)<-proj_str
|
|
920 |
|
|
921 |
interp_area_obj <-interpolate_area_fun(interp_method2,list_models2,s_raster,list_out_filename,dmoday)
|
|
922 |
rast_pred_list <- interp_area_obj$rast_pred_list
|
|
923 |
names(rast_pred_list) <- dev_mod_name
|
|
924 |
rast_pred_list <-rast_pred_list[!sapply(rast_pred_list,is.null)] #remove NULL elements in list
|
|
925 |
list_daily_delta_rast[[k]] <-rast_pred_list
|
|
926 |
names(list_daily_delta_rast) <- names(daily_delta_df)
|
|
927 |
mod_list <-interp_area_obj$mod_list
|
|
928 |
names(mod_list) <- dev_mod_name
|
|
929 |
list_mod_krtmp2[[k]] <-interp_area_obj$mod_list
|
|
930 |
}
|
762 |
931 |
|
763 |
|
list_daily_delta_rast[[k]] <- daily_delta_rast
|
764 |
|
#list_daily_delta_rast[[k]] <- raster_name_delta
|
765 |
932 |
}
|
766 |
933 |
|
767 |
934 |
#Too many I/O out of swap memory on atlas
|
768 |
935 |
#Saving kriged surface in raster images
|
769 |
|
delta_rast_s <-stack(list_daily_delta_rast)
|
770 |
|
names(delta_rast_s) <- names(daily_delta_df)
|
|
936 |
#delta_rast_s <-stack(list_daily_delta_rast)
|
|
937 |
#names(delta_rast_s) <- names(daily_delta_df)
|
771 |
938 |
|
772 |
939 |
#Should check that all delta images have been created for every model!!! remove from list empty elements!!
|
773 |
940 |
|
... | ... | |
776 |
943 |
#raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
777 |
944 |
#writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
778 |
945 |
|
779 |
|
data_name<-paste("daily_delta_",y_var_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
780 |
|
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
781 |
|
raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
|
946 |
#data_name<-paste("daily_delta_",y_var_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
947 |
# sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
|
948 |
#raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
|
782 |
949 |
|
783 |
|
writeRaster(delta_rast_s, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
|
950 |
#writeRaster(delta_rast_s, filename=raster_name_delta,overwrite=TRUE) #Writing the data in a raster file format...(IDRISI)
|
784 |
951 |
#writeRaster(r_spat, NAflag=NA_flag_val,filename=raster_name,bylayer=TRUE,bandorder="BSQ",overwrite=TRUE)
|
785 |
952 |
|
786 |
953 |
#raster_name_delta <- list_daily_delta_rast
|
787 |
|
mod_krtmp2 <- list_mod_krtmp2
|
|
954 |
#mod_krtmp2 <- list_mod_krtmp2
|
788 |
955 |
}
|
789 |
956 |
|
790 |
957 |
#########
|
... | ... | |
798 |
965 |
temp_list<-vector("list",nlayers(rast_clim_mod))
|
799 |
966 |
for (k in 1:nlayers(rast_clim_mod)){
|
800 |
967 |
if(use_clim_image==TRUE){
|
801 |
|
daily_delta_rast <- list_daily_delta_rast[[k]]
|
|
968 |
if (is.null(list_models2)){
|
|
969 |
daily_delta_rast <- raster(list_daily_delta_rast[[k]]) #There is only one image of deviation per model if list_models2 is NULL
|
|
970 |
}
|
|
971 |
if (!is.null(list_models2)){ #then possible multiple daily dev predictions
|
|
972 |
daily_delta_rast <- stack(unlist(list_daily_delta_rast[[k]]))
|
|
973 |
}
|
|
974 |
#daily_delta_rast <- subset(delta_rast_s,k)
|
802 |
975 |
}
|
803 |
976 |
#if use_clim_image==FALSE then daily__delta_rast already defined earlier...
|
804 |
977 |
|
|
978 |
if(use_clim_image==FALSE){
|
|
979 |
if (is.null(list_models2)){
|
|
980 |
daily_delta_rast <- raster(list_daily_delta_rast[[1]]) #There is only one image of deviation per model if list_models2 is NULL
|
|
981 |
}
|
|
982 |
if (!is.null(list_models2)){ #then possible multiple daily dev predictions hence use stack
|
|
983 |
daily_delta_rast <- stack(unlist(list_daily_delta_rast[[1]]))
|
|
984 |
}
|
|
985 |
#daily_delta_rast <- subset(delta_rast_s,k)
|
|
986 |
}
|
|
987 |
|
805 |
988 |
#rast_clim_month<-raster(rast_clim_list[[k]])
|
806 |
|
rast_clim_month <- subset(rast_clim_mod,k)
|
807 |
|
temp_predicted<-rast_clim_month + daily_delta_rast
|
808 |
|
|
809 |
|
data_name<-paste(y_var_name,"_predicted_",names(rast_clim_mod)[k],"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
810 |
|
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
811 |
|
raster_name<-file.path(out_path,paste(interpolation_method,"_",data_name,out_prefix,".tif", sep=""))
|
812 |
|
writeRaster(temp_predicted, filename=raster_name,overwrite=TRUE)
|
813 |
|
temp_list[[k]]<-raster_name
|
|
989 |
rast_clim_month <- subset(rast_clim_mod,k) #long term monthly prediction
|
|
990 |
if (is.null(list_models2)){
|
|
991 |
temp_predicted<-rast_clim_month + daily_delta_rast
|
|
992 |
data_name<-paste(y_var_name,"_predicted_",names(rast_clim_mod)[k],"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
993 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
|
|
994 |
raster_name<-file.path(out_path,paste(interpolation_method,"_",data_name,out_prefix,".tif", sep=""))
|
|
995 |
writeRaster(temp_predicted, filename=raster_name,overwrite=TRUE)
|
|
996 |
temp_list[[k]]<-raster_name
|
|
997 |
}
|
|
998 |
if (!is.null(list_models2)){
|
|
999 |
dev_mod_name <- paste("dev_mod",1:length(list_models2),sep="") #change to more meaningful name?
|
|
1000 |
raster_name_list <- vector("list",length(list_models2))
|
|
1001 |
for(j in 1:length(list_models2)){
|
|
1002 |
temp_predicted <- rast_clim_month + subset(daily_delta_rast,j)
|
|
1003 |
data_name<-paste(y_var_name,"_predicted_",names(rast_clim_mod)[k],"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
|
|
1004 |
sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],"_",
|
|
1005 |
interp_method2,"_",dev_mod_name[j],sep="")
|
|
1006 |
raster_name<-file.path(out_path,paste(interpolation_method,"_",data_name,out_prefix,".tif", sep=""))
|
|
1007 |
writeRaster(temp_predicted, filename=raster_name,overwrite=TRUE)
|
|
1008 |
raster_name_list[[j]] <- raster_name
|
|
1009 |
}
|
|
1010 |
names(raster_name_list) <- dev_mod_name
|
|
1011 |
temp_list[[k]]<-raster_name_list #record names of the daily predictions
|
|
1012 |
}
|
814 |
1013 |
}
|
815 |
1014 |
|
816 |
1015 |
##########
|
817 |
1016 |
# STEP 5 - Prepare output object to return
|
818 |
1017 |
##########
|
819 |
1018 |
|
820 |
|
data_s<-dmoday #put the
|
|
1019 |
data_s <- dmoday #put the
|
821 |
1020 |
#coordinates(data_s)<-cbind(data_s$x,data_s$y)
|
822 |
1021 |
#proj4string(data_s)<-proj_str
|
823 |
1022 |
coordinates(data_v)<-cbind(data_v$x,data_v$y)
|
... | ... | |
826 |
1025 |
#mod_krtmp2<-list_mod_krtmp2
|
827 |
1026 |
#mod_krtmp2<-fitdelta
|
828 |
1027 |
|
829 |
|
model_name<-paste("mod_kr","day",sep="_")
|
|
1028 |
model_name<-paste("mod_","day",sep="_")
|
830 |
1029 |
|
831 |
1030 |
names(temp_list)<-names(rast_clim_list)
|
832 |
|
|
|
1031 |
|
833 |
1032 |
#add data_month_s and data_month_v?
|
834 |
|
delta_obj<-list(temp_list,rast_clim_list,raster_name_delta, data_s, data_v,
|
835 |
|
modst,data_month_v,sampling_dat[index_d,],daily_dev_sampling_dat[i,],mod_krtmp2)
|
|
1033 |
delta_obj<-list(temp_list,rast_clim_list,list_daily_delta_rast, data_s, data_v,
|
|
1034 |
modst,data_month_v,sampling_dat[index_d,],daily_dev_sampling_dat[i,],list_mod_krtmp2)
|
836 |
1035 |
|
837 |
1036 |
obj_names<-c(y_var_name,"clim","delta","data_s","data_v",
|
838 |
1037 |
"data_month_s","data_month_v","sampling_dat","daily_dev_sampling_dat",model_name)
|
modificatons for multi-time scale methods, adding gam,gwr,kriging options for daily deviation surfaces