Project

General

Profile

« Previous | Next » 

Revision efcab48e

Added by Benoit Parmentier about 8 years ago

modifying time series ploting function with additional option

View differences:

climate/research/oregon/interpolation/global_product_assessment_part1.R
593 593
i<-1
594 594

  
595 595
#Product assessment
596
function_product_assessment_part1_functions <- "global_product_assessment_part1_functions_09192016b.R"
597
source(file.path(script_path,function_product_assessment_part1_functions)) #source all functions used in this script 
598
#undebug(combine_measurements_and_predictions_df)
596 599
out_suffix_str <- paste0(region_name,"_",out_suffix)
597 600
#this can be run with mclapply, very fast right now:
598 601
station_summary_obj <- combine_measurements_and_predictions_df(i=i,
......
625 628
id_name <- list_selected_ID[i]
626 629
station_id <- id_name
627 630
#> myDF[ is.na(myDF) ] <- NA 
628
#var_name1 <- "mod1_mosaic"
629
var_name1 <- y_var_name
630
var_name2 <- "mod1_mosaic"
631
out_suffix_str <- paste(region_name,out_suffix,sep="_")
632
function_product_assessment_part1_functions <- "global_product_assessment_part1_functions_09192016d.R"
633
source(file.path(script_path,function_product_assessment_part1_functions)) #source all functions used in this script 
634 631

  
635
debug(plot_observation_predictions_time_series)
636
test_plot <- plot_observation_predictions_time_series(df_pix_time_series=df_pix_ts,
637
                                                      var_name1=var_name1,
638
                                                      var_name2=var_name2,
639
                                                      station_id=id_name,
640
                                                      scaling=scaling,
641
                                                      out_dir=".",
642
                                                      out_suffix="")
632
df_pix_ts[is.na(df_pix_ts)] <- NA
633
if(!is.null(scaling)){
634
  df_pix_ts[[var_pred_mosaic]] <-  df_pix_ts[[var_pred_mosaic]]*scaling 
635
}
636

  
637
d_z_var <- zoo(as.numeric(df_pix_ts[[var_pred_mosaic]]),as.Date(df_pix_ts$date)) #make sure date is a date object !!!
638
names(d_z_var) <- var_pred_mosaic
639
plot(d_z_var)  
640
d_z_obs <- zoo(as.numeric(df_pix_ts[[y_var_name]]),as.Date(df_pix_ts$date))
641
plot(d_z_obs)  
642

  
643
d_z_res <- zoo(as.numeric(df_pix_ts[[paste0("res_",var_pred_mosaic)]]),as.Date(df_pix_ts$date))
644
plot(d_z_res)  
645

  
646
d_z <- merge(d_z_var,d_z_obs)
647
range(d_z_res,na.rm=T)
648
mean(d_z_res,na.rm=T)
649
quantile(d_z_res,na.rm=T)
650
plot(d_z,plot.type="single",col=c("blue","red"))
651
names(d_z) <- c("pred","obs")
652

  
653
#day_start <- "1984-01-01" #PARAM 12 arg 12
654
#day_end <- "2014-12-31" #PARAM 13 arg 13
655
#start_date <- as.Date(day_start)
656
#end_date <- as.Date(day_end)
657
#start_year <- year(start_date)
658
#end_year <- year(end_date)
659
range_year <- range(df_pix_ts$year)
660
start_year <- range_year[1]
661
end_year <- range_year[2]
662
var="tmax"
663

  
664
res_pix <- 1000
665
#res_pix <- 480
666
col_mfrow <- 2
667
row_mfrow <- 1
668
  
669
png_filename <-  file.path(out_dir,paste("Figure5a_time_series_profile_",region_name,"_",id_name,y_var_name,out_suffix,".png",sep =""))
670
title_str <- paste("Predicted daily ", station_id," ",var," for the ", start_year,"-",end_year," time period",sep="")
671
  
672
png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
673
#this is the whole time series
674
#plot(d_z_var,ylab="tmax in deg C",xlab="Daily time steps",
675
#     main=title_str,cex=3,font=2,
676
#     cex.main=1.5,cex.lab=1.5,font.lab=2,
677
#     lty=3)
678
#range(df_pix_ts[[var_pred_mosaic]],na.rm=T)
679

  
680
plot(df_pix_ts[[var_pred_mosaic]] ~ as.Date(df_pix_ts$date),ylab="tmax in deg C",xlab="Daily time steps",
681
     main=title_str,cex=1,font=2,type="l",
682
     cex.main=1.5,cex.lab=1.5,font.lab=2,
683
     lty=3)
684
lines(as.numeric(df_pix_ts[[y_var_name]]) ~ as.Date(df_pix_ts$date),ylab="tmax in deg C",xlab="Daily time steps",
685
     main=title_str,cex=1,font=2,col="red",type="l",
686
     cex.main=1.5,cex.lab=1.5,font.lab=2,
687
     lty=3)
688

  
689

  
690
dev.off()
691

  
692
### get smaller window
693
day_start <- "1994-01-01" #PARAM 12 arg 12
694
day_end <- "1999-12-31" #PARAM 13 arg 13
695

  
696
start_date <- as.Date(day_start)
697
end_date <- as.Date(day_end)
698
start_year <- year(start_date)
699
end_year <- year(end_date)
700
d_z_tmp <- d_z_var
701
d_z <- window(d_z_tmp,start=start_date,end=end_date)
702
names(d_z) <- var_pred_mosaic
703
df_var <- as.data.frame(d_z)
704
 
705
d_z_tmp <- d_z_obs
706
d_z_tmp <- d_z
707
d_z_tmp <- window(d_z_tmp,start=start_date,end=end_date)
708
plot(d_z_tmp,col=c("blue","red"),plot.type="single")
709
df_z <- as.data.frame(d_z)
710

  
711
names(d_z) <- y_var_name
712
df_obs <- as.data.frame(d_z)
713
names(d_z) <- y_var_name
714

  
715
if(!is.null(df_selected2)){
716
  d_z2 <- window(d_z_tmp2,start=start_date,end=end_date)
717
}
718

  
719
res_pix <- 1000
720
#res_pix <- 480
721
col_mfrow <- 2
722
row_mfrow <- 1
723
  
724
png_filename <-  file.path(out_dir,paste("Figure5b_time_series_profile_",region_name,"_",out_suffix,".png",sep =""))
725
title_str <- paste("Predicted daily ", station_id," ",var," for the ", start_year,"-",end_year," time period",sep="")
726
  
727
png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
728

  
729
plot(df_pix_ts[[var_pred_mosaic]] ~ as.Date(df_pix_ts$date),ylab="tmax in deg C",xlab="Daily time steps",
730
     main=title_str,cex=1,font=2,type="l",
731
     cex.main=1.5,cex.lab=1.5,font.lab=2,
732
     lty=3)
733
lines(as.numeric(df_pix_ts[[y_var_name]]) ~ as.Date(df_pix_ts$date),ylab="tmax in deg C",xlab="Daily time steps",
734
     main=title_str,cex=1,font=2,col="red",type="l",
735
     cex.main=1.5,cex.lab=1.5,font.lab=2,
736
     lty=3)
737

  
738
dev.off()
739

  
740
#### Subset for 5c: zoom in
741

  
742
day_start <- "1991-01-01" #PARAM 12 arg 12
743
day_end <- "1992-12-31" #PARAM 13 arg 13
744

  
745
start_date <- as.Date(day_start)
746
end_date <- as.Date(day_end)
747
start_year <- year(start_date)
748
end_year <- year(end_date)
749
d_z <- window(d_z_tmp,start=start_date,end=end_date)
750
if(!is.null(df_selected2)){
751
  d_z2 <- window(d_z_tmp2,start=start_date,end=end_date)
752
}
753

  
754
res_pix <- 1000
755
#res_pix <- 480
756
col_mfrow <- 2
757
row_mfrow <- 1
758
  
759
png_filename <-  file.path(out_dir,paste("Figure5c_subset_time_series_profile_",region_name,"_",out_suffix,".png",sep =""))
760
title_str <- paste("Predicted daily ", station_id," ",var," for the ", start_year,"-",end_year," time period",sep="")
761
  
762
png(filename=png_filename,width = col_mfrow * res_pix,height = row_mfrow * res_pix)
763

  
764
plot(d_z,ylab="tmax in deg C",xlab="Daily time steps",
765
     main=title_str,cex=3,font=2,
766
     cex.main=1.5,cex.lab=1.5,font.lab=2,
767
     lty=3)
768
if(!is.null(df_selected2)){
769
  lines(d_z2,ylab="tmax in deg C",xlab="Daily time steps",
770
        main=title_str,cex=3,font=2,
771
        col="red",
772
        cex.main=1.5,cex.lab=1.5,font.lab=2,
773
        lty=3)
774
}
643 775

  
776
dev.off()
644 777

  
645 778
############### PART5: Make raster stack and display maps #############
646 779
#### Extract corresponding raster for given dates and plot stations used

Also available in: Unified diff