Project

General

Profile

« Previous | Next » 

Revision 5f91c983

Added by Benoit Parmentier over 11 years ago

gam fusion, gam CAI functions modifications to store predictions in one unique output folder

View differences:

climate/research/oregon/interpolation/GAM_fusion_function_multisampling.R
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: 04/30/2013                                                                                 
11
#DATE: 05/07/2013                                                                                 
12 12
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
13 13

  
14 14
##Comments and TODO:
......
73 73
  #7)var: TMAX or TMIN, variable being interpolated
74 74
  #8)y_var_name: output name, not used at this stage
75 75
  #9)out_prefix
76
  #
76
  #10) out_path
77
  
77 78
  #The output is a list of four shapefile names produced by the function:
78 79
  #1) clim: list of output names for raster climatogies 
79 80
  #2) data_month: monthly training data for bias surface modeling
......
92 93
  var<-list_param$var
93 94
  y_var_name<-list_param$y_var_name
94 95
  out_prefix<-list_param$out_prefix
95
    
96
  out_path<-list_param$out_path
97
  
96 98
  #Model and response variable can be changed without affecting the script
97 99
  prop_month<-0 #proportion retained for validation
98 100
  run_samp<-1
......
133 135
    #j indicate which month is predicted
134 136
    data_name<-paste(var,"_clim_month_",j,"_",cname[k],"_",prop_month,
135 137
                     "_",run_samp,sep="")
136
    raster_name<-paste("CAI_",data_name,out_prefix,".tif", sep="")
138
    raster_name<-file.path(out_path,paste("CAI_",data_name,out_prefix,".tif", sep=""))
137 139
    list_out_filename[[k]]<-raster_name
138 140
  }
139 141
  
......
162 164
  #clim_rast<-LST-bias_rast
163 165
  data_name<-paste(var,"_clim_month_",j,"_",model_name,"_",prop_month,
164 166
                   "_",run_samp,sep="")
165
  raster_name_clim<-paste("CAI_",data_name,out_prefix,".tif", sep="")
167
  raster_name_clim<-file.path(out_path,paste("CAI_",data_name,out_prefix,".tif", sep=""))
166 168
  writeRaster(clim_rast, filename=raster_name_clim,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
167 169
  
168 170
  #Adding to current objects
......
174 176
  clim_obj<-list(rast_clim_list,data_month,mod_list,list_formulas)
175 177
  names(clim_obj)<-c("clim","data_month","mod","formulas")
176 178
  
177
  save(clim_obj,file= paste("clim_obj_CAI_month_",j,"_",var,"_",out_prefix,".RData",sep=""))
179
  save(clim_obj,file= file.path(out_path,paste("clim_obj_CAI_month_",j,"_",var,"_",out_prefix,".RData",sep="")))
178 180
  
179 181
  return(clim_obj) 
180 182
}
......
212 214
  var<-list_param$var
213 215
  y_var_name<-list_param$y_var_name
214 216
  out_prefix<-list_param$out_prefix
215

  
217
  out_path<-list_param$out_path
218
  
216 219
  #Model and response variable can be changed without affecting the script
217 220
  prop_month<-0 #proportion retained for validation
218 221
  run_samp<-1 #This option can be added later on if/when neeeded
......
258 261
    #j indicate which month is predicted, var indicates TMIN or TMAX
259 262
    data_name<-paste(var,"_bias_LST_month_",j,"_",cname[k],"_",prop_month,
260 263
                     "_",run_samp,sep="")
261
    raster_name<-paste("fusion",data_name,out_prefix,".tif", sep="")
264
    raster_name<-file.path(out_path,paste("fusion",data_name,out_prefix,".tif", sep=""))
262 265
    list_out_filename[[k]]<-raster_name
263 266
  }
264 267

  
......
275 278
    clim_fus_rast<-LST-subset(mod_rast,k)
276 279
    data_name<-paste(var,"_clim_LST_month_",j,"_",names(rast_clim_list)[k],"_",prop_month,
277 280
                     "_",run_samp,sep="")
278
    raster_name<-paste("fusion_",data_name,out_prefix,".tif", sep="")
281
    raster_name<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
279 282
    rast_clim_list[[k]]<-raster_name
280 283
    writeRaster(clim_fus_rast, filename=raster_name,overwrite=TRUE)  #Wri
281 284
  }
......
292 295
  #Saving kriged surface in raster images
293 296
  data_name<-paste(var,"_bias_LST_month_",j,"_",model_name,"_",prop_month,
294 297
                   "_",run_samp,sep="")
295
  raster_name_bias<-paste("fusion_",data_name,out_prefix,".tif", sep="")
298
  raster_name_bias<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
296 299
  writeRaster(bias_rast, filename=raster_name_bias,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
297 300
  
298 301
  #now climatology layer
299 302
  clim_rast<-LST-bias_rast
300 303
  data_name<-paste(var,"_clim_LST_month_",j,"_",model_name,"_",prop_month,
301 304
                   "_",run_samp,sep="")
302
  raster_name_clim<-paste("fusion_",data_name,out_prefix,".tif", sep="")
305
  raster_name_clim<-file.path(out_path,paste("fusion_",data_name,out_prefix,".tif", sep=""))
303 306
  writeRaster(clim_rast, filename=raster_name_clim,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
304 307
  
305 308
  #Adding to current objects
......
312 315
  clim_obj<-list(rast_bias_list,rast_clim_list,data_month,mod_list,list_formulas)
313 316
  names(clim_obj)<-c("bias","clim","data_month","mod","formulas")
314 317
  
315
  save(clim_obj,file= paste("clim_obj_month_",j,"_",var,"_",out_prefix,".RData",sep=""))
318
  save(clim_obj,file= file.path(out_path,paste("clim_obj_month_",j,"_",var,"_",out_prefix,".RData",sep="")))
316 319
  
317 320
  return(clim_obj)
318 321
}
......
333 336
  #5)var: variable predicted -TMAX or TMIN
334 337
  #6)y_var_name: name of the variable predicted - dailyTMax, dailyTMin
335 338
  #7)out_prefix
336
  #8)
339
  #8)out_path
337 340
  #
338 341
  #The output is a list of four shapefile names produced by the function:
339 342
  #1) list_temp: y_var_name
......
356 359
  y_var_name<-list_param$y_var_name
357 360
  out_prefix<-list_param$out_prefix
358 361
  dst<-list_param$dst #monthly station dataset
362
  out_path <-list_param$out_path
359 363
  
360 364
  ##########
361 365
  # STEP 1 - Read in information and get traing and testing stations
......
472 476
  #Saving kriged surface in raster images
473 477
  data_name<-paste("daily_delta_",y_var_name,"_",sampling_dat$date[i],"_",sampling_dat$prop[i],
474 478
                   "_",sampling_dat$run_samp[i],sep="")
475
  raster_name_delta<-paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep="")
479
  raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
476 480
  writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
477 481
  
478 482
  #Now predict daily after having selected the relevant month
......
484 488
    data_name<-paste(y_var_name,"_predicted_",names(rast_clim_list)[j],"_",
485 489
                     sampling_dat$date[i],"_",sampling_dat$prop[i],
486 490
                     "_",sampling_dat$run_samp[i],sep="")
487
    raster_name<-paste(interpolation_method,"_",data_name,out_prefix,".tif", sep="")
491
    raster_name<-file.path(out_path,paste(interpolation_method,"_",data_name,out_prefix,".tif", sep=""))
488 492
    writeRaster(temp_predicted, filename=raster_name,overwrite=TRUE) 
489 493
    temp_list[[j]]<-raster_name
490 494
  }
......
507 511
  obj_names<-c(y_var_name,"clim","delta","data_s","data_v",
508 512
               "sampling_dat",model_name)
509 513
  names(delta_obj)<-obj_names 
510
  save(delta_obj,file= paste("delta_obj_",var,"_",sampling_dat$date[i],"_",sampling_dat$prop[i],
511
                                "_",sampling_dat$run_samp[i],out_prefix,".RData",sep=""))
514
  save(delta_obj,file= file.path(out_path,paste("delta_obj_",var,"_",sampling_dat$date[i],"_",sampling_dat$prop[i],
515
                                "_",sampling_dat$run_samp[i],out_prefix,".RData",sep="")))
512 516
  return(delta_obj)
513 517
  
514 518
}

Also available in: Unified diff