Project

General

Profile

« Previous | Next » 

Revision f1082c52

Added by Benoit Parmentier about 9 years ago

debugging code for mosacing with new options and plot screen function

View differences:

climate/research/oregon/interpolation/global_run_scalingup_mosaicing_function.R
415 415
}
416 416

  
417 417
mosaicFiles <- function(lf_mosaic,mosaic_method="unweighted",num_cores=1,r_mask_raster_name=NULL,python_bin=NULL,mosaic_python="/nobackupp6/aguzman4/climateLayers/sharedCode/gdal_merge_sum.py",algorithm="R",df_points=NULL,NA_flag_val=-9999,file_format=".tif",out_suffix=NULL,out_dir=NULL){
418
  #This functions mosaics tiles/files give a list of files
418
  #This functions mosaics tiles/files give a list of files. 
419 419
  #There are four options to mosaic:   use_sine_weights,use_edge,use_linear_weights, unweighted
420 420
  #Sine weights fits sine fuctions across rows and column producing elliptical/spherical patterns from center
421 421
  #Use edge uses the distance from the edge of the tiles/fies, higher weights towards the center
422 422
  #Linear weights use simple linear average from distance point feature (usually centroid)
423 423
  #Unweighted: average without and weigthing surface
424
  #In addition, option is given to the user to use R raster mosaic function or a python/gdal modified gdalmerge in mosaicing.
424 425
  #
425 426
  #INPUT Arguments: 
426 427
  #1)lf_mosaic: list of files to mosaic
......
428 429
  #3)num_cores: number of cores used in parallilization in mclapply
429 430
  #4)r_mask_raster_name: mask rference raster image
430 431
  #5)python_bin: location of python executables, defaut is NULL
431
  #6)df_points: point location used in weighting, defaul is NULL
432
  #7)NA_flag_val: raster flag values, e.g. -9999
433
  #8)file_format: raster format used, default is ".tif"
434
  #9)out_suffix: output suffix, default is NULL, it is recommended to add the variable name
432
  #6)mosaic_python: location/directory of python excecutable used for mosaicing with option sum/mean from Alberto Guzmann
433
  #7)df_points: point location used in weighting, defaul is NULL
434
  #8)NA_flag_val: raster flag values, e.g. -9999
435
  #9)file_format: raster format used, default is ".tif"
436
  #10)out_suffix: output suffix, default is NULL, it is recommended to add the variable name
435 437
  #             here e.g. dailyTmax and date!!
436
  #10)out_dir: output directory, default is NULL
437
  #11)algorithm: use R or python function
438
  #11)out_dir: output directory, default is NULL
439
  #12)algorithm: use R or python function
438 440
  #
439 441
  #OUTPUT:
440 442
  # Object is produced with 3 components:
......
709 711
                     "--calc='A/B'","--overwrite",sep=" ") #division by zero is problematic...
710 712
    system(cmd_str)
711 713
    
714
    #cmd_str <- "/nobackupp6/aguzman4/climateLayers/sharedModules/bin/gdal_calc.py -A r_prod_weights_sum_m_use_edge_weights_weighted_mean_gam_CAI_dailyTmax_19920101_reg4_run10_1500x4500_global_analyses_pred_1992_10052015.tif -B r_weights_sum_m_use_edge_weights_weighted_mean_gam_CAI_dailyTmax_19920101_reg4_run10_1500x4500_global_analyses_pred_1992_10052015.tif --outfile='test2.tif' --calc='A/B' --overwrite"
715
    
712 716
    #writeRaster(r_m_weighted_mean, NAflag=NA_flag_val,filename=raster_name,overwrite=TRUE)  
713 717
    #now use the mask
714 718
    if(!is.null(r_mask_raster_name)){
715
      r_m_weighted_mean_mask_raster_name <- file.path(out_dir,paste("r_m_",method_mosaic_method,"_weighted_mean_mask_",out_suffix,".tif",sep=""))
719
      r_m_weighted_mean_mask_raster_name <- file.path(out_dir,paste("r_m_",mosaic_method,"_weighted_mean_mask_",out_suffix,".tif",sep=""))
716 720
      mask(raster(r_m_weighted_mean_raster_name),mask=raster(r_mask_raster_name),
717 721
           filename=r_m_weighted_mean_mask_raster_name,overwrite=TRUE)
718 722
      raster_name <- r_m_weighted_mean_mask_raster_name
......
925 929
  
926 930
}
927 931

  
928

  
932
#Use this instead of daily mosaic plot function
929 933
plot_screen_raster_val<-function(i,list_param){
930 934
  ##USAGE###
931 935
  #Screen raster list and produced plot as png.
932 936
  fname <-list_param$lf_raster_fname[i]
937
  var_name <-list_param$var_name #tmax, rmse tmax etc.  
933 938
  screenRast <- list_param$screenRast
934 939
  l_dates<- list_param$l_dates
935 940
  out_dir_str <- list_param$out_dir_str
......
971 976
  
972 977
#  png(filename=paste("Figure10_clim_world_mosaics_day_","_",date_proc,"_",tile_size,"_",out_suffix,".png",sep=""),
973 978
#    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
974
  png(filename=paste(prefix_str,"_",date_proc,"_","_",out_suffix_str,".png",sep=""),
979
  png_filename <- paste(prefix_str,"_",date_proc,"_","_",out_suffix_str,".png",sep="")
980
  png(filename=png_filename ,
975 981
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
976 982

  
977
  plot(r_pred,main=paste("Predicted on ",date_proc , " ", sep=""),cex.main=1.5)
983
  plot(r_pred,main=paste("Predicted on ",date_proc ," ",var_name, sep=""),cex.main=1.5)
978 984
  dev.off()
979

  
985
  
986
  return(png_filename)
980 987
}
981 988

  
982 989

  

Also available in: Unified diff