Project

General

Profile

« Previous | Next » 

Revision 1cd7ecf2

Added by Benoit Parmentier over 11 years ago

GAM fusion raster prediction, transforming script in function with explicit passing and tracking of arguments

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
1
##################    MULTI SAMPLING GAM FUSION METHOD ASSESSMENT   ####################################
2
############################ Merging LST and station data ##########################################
3
#This script interpolates tmax values using MODIS LST and GHCND station data                      
4
#interpolation area. It requires the text file of stations and a shape file of the study area.           
1
#########################    Raster prediction GAM FUSION    ####################################
2
############################ Interpolation of temperature for given processing region ##########################################
3
#This script interpolates temperature values using MODIS LST, covariates and GHCND station data.                      
4
#It requires the text file of stations and a shape file of the study area.           
5 5
#Note that the projection for both GHCND and study area is lonlat WGS84.       
6 6
#Options to run this program are:
7 7
#1) Multisampling: vary the porportions of hold out and use random samples for each run
......
11 11
#5)GAM fusion: possibilty of running GAM+FUSION or GAM+CAI and other options added
12 12
#The interpolation is done first at the monthly time scale then delta surfaces are added.
13 13
#AUTHOR: Benoit Parmentier                                                                        
14
#DATE: 03/05/2013                                                                                 
14
#DATE: 03/12/2013                                                                                 
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568--                                   
16 16
###################################################################################################
17 17

  
......
38 38
#infile_locs<-"stations_venezuela_region_y2010_2010_VE_02082013.shp"
39 39
infile_covariates<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
40 40
var<-"TMAX"
41
out_prefix<-"_365d_GAM_fus5_all_lstd_02202013"                #User defined output prefix
41
#out_prefix<-"_365d_GAM_fus5_all_lstd_02202013"                #User defined output prefix should be defined in master script
42 42
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84: same as earlier
43 43

  
44 44
infile_monthly<-list_outfiles$monthly_covar_ghcn_data #outile4 from database_covar script
......
83 83
setwd(in_path)
84 84

  
85 85

  
86
list_param_data_prep<-c(infile_monthly,infile_daily,infile_locs,infile_covariates,var,out_prefix,CRS_locs_WGS84)
86
#PARSING INPUTS/ARGUMENTS
87
list_param_data_prep<-c(infile_monthly,infile_daily,infile_locs,infile_covariates,covar_names,var,out_prefix,CRS_locs_WGS84)
87 88
list_param_raster_prediction<-c(list_param_data_prep,
88 89
                                seed_number,nb_sample,step,constant,prop_minmax,infile_dates,
89 90
                                list_models,lst_avg,in_path,out_path,script_path,
90 91
                                interpolation_method)
91 92

  
93
#9 parameters used in the data preparation stage and input in the current script
94
list_param_data_prep<-list_param_raster_prediction$list_param_data_prep
95
infile_monthly<-list_param_data_prep$infile_monthly
96
infile_daily<-list_param_data_prep$infile_daily
97
infile_locs<-list_param_data_prep$infile_locs
98
infile_covariates<-list_param_data_prep$infile_covariates
99
covar_names<- list_param_data_prep$covar_names
100
var<-list_param_data_prep$var
101
out_prefix<-list_param_data_prep$out_prefix
102
CRS_locs_WGS84<-list_param_data_prep$CRS_locs_WGS84
103

  
104
#6 parameters for sampling function
105
seed_number<-list_param_raster_prediction$seed_number
106
nb_sample<-list_param_raster_prediction$nb_sample
107
step<-list_param_raster_prediction$step
108
constant<-list_param_raster_prediction$constant
109
prop_minmax<-list_param_raster_prediction$prop_minmax
110
infile_dates<-list_param_raster_prediction$infile_dates
111

  
112
#6 additional parameters for monthly climatology and more
113
list_models<-list_param_raster_prediction$list_models
114
lst_avg<-list_param_raster_prediction$lst_avg
115
in_path<-list_param_raster_prediction$in_path
116
out_path<-list_param_raster_prediction$out_path
117
script_path<-list_param_raster_prediction$script_path
118
interpolation_method<-list_param_raster_prediction$interpolation_method
92 119

  
93 120
source(file.path(script_path,"sampling_script_functions_03052013.R"))
94
source(file.path(script_path,"GAM_fusion_function_multisampling_03052013.R"))
121
source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
95 122
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_02262013.R"))
96 123

  
97 124

  
......
172 199
#First predict at the monthly time scale: climatology
173 200
writeLines("Predictions at monthly scale:",con=log_file,sep="\n")
174 201
t1<-proc.time()
175
gamclim_fus_mod<-mclapply(1:12, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
202
j=12
203
list_param_runClim_KGFusion<-list(j,s_raster,covar_names,list_models,dst,var,y_var_name, out_prefix)
204
names(list_param_runClim_KGFusion)<-c("list_index","covar_rast","covar_names","list_models","dst","var","y_var_name","out_prefix")
205
source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
206

  
207
gamclim_fus_mod<-mclapply(1:6, list_param=list_param_runClim_KGFusion, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
176 208
#gamclim_fus_mod<-mclapply(1:6, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
177 209
save(gamclim_fus_mod,file= paste("gamclim_fus_mod",out_prefix,".RData",sep=""))
178 210
t2<-proc.time()-t1

Also available in: Unified diff