Project

General

Profile

« Previous | Next » 

Revision 92a3f212

Added by Benoit Parmentier about 11 years ago

dealing with memory swap overload, daily devation debugging following change in monthly outputs

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: 08/25/2013                                                                                 
11
#DATE: 08/30/2013                                                                                 
12 12
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
13 13

  
14 14
##Comments and TODO:
......
621 621
    
622 622
    daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the bias surface...
623 623
    
624
    #To many I/O out of swap memory on atlas
624 625
    #Saving kriged surface in raster images
625 626
    data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
626 627
                     sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
......
695 696
      
696 697
      daily_delta_rast<-interpolate(rast_clim_month,fitdelta) #Interpolation of the bias surface...
697 698
      
698
      #Saving kriged surface in raster images
699
      data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
700
                       sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
701
      raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
702
      writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
703
      
704
      list_daily_delta_rast[[k]] <- raster_name_delta   
699
      list_daily_delta_rast[[k]] <- daily_delta_rast 
700
      #list_daily_delta_rast[[k]] <- raster_name_delta   
705 701
    }
706 702
    
707
    raster_name_delta <- list_daily_delta_rast
703
    #Too many I/O out of swap memory on atlas
704
    #Saving kriged surface in raster images
705
    delta_rast_s <-stack(list_daily_delta_rast)
706
    names(delta_rast_s) <- names(daily_delta_df)
707
    
708
    #Should check that all delta images have been created for every model!!! remove from list empty elements!!
709
    
710
    #data_name<-paste("daily_delta_",y_var_name,"_",model_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
711
    #                 sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
712
    #raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
713
    #writeRaster(daily_delta_rast, filename=raster_name_delta,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
714
    
715
    data_name<-paste("daily_delta_",y_var_name,"_",sampling_month_dat$prop[index_m],"_",sampling_month_dat$run_samp[index_m],"_",
716
                     sampling_dat$date[index_d],"_",sampling_dat$prop[index_d],"_",sampling_dat$run_samp[index_d],sep="")
717
    raster_name_delta<-file.path(out_path,paste(interpolation_method,"_",var,"_",data_name,out_prefix,".tif", sep=""))
718
    
719
    writeRaster(delta_rast_s, filename=raster_name_delta,overwrite=TRUE)  #Writing the data in a raster file format...(IDRISI)
720
    #writeRaster(r_spat, NAflag=NA_flag_val,filename=raster_name,bylayer=TRUE,bandorder="BSQ",overwrite=TRUE)   
721
    
722
    #raster_name_delta <- list_daily_delta_rast
708 723
    mod_krtmp2 <- list_mod_krtmp2
709 724
  }
710 725
  
......
712 727
  # STEP 4 - Calculate daily predictions - T(day) = clim(month) + delta(day)
713 728
  #########
714 729
  
715
  if(use_clim_image==FALSE){
716
    list_daily_delta_rast <- rep(raster_name_delta,length=nlayers(rast_clim_mod))
717
  }
730
  #if(use_clim_image==FALSE){
731
  #  list_daily_delta_rast <- rep(raster_name_delta,length=nlayers(rast_clim_mod))
732
  #}
718 733
  #Now predict daily after having selected the relevant month
719 734
  temp_list<-vector("list",nlayers(rast_clim_mod))  
720 735
  for (k in 1:nlayers(rast_clim_mod)){
721
    rast_clim_month<-raster(rast_clim_list[[k]])
722
    daily_delta_rast <- raster(list_daily_delta_rast[[k]])
736
    if(use_clim_image==TRUE){
737
      daily_delta_rast <- list_daily_delta_rast[[k]]
738
    }
739
    #if use_clim_image==FALSE then daily__delta_rast already defined earlier...
740
    
741
    #rast_clim_month<-raster(rast_clim_list[[k]])
742
    rast_clim_month <- subset(rast_clim_mod,k)
723 743
    temp_predicted<-rast_clim_month + daily_delta_rast
724 744
    
725 745
    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],"_",
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: 08/25/2013                                                                                 
13
#DATE: 08/30/2013                                                                                 
14 14

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

  
......
80 80
#met_stations_outfiles_obj_file<-"met_stations_outfiles_obj_gam_CAI__365d_gam_CAI_lst_comb3_08252013.RData"
81 81

  
82 82
var<-"TMAX" # variable being interpolated
83
out_prefix<-"_365d_gam_CAI_lst_comb3_08252013"                #User defined output prefix
84
out_suffix<-"_OR_08252013"                                       #Regional suffix
83
out_prefix<-"_365d_gam_CAI_lst_comb3_08302013"                #User defined output prefix
84
out_suffix<-"_OR_08302013"                                       #Regional suffix
85 85
out_suffix_modis <-"_05302013"                       #pattern to find tiles produced previously     
86 86

  
87 87
#interpolation_method<-c("gam_fusion","gam_CAI","gam_daily") #other otpions to be added later
......
259 259
#dates_selected<-c("20100101","20100102","20100301","20100302","20100501","20100502","20100701","20100702","20100901","20100902","20101101","20101102")
260 260
dates_selected<-"" # if empty string then predict for the full year specified earlier
261 261
screen_data_training<-FALSE #screen training data for NA and use same input training for all models fitted
262
use_clim_image <- TRUE # use predicted image as a base...rather than average Tmin at the station for delta
263
join_daily <- FALSE # join monthly and daily station before calucating delta
262 264

  
263 265
#Models to run...this can be changed for each run
264 266
#LC1: Evergreen/deciduous needleleaf trees
......
307 309
list_param_raster_prediction<-list(list_param_data_prep,screen_data_training,
308 310
                                seed_number,nb_sample,step,constant,prop_minmax,dates_selected,
309 311
                                seed_number_month,nb_sample_month,step_month,constant_month,prop_minmax_month,
310
                                list_models,lst_avg,out_path,script_path,
312
                                list_models,lst_avg,out_path,script_path,use_clim_image,join_daily,
311 313
                                interpolation_method)
312 314
names(list_param_raster_prediction)<-c("list_param_data_prep","screen_data_training",
313 315
                                "seed_number","nb_sample","step","constant","prop_minmax","dates_selected",
314 316
                                "seed_number_month","nb_sample_month","step_month","constant_month","prop_minmax_month",
315
                                "list_models","lst_avg","out_path","script_path",
317
                                "list_models","lst_avg","out_path","script_path","use_clim_image","join_daily",
316 318
                                "interpolation_method")
319

  
317 320
#debug(raster_prediction_fun)
318 321
raster_prediction_obj <-raster_prediction_fun(list_param_raster_prediction)
319 322

  

Also available in: Unified diff