Project

General

Profile

« Previous | Next » 

Revision 23ba6282

Added by Benoit Parmentier over 9 years ago

adding plotting function for daily mosaics from other script

View differences:

climate/research/oregon/interpolation/global_run_scalingup_mosaicing_function.R
598 598
  return(out_file)
599 599
}
600 600

  
601
plot_daily_mosaics <- function(i,list_param_plot_daily_mosaics){
602
  #Purpose:
603
  #This functions mask mosaics files for a default range (-100,100 deg).
604
  #It produces a masked tif in a given dataType format (FLT4S)
605
  #It creates a figure of mosaiced region being interpolated.
606
  #Author: Benoit Parmentier
607
  #Parameters:
608
  #lf_m: list of files 
609
  #reg_name:region name with tile size included
610
  #To do:
611
  #Add filenames
612
  #Add range
613
  #Add output dir
614
  #Add dataType_val option
615
  
616
  ##### BEGIN ########
617
  
618
  #Parse the list of parameters
619
  lf_m <- list_param_plot_daily_mosaics$lf_m
620
  reg_name <- list_param_plot_daily_mosaics$reg_name
621
  out_dir_str <- list_param_plot_daily_mosaics$out_dir_str
622
  out_suffix <- list_param_plot_daily_mosaics$out_suffix
623
  l_dates <- list_param_plot_daily_mosaics$l_dates
624

  
625

  
626
  #list_param_plot_daily_mosaics <- list(lf_m=lf_m,reg_name=reg_name,out_dir_str=out_dir_str)
627

  
628
  
629
  #rast_list <- vector("list",length=length(lf_m))
630
  r_test<- raster(lf_m[i])
631

  
632
  m <- c(-Inf, -100, NA,  
633
         -100, 100, 1, 
634
         100, Inf, NA) #can change the thresholds later
635
  rclmat <- matrix(m, ncol=3, byrow=TRUE)
636
  rc <- reclassify(r_test, rclmat,filename=paste("rc_tmp_",i,".tif",sep=""),dataType="FLT4S",overwrite=T)
637
  file_name <- unlist(strsplit(basename(lf_m[i]),"_"))
638
  
639
  #date_proc <- file_name[7] #specific tot he current naming of files
640
  date_proc <- l_dates[i]
641
  #paste(raster_name[1:7],collapse="_")
642
  #add filename option later
643
  extension_str <- extension(filename(r_test))
644
  raster_name_tmp <- gsub(extension_str,"",basename(filename(r_test)))
645
  raster_name <- file.path(out_dir_str,paste(raster_name_tmp,"_masked.tif",sep=""))
646
  r_pred <- mask(r_test,rc,filename=raster_name,overwrite=TRUE)
647
  
648
  res_pix <- 1200
649
  #res_pix <- 480
650

  
651
  col_mfrow <- 1
652
  row_mfrow <- 1
653
  
654
  png(filename=paste("Figure9_clim_mosaics_day_test","_",date_proc,"_",reg_name,"_",out_suffix,".png",sep=""),
655
    width=col_mfrow*res_pix,height=row_mfrow*res_pix)
656

  
657
  plot(r_pred,main=paste("Predicted on ",date_proc , " ", reg_name,sep=""),cex.main=1.5)
658
  dev.off()
659
  
660
  return(raster_name)
661
  
662
}
663

  
664

  
601 665
##################### END OF SCRIPT ######################
602 666

  

Also available in: Unified diff