Project

General

Profile

« Previous | Next » 

Revision fe3fe74e

Added by Benoit Parmentier about 8 years ago

fixing png file name and data type of output raster

View differences:

climate/research/oregon/interpolation/global_product_assessment_part0_functions.R
281 281
  NA_value <- NA_flag_val 
282 282
  #metric_name <- "rmse" #to be added to the code later...
283 283
  #data_type <- "Int16" #, param 19, use int32 for output layers mosaiced
284
  
284

  
285
  if(data_type=="Int16"){
286
    data_type_str <- "INT2S"
287
  }
288

  
285 289
  ##### Select relevant day and create stack of missing tiles
286 290
    
287 291
  missing_tiles <- df_missing_tiles_day[i,]
......
336 340
  col_mfrow <- 1
337 341
  row_mfrow <- 1
338 342
  
339
  png_filename <-  file.path(out_dir,paste("Figure_number_of_predictions_by_pixel_",date_str,"_",region_name,"_",out_suffix,".png",sep =""))
343
  png_filename_number_of_predictions <-  file.path(out_dir,paste("Figure_number_of_predictions_by_pixel_",date_str,"_",region_name,"_",out_suffix,".png",sep =""))
340 344
    
341 345
  title_str <-  paste("Number of predicted pixels for ",variable_name," on ",date_str, sep = "")
342 346
  
343
  png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
347
  png(filename=png_filename_number_of_predictions,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
344 348
  #my_col=c('blue','red','green')
345 349
  my_col <- rainbow(length(tb_freq$value))
346 350
  plot(r_day_predicted,col=my_col,legend=F,box=F,axes=F,main=title_str)
......
371 375
  col_mfrow <- 1
372 376
  row_mfrow <- 1
373 377
  
374
  png_filename <-  file.path(out_dir,paste("Figure_missing_predictions_by_pixel_",date_str,"_",region_name,"_",out_suffix,".png",sep =""))
378
  png_filename_missing_predictions <-  file.path(out_dir,paste("Figure_missing_predictions_by_pixel_",date_str,"_",region_name,"_",out_suffix,".png",sep =""))
375 379
    
376 380
  title_str <-  paste("Number of predicted pixels for ",variable_name," on ",date_str, sep = "")
377 381
  
378
  png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
382
  png(filename=png_filename_missing_predictions,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
379 383
  #my_col=c('blue','red','green')
380 384
  my_col <- c("black","red")
381 385
  plot(r_missing_day,col=my_col,legend=F,box=F,axes=F,main=title_str)
......
392 396
    
393 397

  
394 398
  ### generate return object
395
  obj_number_day_predicted <- list(raster_name_number_prediction,raster_name_missing,tb_freq)
396
  names(obj_number_day_predicted) <- c("raster_name_number_prediction","raster_name_missing","tb_freq")
399
  obj_number_day_predicted <- list(raster_name_number_prediction,raster_name_missing,tb_freq,
400
                                   png_filename_number_of_predictions,png_filename_missing_predictions)
401
  names(obj_number_day_predicted) <- c("raster_name_number_prediction","raster_name_missing","tb_freq",
402
                                       "png_filename_number_of_predictions","png_missing_predictions")
397 403
    
398 404
  return(obj_number_day_predicted)
399 405
}
......
446 452
  
447 453
  setwd(out_dir)
448 454
  
455
  if(is.null(scaling)){
456
    scaling <- 1
457
  }
458
  #valid_range <- values_range #if NULL don't screen values!!
459
  #valid_range <- c(-100,100) #pass this as parameter!! (in the next update)
460
  if(data_type=="Int16"){
461
    data_type_str <- "INT2S"
462
  }
463

  
449 464
  #list_outfiles <- vector("list", length=35) #collect names of output files, this should be dynamic?
450 465
  #list_outfiles_names <- vector("list", length=35) #collect names of output files
451 466

  
......
708 723
  r_overlap_m <- mask(r_overlap,
709 724
                  mask=r_mask,
710 725
                  filename=out_mosaic_name_overlap_masked,
711
                  datatype=data_type,
712
                  #datatype=data_type_str,
726
                  datatype=data_type_str,
727
                  #datatype=data_type,
713 728
                  options=c("COMPRESS=LZW"),#compress tif
714 729
                  overwrite=TRUE,
715 730
                  NAflag=NA_flag_val)
......
730 745
  col_mfrow <- 1
731 746
  row_mfrow <- 1
732 747
  
733
  png_filename <-  file.path(out_dir,paste("Figure_maximum_overlap_",region_name,"_",out_suffix,".png",sep =""))
748
  png_filename_maximum_overlap <-  file.path(out_dir,paste("Figure_maximum_overlap_",region_name,"_",out_suffix,".png",sep =""))
734 749
    
735 750
  title_str <-  paste("Maximum overlap: Number of predicted pixels for ",variable_name, sep = "")
736 751
  
737
  png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
752
  png(filename=png_filename_maximum_overlap,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
738 753
    #my_col=c('blue','red','green')
739 754
  my_col <- rainbow(length(tb_freq_overlap$value))
740 755

  
......
775 790
                                                 FUN=function(i){mask(raster(list_tiles_predicted_m[i]),
776 791
                                                                      r_mask,filename=list_mask_out_file_name[i],
777 792
                                                                      overwrite=T,
778
                                                                      datatype=data_type,                  
793
                                                                      datatype=data_type_str,                  
779 794
                                                                      options=c("COMPRESS=LZW"))},
780 795
                                                 mc.preschedule=FALSE,
781 796
                                                 mc.cores = num_cores))                         
......
795 810
  
796 811
  
797 812
  list_param_generate_raster_number_pred <- list(list_tiles_predicted_masked,df_missing_tiles_day,r_overlap_m,
798
                                                 num_cores,region_name,data_type,scaling,
813
                                                 num_cores,region_name,data_type,scaling,python_bin,
799 814
                                                 NA_flag_val,out_suffix,out_dir)
800 815
  
801 816
  names(list_param_generate_raster_number_pred) <- c("list_tiles_predicted_masked","df_missing_tiles_day","r_overlap_m",
802
                                                     "num_cores","region_name","data_type","scaling",
817
                                                     "num_cores","region_name","data_type","scaling","python_bin",
803 818
                                                      "NA_flag_val","out_suffix","out_dir")
804 819
  
805 820
  #function_product_assessment_part0_functions <- "global_product_assessment_part0_functions_11152016b.R"
......
807 822

  
808 823
  #undebug(generate_raster_number_of_prediction_by_day)
809 824
  #4.51pm
810
  browser()
825
  #browser()
811 826
  #5.10pm
812 827
  #test_number_pix_predictions <- generate_raster_number_of_prediction_by_day(1,list_param=list_param_generate_raster_number_pred)
813 828
  if(nrow(df_missing_tiles_day)>0){
......
832 847
  }
833 848
  
834 849
  predictions_tiles_missing_obj <- list(df_lf_tiles_time_series,df_missing_tiles_day,out_mosaic_name_overlap_masked,
835
                                        tb_freq_overlap,obj_number_pix_predictions)
850
                                        tb_freq_overlap,png_filename_maximum_overlap,obj_number_pix_predictions)
836 851
  names(predictions_tiles_missing_obj) <- c("df_lf_tiles_time_series","df_missing_tiles_day","raster_name_overlap",
837
                                            "tb_freq_overlap","obj_number_pix_predictions")
852
                                            "tb_freq_overlap","png_maximum_overlap","obj_number_pix_predictions")
853
  browser()
838 854
  
839 855
  return(predictions_tiles_missing_obj)
840 856
}

Also available in: Unified diff