From 28149d1f6fb1252421216bf1fbb924bb2b282224 Mon Sep 17 00:00:00 2001 From: James McCreight Date: Mon, 22 Feb 2021 17:12:36 -0700 Subject: [PATCH] wavelet touch ups --- DESCRIPTION | 2 +- R/wavelet_event_timing.R | 2 -- R/wavelet_event_timing_plot.R | 26 +++++++++----------------- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index aa22a26..49c2e10 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: rwrfhydro Type: Package Title: R tools for the WRF Hydro Model -Version: 1.0.1 +Version: 1.0.2 Date: 2015-05-01 Authors@R: c( person("James", "McCreight", email = "jamesmcc@ucar.edu", role = c("aut","cre")), diff --git a/R/wavelet_event_timing.R b/R/wavelet_event_timing.R index a097927..422aa2d 100644 --- a/R/wavelet_event_timing.R +++ b/R/wavelet_event_timing.R @@ -237,7 +237,6 @@ WtTimeChunks <- function( for(cc in (first_ind+1):length(chunk_list)) { if(class(chunk_list[[cc]]) != "biwavelet") { - # print(cc) next } @@ -327,7 +326,6 @@ WtEventTiming <- function(POSIXct, obs, "than min_ts_length. Returning.") cat(msg,'\n') cat(paste0("min_ts_length: ", min_ts_length), '\n') - print(chunk_len) return(NULL) } diff --git a/R/wavelet_event_timing_plot.R b/R/wavelet_event_timing_plot.R index 70c76c4..d9270df 100644 --- a/R/wavelet_event_timing_plot.R +++ b/R/wavelet_event_timing_plot.R @@ -543,6 +543,7 @@ step1_figure = function(wt_event, cluster_maxima=FALSE) { library(dplyr) library(ggplot2) library(relayer) ## git hash 8a1d49e1707d9fcc1aaa83476a3d9a15448a1065 + library(ggplotify) obs_power = get_data_plot_power(wt_event$obs$wt, wt_event$input_data) obs_t_avg_power = get_data_plot_time_avg_power(wt_event$obs$wt) @@ -642,15 +643,15 @@ step1_figure = function(wt_event, cluster_maxima=FALSE) { ## Merge the new and old data. pd = rbind(plot_data, wt_copy) - + ## Get the standard plot gg = plot_wavelet_events(pd, do_plot=FALSE) - + ## Extend the standard plot. ## Use annotations for units labels on the y-axes. plot_data = as.data.table(plot_data) - + y_labs = plot_data[, .(y_center=min(y, na.rm=TRUE)+.5*(max(y, na.rm=TRUE)-min(y, na.rm=TRUE)), @@ -716,11 +717,6 @@ step1_figure = function(wt_event, cluster_maxima=FALSE) { max_stats$y_var = ordered('d Period', levels=new_y_levels) max_stats$x = min(plot_data$x, na.rm=TRUE) + 3600*(max_stats$time) - print(max_stats$x) - print(min(plot_data$x, na.rm=TRUE)) - print((max_stats$time)) - print(3600*(max_stats$time)) - period_y_cols = c('y', 'period') period_y_map = unique(plot_data[ y_var =='d Period', ..period_y_cols ]) max_stats = merge(max_stats, period_y_map, by='period') @@ -812,7 +808,7 @@ step1_figure = function(wt_event, cluster_maxima=FALSE) { text_color = 'grey30' text_size = 11 - + text_grob_1 = grid.text( 'Streamflow (cms)', x=-1.25, y=.6, hjust=.50, vjust=-3.5, rot=-90, gp=gpar(col=text_color, fontsize=text_size)) @@ -843,7 +839,7 @@ step1_figure = function(wt_event, cluster_maxima=FALSE) { t = unique(grob$layout[grepl("panel-1-4",grob$layout$name), "t"]) g = gtable::gtable_add_grob(g, grobs=text_grob_3, t=t, l=ncol(g), clip='off') - return(g) + return(as.ggplot(g)) } @@ -857,7 +853,8 @@ step2_figure = function( library(dplyr) library(ggplot2) library(relayer) ## git hash 8a1d49e1707d9fcc1aaa83476a3d9a15448a1065 - + library(ggplotify) + ## Currently this is only configured to handle a single modeled timeseries. model_name = setdiff(names(wt_event), c("input_data", "obs")) if(length(model_name) > 1) @@ -1085,11 +1082,6 @@ step2_figure = function( max_stats$y_var = ordered('TimePer', levels=new_y_levels) max_stats$x = min(plot_data$x, na.rm=TRUE) + 3600*(max_stats$time) - print(max_stats$x) - print(min(plot_data$x, na.rm=TRUE)) - print((max_stats$time)) - print(3600*(max_stats$time)) - period_y_cols = c('y', 'period') period_y_map = unique(plot_data[ y_var =='TimePer', ..period_y_cols ]) max_stats = merge(max_stats, period_y_map, by='period') @@ -1228,7 +1220,7 @@ step2_figure = function( guide_layout = guide_layout[c(4,1,2,3),] colnames(guide_layout) = 1:4 g$grobs[[wh_guide_box]]$layout[1:4,] = guide_layout - return(g) + return(as.ggplot(g)) }