Skip to content

Commit

Permalink
Merge pull request #185 from lawinslow/master
Browse files Browse the repository at this point in the history
plot_var_compare x-axis fixes
  • Loading branch information
Luke Winslow committed Dec 31, 2015
2 parents 857f53c + c6018a4 commit b92a8c3
Show file tree
Hide file tree
Showing 38 changed files with 117 additions and 148 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: glmtools
Type: Package
Title: glmtools
Version: 0.10.2
Version: 0.10.3
Date: 2013-09-18
Authors@R: c( person("Jordan", "Read", role = c("aut","cre"),
email = "jread@usgs.gov"),
person("Luke", "Winslow", role = "aut",
email = "lwinslow@usgs.gov"))
Description: tools for working with the GLM lake model.
Description: Tools for working with the GLM lake model.
License: file LICENSE
Copyright: This software is in the public domain because it contains materials
that originally came from the United States Geological Survey, an agency of
Expand All @@ -30,3 +30,4 @@ VignetteBuilder: knitr
BuildVignettes: true
LazyLoad: yes
LazyData: yes
RoxygenNote: 5.0.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by roxygen2 (4.1.1): do not edit by hand
# Generated by roxygen2: do not edit by hand

S3method(print,nml)
S3method(summary,nml)
Expand Down
2 changes: 1 addition & 1 deletion R/plot_temp_compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @param fig_path F if plot to screen, string path if save plot as .png
#'@param \dots additional arguments passed to \code{\link{resample_to_field}}
#'
#'@seealso Internally uses \link{get_temp} and \link{resample_to_field}
#'@seealso Internally uses \code{\link{plot_var_compare}}, \code{\link{get_temp}} and \code{\link{resample_to_field}}
#'
#'@author Luke Winslow
#'
Expand Down
24 changes: 15 additions & 9 deletions R/plot_var_compare.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#'nml_file <- file.path(sim_folder, 'glm2.nml')
#'field_file <- file.path(sim_folder, 'field_data.tsv')
#'
#'plot_var_compare(nc_file, field_file, 'temp') ##makes a plot!
#'run_glm(sim_folder)
#'
#'plot_var_compare(nc_file, field_file, 'temp', resample=FALSE) ##makes a plot!
#'
#'@importFrom akima interp
#'@export
Expand All @@ -26,11 +28,7 @@ plot_var_compare = function(nc_file, field_file, var_name, fig_path = FALSE, res
warning('plot_var_compare not implemented for 1D variables')
return()
}

if (!resample){
warning('resample = FALSE is not yet supported for this function')
return()
}

start_par = par(no.readonly = TRUE)
#Create layout

Expand All @@ -39,7 +37,12 @@ plot_var_compare = function(nc_file, field_file, var_name, fig_path = FALSE, res


data = resample_to_field(nc_file, field_file, ...)
model_df <- resample_sim(mod_temp, t_out = unique(data$DateTime))
if(resample){
model_df <- resample_sim(mod_temp, t_out = unique(data$DateTime))
}else{
model_df = mod_temp
}

#Pivot observed into table

x = as.numeric(as.POSIXct(data$DateTime))
Expand All @@ -59,10 +62,13 @@ plot_var_compare = function(nc_file, field_file, var_name, fig_path = FALSE, res
names(obs_df) <- paste('var_',y_out, sep='')
obs_df <- cbind(data.frame(DateTime=as.POSIXct(x_out, origin='1970-01-01')), obs_df)

#Use model to define X-axis plotting extent for both graphs
xaxis <- get_xaxis(model_df[,1])

y.text = y_out[1]+diff(range(y_out))*0.05 # note, reference will ALWAYS be surface for compare to field data
.plot_df_heatmap(obs_df, bar_title = .unit_label(nc_file,var_name), overlays=c(points(x=x,y=y),text(x_out[1],y=y.text,'Observed', pos=4, offset = 1)))
.plot_df_heatmap(obs_df, bar_title = .unit_label(nc_file,var_name), overlays=c(points(x=x,y=y),text(x_out[1],y=y.text,'Observed', pos=4, offset = 1)), xaxis=xaxis)

.plot_df_heatmap(model_df, bar_title = .unit_label(nc_file,var_name), overlays=text(x_out[1],y=y.text,'Modeled', pos=4, offset = 1))
.plot_df_heatmap(model_df, bar_title = .unit_label(nc_file,var_name), overlays=text(x_out[1],y=y.text,'Modeled', pos=4, offset = 1), xaxis=xaxis)

par(start_par)#set PAR back to what it started at
if(is.character(fig_path))
Expand Down
7 changes: 5 additions & 2 deletions R/timeseries_plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
.plot_df_heatmap(data, title, num_cells, palette)
}

.plot_df_heatmap <- function(data, bar_title, num_cells, palette, title_prefix=NULL, overlays=NULL, ...){
.plot_df_heatmap <- function(data, bar_title, num_cells, palette, title_prefix=NULL, overlays=NULL, xaxis=NULL, ...){

z_out <- rLakeAnalyzer::get.offsets(data)
reference = ifelse(substr(names(data)[2],1,3) == 'elv', 'bottom', 'surface')
Expand All @@ -27,7 +27,10 @@
colors <- palette(n = length(levels)-1)
dates <- data[, 1]
matrix_var <- data.matrix(data[, -1])
xaxis <- get_xaxis(dates)
if(is.null(xaxis)){
xaxis <- get_xaxis(dates)
}

yaxis <- get_yaxis_2D(z_out, reference, prefix=title_prefix)
plot_layout(xaxis, yaxis, add=T)
.filled.contour(x = dates, y = z_out, z =matrix_var,
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
init:
ps: |
$ErrorActionPreference = "Stop"
Invoke-WebRequest http://raw.github.com/jread-usgs/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
Invoke-WebRequest http://raw.github.com/krlmlr/r-appveyor/master/scripts/appveyor-tool.ps1 -OutFile "..\appveyor-tool.ps1"
Import-Module '..\appveyor-tool.ps1'
install:
Expand Down
18 changes: 9 additions & 9 deletions man/compare_to_field.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_evaporation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/get_hypsography.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/get_ice.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_nml_value.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_raw.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_surface_height.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/get_temp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions man/get_var.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/get_wind.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/plot_compare_stage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/plot_meteo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/plot_temp.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions man/plot_temp_compare.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b92a8c3

Please sign in to comment.