Project

General

Profile

« Previous | Next » 

Revision 84022daa

Added by Benoit Parmentier about 8 years ago

function tile assessment fixing output tmp files and other for testing by Alberto

View differences:

climate/research/oregon/interpolation/global_product_assessment_part0_functions.R
9 9
#
10 10
#AUTHOR: Benoit Parmentier 
11 11
#CREATED ON: 10/31/2016  
12
#MODIFIED ON: 11/28/2016            
12
#MODIFIED ON: 12/01/2016            
13 13
#Version: 1
14 14
#PROJECT: Environmental Layers project     
15 15
#COMMENTS: removing unused functions and clean up for part0 global prodduct assessment part0 
......
319 319
    
320 320
  ##### Sum missing tiles in the stack and generate number of predictions by pixels
321 321
  ## This stores files in the temp dir
322
  raster_name_data_sum <- file.path(out_dir,paste("r_data_sum","_",region_name,"_masked_",date_str,file_format,sep=""))
322
  raster_name_data_sum <- file.path(out_dir,paste("r_data_sum","_",region_name,"_masked_",date_str,"_tmp",file_format,sep=""))
323 323
  r_data_sum <- stackApply(r_tiles_s, 1:nlayers(r_tiles_s), fun = sum,filename=raster_name_data_sum,overwrite=TRUE)
324 324
     
325 325
  ### then substract missing tiles...
......
467 467
  year_predicted <- list_param$year_predicted #selected year #PARAM 23
468 468
  data_type <- list_param$data_type #PARAM 24
469 469
  scaling <- list_param$scaling #PARAM 25
470
  tmp_files <- list_param$tmp_files
470 471
  
471 472
  ########################## START SCRIPT #########################################
472 473
  
......
606 607
  #http://stackoverflow.com/questions/26220913/replace-na-with-na
607 608
  #Use dfr[dfr=="<NA>"]=NA where dfr is your dataframe.
608 609
  names(df_lf_tiles_time_series) <- unlist(basename(in_dir_reg))
609
  filename_df_lf_tiles <- file.path(out_dir,paste0("df_files_by_tiles_predicted_tif_",region_name,"_",pred_mod_name,"_",out_suffix))
610
  filename_df_lf_tiles <- file.path(out_dir,paste0("df_files_by_tiles_predicted_tif_",region_name,"_",pred_mod_name,"_",out_suffix,".txt"))
610 611
  write.table(df_lf_tiles_time_series,file=filename_df_lf_tiles)
611 612

  
612 613
  ###Now combined missing in one table?
......
620 621
  df_missing$reg <- region_name
621 622
  df_missing$date <- day_to_mosaic
622 623

  
623
  filename_df_missing <- file.path(out_dir,paste0("df_missing_by_tiles_predicted_tif_",region_name,"_",pred_mod_name,"_",out_suffix))
624
  filename_df_missing <- file.path(out_dir,paste0("df_missing_by_tiles_predicted_tif_",region_name,"_",pred_mod_name,"_",out_suffix,".txt"))
624 625
  write.table(df_missing,file=filename_df_missing)
625 626
  
626 627
  ########################
......
709 710
           col_name = "overlap",
710 711
           date_val=df_missing$date[1],
711 712
           out_dir = out_dir,
712
           out_suffix = "",
713
           #out_suffix = "",
714
           out_suffix = "_tmp",
713 715
            mc.preschedule=FALSE,
714 716
           mc.cores = num_cores)
715 717

  
......
719 721
  #plot(spdf_tiles_test,add=T,border="green",usePolypath = FALSE) #added usePolypath following error on brige and NEX
720 722

  
721 723
  ### Make a list of file
722
  out_suffix_str_tmp <- paste0(region_name,"_",out_suffix)
724
  out_suffix_str_tmp <- paste0(region_name,"_",out_suffix,"_tmp")
723 725
  out_dir_str <- out_dir
724 726
  filename_list_predicted <- file.path(out_dir_str,paste("list_to_mosaics_",out_suffix_str_tmp,".txt",sep=""))
725 727

  
......
732 734
  
733 735
  #out_mosaic_name_weights_m <- r_weights_sum_raster_name <- file.path(out_dir,paste("r_weights_sum_m_",mosaic_method,"_weighted_mean_",out_suffix,".tif",sep=""))
734 736
  #out_mosaic_name_prod_weights_m <- r_weights_sum_raster_name <- file.path(out_dir,paste("r_prod_weights_sum_m_",mosaic_method,"_weighted_mean_",out_suffix,".tif",sep=""))
735
  out_mosaic_name_predicted_m  <- file.path(out_dir_str,paste("r_overlap_sum_m_",out_suffix_str_tmp,".tif",sep=""))
737
  out_mosaic_name_predicted_m  <- file.path(out_dir_str,paste("r_overlap_sum_m_",out_suffix_str_tmp,"_tmp",".tif",sep=""))
736 738

  
737 739
  rast_ref_name <- infile_mask
738 740
  mosaic_python <- "/nobackupp6/aguzman4/climateLayers/sharedCode/"
......
750 752
  r_overlap <- raster(r_overlap_raster_name)
751 753
  r_mask <- raster(infile_mask)
752 754
  
753
  out_mosaic_name_overlap_masked  <- file.path(out_dir_str,paste("r_overlap_sum_masked_",out_suffix_str_tmp,".tif",sep=""))
755
  out_mosaic_name_overlap_masked  <- file.path(out_dir_str,paste("r_overlap_sum_masked_",region_name,"_",out_suffix,".tif",sep=""))
754 756

  
755 757
  r_overlap_m <- mask(r_overlap,
756 758
                  mask=r_mask,
......
831 833
  ########################
832 834
  #### Step 3: combine overlap information and number of predictions by day
833 835
  ##Now loop through every day if missing then generate are raster showing map of number of prediction
834
  
836
   
837
  #browser()
835 838
  #r_tiles_stack <- stack(list_tiles_predicted_masked)
836 839
  #names(r_tiles_stack) <- basename(in_dir_reg) #this does not work, X. is added to the name, use list instead
837 840
  
......
840 843
  #r_tiles_s <- r_tiles_stack
841 844
  names_tiles <- basename(in_dir_reg)
842 845
  
843
  browser()
846

  
844 847
  list_param_generate_raster_number_pred <- list(list_tiles_predicted_masked,df_missing_tiles_day,r_overlap_m,
845 848
                                                 num_cores,region_name,data_type,scaling,python_bin,
846 849
                                                 plotting_figures,
......
872 875
    obj_number_pix_predictions <- NULL
873 876
  }
874 877
  
878
  #browser()
875 879
  #Delete temporary files : Fix this part later...
876 880
  #rasterOptions(), find where tmp dir are stored
877 881
  #rasterOptions(tempdir=out_dir)
878 882
  if(tmp_files==F){ #if false...delete all files with "_tmp"
879
    lf_tmp <- unlist(lf_accuracy_training_raster)
883
    lf_tmp <- list.files(path=out_dir,pattern=".*._tmp.*")
884
    #lf_tmp <- unlist(lf_accuracy_training_raster)
880 885
    ##now delete temporary files...
881 886
    file.remove(lf_tmp)
882 887
  }
......
887 892
                                            "tb_freq_overlap","png_maximum_overlap","obj_number_pix_predictions")
888 893
  
889 894
  
895
  predictions_tiles_missing_obj_filename <- file.path(out_dir,paste("obj_predictions_tiles_missing_fun_",interpolation_method,y_var_name,region_name,out_suffix,".RData",sep=""))
896
  save(predictions_tiles_missing_obj,file=predictions_tiles_missing_obj_filename)
897

  
890 898
  return(predictions_tiles_missing_obj)
891 899
}
892 900

  

Also available in: Unified diff