Project

General

Profile

« Previous | Next » 

Revision 44f43362

Added by Benoit Parmentier over 11 years ago

gam fusion handling errors

View differences:

climate/research/oregon/interpolation/GAM_fusion_analysis_raster_prediction_multisampling.R
181 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")
182 182
    #source(file.path(script_path,"GAM_fusion_function_multisampling_03122013.R"))
183 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
184
    men#test<-runClim_KGFusion(1,list_param=list_param_runClim_KGFusion)
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
184
    #clim_method_mod_obj<-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
185
    #test<-runClim_KGFusion(3,list_param=list_param_runClim_KGFusion)
186 186
    save(clim_method_mod_obj,file= file.path(out_path,paste(interpolation_method,"_mod_",y_var_name,out_prefix,".RData",sep="")))
187 187
    list_tmp<-vector("list",length(clim_method_mod_obj))
188 188
    for (i in 1:length(clim_method_mod_obj)){
......
226 226
  #TODO : Same call for all functions!!! Replace by one "if" for all multi time scale methods...
227 227
  if (interpolation_method=="gam_CAI" | interpolation_method=="gam_fusion"){
228 228
    #input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn
229
    i<-1
229 230
    list_param_run_prediction_daily_deviation <-list(i,clim_yearlist,sampling_obj,dst,var,y_var_name, interpolation_method,out_prefix,out_path)
230 231
    names(list_param_run_prediction_daily_deviation)<-c("list_index","clim_yearlist","sampling_obj","dst","var","y_var_name","interpolation_method","out_prefix","out_path")
231 232
    #test<-mclapply(1:18, runGAMFusion,list_param=list_param_runGAMFusion,mc.preschedule=FALSE,mc.cores = 9)
......
238 239
  #TODO : Same call for all functions!!! Replace by one "if" for all daily single time scale methods...
239 240
  if (interpolation_method=="gam_daily"){
240 241
    #input a list:note that ghcn.subsets is not sampling_obj$data_day_ghcn
241
    
242
    i<-1
242 243
    list_param_run_prediction_gam_daily <-list(i,s_raster,covar_names,lst_avg,list_models,dst,var,y_var_name, sampling_obj,interpolation_method,out_prefix,out_path)
243 244
    names(list_param_run_prediction_gam_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")
244 245
    #test <- runGAM_day_fun(1,list_param_run_prediction_gam_daily)
climate/research/oregon/interpolation/GAM_fusion_function_multisampling.R
265 265
    list_out_filename[[k]]<-raster_name
266 266
  }
267 267

  
268
  #now predict values for raster image...
268
  #now predict values for raster image...by providing fitted model list, raster brick and list of output file names
269 269
  rast_bias_list<-predict_raster_model(mod_list,s_raster,list_out_filename)
270 270
  names(rast_bias_list)<-cname
271 271
  #Some modles will not be predicted...remove them
......
286 286
  #### STEP 4:Adding Kriging for Climatology options
287 287
  
288 288
  bias_xy<-coordinates(data_month)
289
  fitbias<-Krig(bias_xy,data_month$LSTD_bias,theta=1e5) #use TPS or krige 
290
  mod_krtmp1<-fitbias
289
  #fitbias<-Krig(bias_xy,data_month$LSTD_bias,theta=1e5) #use TPS or krige 
290
  fitbias<-try(Krig(bias_xy,data_month$LSTD_bias,theta=1e5)) #use TPS or krige 
291
 
291 292
  model_name<-"mod_kr"
293

  
294
  if (inherits(fitbias,"Krig")){
295
    #Saving kriged surface in raster images
296
    bias_rast<-bias_rast<-interpolate(LST,fitbias) #interpolation using function from raster package
297
    data_name<-paste(var,"_bias_LST_month_",j,"_",model_name,"_",prop_month,
298
                     "_",run_samp,sep="")
299
    raster_name_bias<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
300
    writeRaster(bias_rast, filename=raster_name_bias,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
301
    
302
    #now climatology layer
303
    clim_rast<-LST-bias_rast
304
    data_name<-paste(var,"_clim_LST_month_",j,"_",model_name,"_",prop_month,
305
                     "_",run_samp,sep="")
306
    raster_name_clim<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
307
    writeRaster(clim_rast, filename=raster_name_clim,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
308
    #Adding to current objects
309
    mod_list[[model_name]]<-fitbias
310
    rast_bias_list[[model_name]]<-raster_name_bias
311
    rast_clim_list[[model_name]]<-raster_name_clim
312
  }
292 313
  
293
   
294
  bias_rast<-interpolate(LST,fitbias) #interpolation using function from raster package
295
  #Saving kriged surface in raster images
296
  data_name<-paste(var,"_bias_LST_month_",j,"_",model_name,"_",prop_month,
297
                   "_",run_samp,sep="")
298
  raster_name_bias<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
299
  writeRaster(bias_rast, filename=raster_name_bias,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
300
  
301
  #now climatology layer
302
  clim_rast<-LST-bias_rast
303
  data_name<-paste(var,"_clim_LST_month_",j,"_",model_name,"_",prop_month,
304
                   "_",run_samp,sep="")
305
  raster_name_clim<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
306
  writeRaster(clim_rast, filename=raster_name_clim,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
307
  
308
  #Adding to current objects
309
  mod_list[[model_name]]<-mod_krtmp1
310
  rast_bias_list[[model_name]]<-raster_name_bias
311
  rast_clim_list[[model_name]]<-raster_name_clim
314
  if (inherits(fitbias,"try-error")){
315
    #NEED TO DEAL WITH THIS!!!
316
    
317
    #Adding to current objects
318
    mod_list[[model_name]]<-NULL
319
    rast_bias_list[[model_name]]<-NULL
320
    rast_clim_list[[model_name]]<-NULL
321
  }
322

  
312 323
  
313 324
  #### STEP 5: Prepare object and return
314 325
  

Also available in: Unified diff