Project

General

Profile

« Previous | Next » 

Revision 3b4bb643

Added by Benoit Parmentier over 11 years ago

adding GWR daily method, test in Oregon

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
11 11
#5)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: 06/05/2013                                                                                 
14
#DATE: 06/08/2013                                                                                 
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#568--     
16 16
#
17 17
# TO DO:
......
68 68
  library(plotrix)
69 69
  library(maptools)
70 70
  library(gdata) #Nesssary to use cbindX
71
  library(automap)
71
  library(automap)  #autokrige function
72
  library(spgwr)   #GWR method
73
  
72 74
  ### Parameters and arguments
73 75
  #PARSING INPUTS/ARGUMENTS
74 76
#   
......
104 106
  interpolation_method<-list_param_raster_prediction$interpolation_method
105 107
  
106 108
  setwd(out_path)
107
  #Sourcing in the master script to avoid confusion on the latest versions of scripts and functions!!!
108
  
109
  #source(file.path(script_path,"sampling_script_functions_03122013.R"))
110
  #source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
111
  #source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_03182013.R"))
112 109
  
113 110
  ###################### START OF THE SCRIPT ########################
114 111
   
......
184 181
    names(list_param_runClim_KGFusion)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","var","y_var_name","out_prefix","out_path")
185 182
    #source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
186 183
    clim_method_mod_obj<-mclapply(1:12, list_param=list_param_runClim_KGFusion, runClim_KGFusion,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
187
    #test<-runClim_KGFusion(1,list_param=list_param_runClim_KGFusion)
184
    men#test<-runClim_KGFusion(1,list_param=list_param_runClim_KGFusion)
188 185
    #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
189 186
    save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep="")))
190 187
    list_tmp<-vector("list",length(clim_method_mod_obj))
......
226 223
  cat(paste("Local Date and Time: ",as.character(Sys.time()),sep=""),
227 224
      file=log_fname,sep="\n")
228 225
  
226
  #TODO : Same call for all functions!!! Replace by one "if" for all multi time scale methods...
229 227
  if (interpolation_method=="gam_CAI" | interpolation_method=="gam_fusion"){
230 228
    #input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn
231 229
    list_param_run_prediction_daily_deviation <-list(i,clim_yearlist,sampling_obj,dst,var,y_var_name, interpolation_method,out_prefix,out_path)
......
237 235
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
238 236
   }
239 237
  
238
  #TODO : Same call for all functions!!! Replace by one "if" for all daily single time scale methods...
240 239
  if (interpolation_method=="gam_daily"){
241 240
    #input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn
242 241
    
......
262 261
    
263 262
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
264 263
    
264
  }
265
  
266
  if (interpolation_method=="gwr_daily"){
267
    #input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn
268
    i<-1
269
    list_param_run_prediction_gwr_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path)
270
    names(list_param_run_prediction_gwr_daily)<-c("list_index","covar_rast","covar_names","lst_avg","list_models","dst","var","y_var_name","sampling_obj","interpolation_method","out_prefix","out_path")
271
    #test <- run_interp_day_fun(1,list_param_run_prediction_gwr_daily)
272
    method_mod_obj<-mclapply(1:length(sampling_obj$ghcn_data_day),list_param=list_param_run_prediction_gwr_daily,run_interp_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
273
    #method_mod_obj<-mclapply(1:9,list_param=list_param_run_prediction_gwr_daily,run_interp_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
274
    #method_mod_obj<-mclapply(1:18,list_param=list_param_run_prediction_kriging_daily,runKriging_day_fun,mc.preschedule=FALSE,mc.cores = 9) #This is the end bracket from mclapply(...) statement
275
    
276
    save(method_mod_obj,file= file.path(out_path,paste("method_mod_obj_",interpolation_method,"_",y_var_name,out_prefix,".RData",sep="")))
277
    
265 278
  }
266 279
  t2<-proc.time()-t1
267 280
  cat(as.character(t2),file=log_fname,sep="\n", append=TRUE)
......
326 339
    save(raster_prediction_obj,file= file.path(out_path,paste("raster_prediction_obj_",interpolation_method,"_", y_var_name,out_prefix,".RData",sep="")))
327 340
    
328 341
  }
329
  
330
  if (interpolation_method=="gam_daily" | interpolation_method=="kriging_daily" ){
342
  #use %in% instead of "|" operator
343
  if (interpolation_method=="gam_daily" | interpolation_method=="kriging_daily" | interpolation_method=="gwr_daily"){
331 344
    raster_prediction_obj<-list(method_mod_obj,validation_mod_obj,tb_diagnostic_v,
332 345
                                summary_metrics_v,summary_month_metrics_v)
333 346
    names(raster_prediction_obj)<-c("method_mod_obj","validation_mod_obj","tb_diagnostic_v",
climate/research/oregon/interpolation/master_script_temp.R
10 10
#STAGE 5: Output analyses: assessment of results for specific dates...
11 11
#
12 12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 06/07/2013                                                                                 
13
#DATE: 06/08/2013                                                                                 
14 14

  
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568--   
16 16

  
......
48 48

  
49 49
##SCRIPT USED FOR THE PREDICTIONS: Source or list all scripts here to avoid confusion on versions being run!!!!
50 50

  
51
#source(file.path(script_path,"master_script_temp_06032013.R")) #Master script can be run directly...
51
#source(file.path(script_path,"master_script_temp_06082013.R")) #Master script can be run directly...
52 52

  
53 53
#CALLED FROM MASTER SCRIPT:
54 54

  
55 55
modis_download_script <- file.path(script_path,"modis_download_05142013.py") # LST modis download python script
56
clim_script <- file.path(script_path,"climatology_05142013.py") # LST climatology python script
56
clim_script <- file.path(script_path,"climatology_05312013.py") # LST climatology python script
57 57
grass_setting_script <- file.path(script_path,"grass-setup.R") #Set up system shell environment for python+GRASS
58 58
source(file.path(script_path,"download_and_produce_MODIS_LST_climatology_05302013.R"))
59 59
source(file.path(script_path,"covariates_production_temperatures_06072013.R"))
60 60
source(file.path(script_path,"Database_stations_covariates_processing_function_05212013.R"))
61
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_06052013.R"))
62
source(file.path(script_path,"results_interpolation_date_output_analyses_05062013.R"))
61
source(file.path(script_path,"GAM_fusion_analysis_raster_prediction_multisampling_06082013.R"))
62
source(file.path(script_path,"results_interpolation_date_output_analyses_06102013.R"))
63 63
#source(file.path(script_path,"results_covariates_database_stations_output_analyses_04012013.R"))
64 64

  
65 65
#FUNCTIONS CALLED FROM GAM ANALYSIS RASTER PREDICTION ARE FOUND IN...
66 66

  
67 67
source(file.path(script_path,"sampling_script_functions_03122013.R"))
68 68
source(file.path(script_path,"GAM_fusion_function_multisampling_05212013.R")) #Include GAM_CAI
69
source(file.path(script_path,"interpolation_method_day_function_multisampling_06052013.R")) #Include GAM_day
69
source(file.path(script_path,"interpolation_method_day_function_multisampling_06082013.R")) #Include GAM_day
70 70
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_05062013.R"))
71 71

  
72 72
#stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on...
73 73
stages_to_run<-c(0,2,3,4,5) #May decide on antoher strategy later on...
74 74

  
75 75
var<-"TMAX" # variable being interpolated
76
#out_prefix<-"_365d_kriging_day_lst_06072013"                #User defined output prefix
77
out_prefix<-"_365d_GAM_CAI_all_lst_06072013"                #User defined output prefix
78
out_suffix<-"_VE_06072013"
79
#out_suffix_modis <-"_05302013" #use tiles produce previously
80
out_suffix_modis <-"_05242013" #use tiles produce previously
76
out_prefix<-"_365d_gwr_day_lst_06082013"                #User defined output prefix
77
out_suffix<-"_OR_06082013"
78
out_suffix_modis <-"_05302013" #use tiles produce previously
81 79

  
82 80
#interpolation_method<-c("gam_fusion","gam_CAI","gam_daily") #other otpions to be added later
83
interpolation_method<-c("gam_CAI") #other otpions to be added later
81
#interpolation_method<-c("gam_CAI") #other otpions to be added later
84 82
#interpolation_method<-c("gam_fusion") #other otpions to be added later
85 83
#interpolation_method<-c("gam_daily") #other otpions to be added later
86 84
#interpolation_method<-c("kriging_daily") #other otpions to be added later
85
interpolation_method<-c("gwr_daily") #other otpions to be added later
87 86

  
88
out_path <-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data"
89
#out_path<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data"
87
#out_path <- paste("/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data",
88
#                  out_prefix,"/",sep="")
89
out_path<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/output_data"
90 90
out_path <-paste(out_path,out_prefix,sep="")
91 91

  
92 92
if (!file.exists(out_path)){
......
104 104
#infile_reg_outline<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/outline_venezuela_region__VE_01292013.shp" 
105 105
#infile_covariates<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates__venezuela_region_TMIN__VE_03192013.tif" #covariates stack for TMIN
106 106
#infile_covariates<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/covariates_Oregon_region_TMAX__OR_04052013.tif" #Oregon covar TMAX from earlier codes...for continuity
107
infile_reg_outline=""  #input region outline defined by polygon: none for Venezuela
107
#infile_reg_outline=""  #input region outline defined by polygon: none for Venezuela
108 108
#This is the shape file of outline of the study area                                                      #It is an input/output of the covariate script
109
#infile_reg_outline <- "/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/OR83M_state_outline.shp"  #input region outline defined by polygon: Oregon
109
infile_reg_outline <- "/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/OR83M_state_outline.shp"  #input region outline defined by polygon: Oregon
110 110
#infile_reg_outline <-"OR83M_state_outline.shp" #remove this parameter!!!
111
ref_rast_name<-""  #local raster name defining resolution, exent, local projection--. set on the fly?? 
111
#ref_rast_name<-""  #local raster name defining resolution, exent, local projection--. set on the fly?? 
112 112
#this may be redundant with infile_reg_outline
113
#ref_rast_name<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/mean_day244_rescaled.rst"  #local raster name defining resolution, exent: oregon
113
ref_rast_name<-"/home/parmentier/Data/IPLANT_project/Oregon_interpolation/Oregon_03142013/mean_day244_rescaled.rst"  #local raster name defining resolution, exent: oregon
114 114

  
115 115
#covar_names see stage 2
116 116

  
117
list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area
118
#list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon
117
#list_tiles_modis <- c("h11v08,h11v07,h12v07,h12v08,h10v07,h10v08") #tile for Venezuela and surrounding area
118
list_tiles_modis <- c("h08v04,h09v04") #tiles for Oregon
119 119
  
120
CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
121
#CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
120
#CRS_interp<-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs";
121
CRS_interp <-"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +ellps=GRS80 +units=m +no_defs";
122 122
#"+proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5 +x_0=400000 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80"
123 123
CRS_locs_WGS84<-CRS("+proj=longlat +ellps=WGS84 +datum=WGS84 +towgs84=0,0,0") #Station coords WGS84
124
out_region_name<-"_venezuela_region" #generated on the fly
125
#out_region_name<-"_oregon_region" #generated on the fly
124
#out_region_name<-"_venezuela_region" #generated on the fly
125
out_region_name<-"_oregon_region" #generated on the fly
126 126
  
127 127
#The names of covariates can be changed...these names should be output/input from covar script!!!
128 128
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev_s","slope","aspect","CANHEIGHT","DISTOC")
......
187 187
range_years<-c("2010","2011") #right bound not included in the range!!
188 188
range_years_clim<-c("2000","2011") #right bound not included in the range!!
189 189
infile_ghncd_data <-"/home/layers/data/climate/ghcn/v2.92-upd-2012052822/ghcnd-stations.txt"                              #This is the textfile of station locations from GHCND
190
qc_flags_stations<-c("0","S")    #flags allowed for screening after the query from the GHCND??
191
#qc_flags_stations<-c("0")    #flags allowed for screening after the query from the GHCND??
190
#qc_flags_stations<-c("0","S")    #flags allowed for screening after the query from the GHCND??
191
qc_flags_stations<-c("0")    #flags allowed for screening after the query from the GHCND??
192 192

  
193 193
#infile_covariates and infile_reg_outline defined in stage 2 or at the start of script...
194 194

  
......
230 230

  
231 231
#Models to run...this can be change for each run
232 232

  
233
list_models<-c("y_var ~ s(elev_s)",
234
               "y_var ~ s(LST)",
235
               "y_var ~ s(elev_s,LST)",
236
               "y_var ~ s(lat) + s(lon)+ s(elev_s)",
237
               "y_var ~ s(lat,lon,elev_s)",
238
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST)", 
239
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC2)",	
240
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(LC6)", 
241
               "y_var ~ s(lat,lon) + s(elev_s) + s(N_w,E_w) + s(LST) + s(DISTOC)")
242
#krmod2<-autoKrige(tmax~x_OR83M+y_OR83M,input_data=data_s,new_data=s_sgdf,data_variogram=data_s)
243
#list_models<-c("y_var ~ 1",
244
#               "y_var ~ x + y",
245
#               "y_var ~ x + y + elev_s",
246
#               "y_var ~ x + y + DISTOC",
247
#               "y_var ~ x + y + elev_s + DISTOC",
248
#               "y_var ~ x + y + N_w + E_w",
249
#               "y_var ~ LST",
250
#               "y_var ~ x + y + LST",
251
#               "y_var ~ x + y + elev_s + LST")
233
list_models<-c("y_var ~ elev_s",
234
               "y_var ~ LST",
235
               "y_var ~ elev_s*LST")
236
#               "y_var ~ lat + lon + elev_s",
237
#               "y_var ~ lat*lon*elev_s",
238
#               "y_var ~ lat*lon + elev_s + N_w*E_w + LST", 
239
#               "y_var ~ lat*lon + elev_s + N_w*E_w + LST + LC2",	
240
#               "y_var ~ lat*lon + elev_s + N_w*E_w + LST + LC6", 
241
#               "y_var ~ lat*lon + elev_s + N_w*E_w + LST + DISTOC")
242

  
243
#list_models<-c("y_var~ lat + lon + elev_",
244
#               "y_var~ I(lat*lon) + elev_s",
245
#              "y_var~ lat + lon + elev_s + N + E + DISTOC",
246
#              "y_var~ I(lat*lon) + elev_s + I(N*E) + DISTOC + LST", 
247
#              "y_var~ lat + lon + ELEV_SRTM + N_w + E_w + DISTOC + LST", 
248
#              "y_var~ lat + lon + ELEV_SRTM + N_w + E_w + DISTOC + LST + LC2", 
249
#              "y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + LC6", 
250
#              "y_var~ lat + lon + ELEV_SRTM + Northness_w + Eastness_w + DISTOC + LST + I(LST*LC2)", 
252 251

  
253 252
#Default name of LST avg to be matched               
254 253
lst_avg<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12")  

Also available in: Unified diff