Skip to content

Commit

Permalink
Merge branch 'dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
rchlumsk authored May 6, 2024
2 parents f213eab + 336498f commit 71d32ae
Show file tree
Hide file tree
Showing 36 changed files with 921 additions and 144 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
^.rvt$

R/rvn_rvi_process_visplot
^\.github$
50 changes: 50 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
# - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
# - {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
# upload-snapshots: true
error-on: '"error"'
46 changes: 46 additions & 0 deletions .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]
release:
types: [published]
workflow_dispatch:

name: pkgdown

jobs:
pkgdown:
runs-on: ubuntu-latest
# Only restrict concurrency for non-PR jobs
concurrency:
group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }}
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::pkgdown, local::.
needs: website

- name: Build site
run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE)
shell: Rscript {0}

- name: Deploy to GitHub pages 🚀
if: github.event_name != 'pull_request'
uses: JamesIves/github-pages-deploy-action@v4.4.1
with:
clean: false
branch: gh-pages
folder: docs
50 changes: 50 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: test-coverage

jobs:
test-coverage:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: |
covr::codecov(
quiet = FALSE,
clean = FALSE,
install_path = file.path(Sys.getenv("RUNNER_TEMP"), "package")
)
shell: Rscript {0}

- name: Show testthat output
if: always()
run: |
## --------------------------------------------------------------------
find ${{ runner.temp }}/package -name 'testthat.Rout*' -exec cat '{}' \; || true
shell: bash

- name: Upload test results
if: failure()
uses: actions/upload-artifact@v3
with:
name: coverage-test-failures
path: ${{ runner.temp }}/package
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
export("%>%")
export("%notin%")
export(cmax)
export(hhmmss2dec)
export(rvn_annual_peak)
export(rvn_annual_peak_error)
export(rvn_annual_peak_event)
Expand Down Expand Up @@ -61,12 +62,14 @@ export(rvn_rvh_subbasin_visnetwork_plot)
export(rvn_rvh_summarize)
export(rvn_rvh_write)
export(rvn_rvh_write_subbasingroup)
export(rvn_rvi_commandupdate)
export(rvn_rvi_connections)
export(rvn_rvi_getparams)
export(rvn_rvi_process_diagrammer)
export(rvn_rvi_process_ggplot)
export(rvn_rvi_read)
export(rvn_rvi_write_template)
export(rvn_rvp_calib_template)
export(rvn_rvp_fill_template)
export(rvn_rvt_read)
export(rvn_rvt_tidyhydat)
Expand Down
8 changes: 5 additions & 3 deletions R/rvn_apply_wyearly.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#' mm and dd indicate the end of the water year period (i.e. mm=9 and dd=30 indicates
#' a new water year on Oct 1).
#'
#' Note that if using \code{FUN=mean}, please use \code{FUN=colMeans} instead.
#'
#' @param x xts vector to calculate FUN for
#' @param FUN the function to be applied
#' @param ... optional arguments to FUN
Expand All @@ -22,11 +24,11 @@
#' # use sample forcing data (or use forcings_read to read in ForcingFunctions.csv)
#' data(rvn_forcing_data)
#'
#' # apply mean as FUN to daily average temperature
#' rvn_apply_wyearly(rvn_forcing_data$forcings$temp_daily_ave,mean,na.rm=TRUE)
#' # apply mean (with colMeans) as FUN to daily average temperature
#' rvn_apply_wyearly(rvn_forcing_data$forcings$temp_daily_ave,colMeans,na.rm=TRUE)
#'
#' # apply mean as FUN to all forcings
#' rvn_apply_wyearly(rvn_forcing_data$forcings,mean,na.rm=TRUE)
#' rvn_apply_wyearly(rvn_forcing_data$forcings,colMeans,na.rm=TRUE)
#'
#' # apply maximum via RavenR::cmax as FUN to all forcings (takes the max in each column)
#' ## note that the base::max will not work properly here
Expand Down
2 changes: 1 addition & 1 deletion R/rvn_budyko_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ rvn_budyko_plot <- function(x=NULL, x_indices=NULL, limiting_labels=FALSE, budyk

if (!is.null(x)) {
# convert x into x_indices
temp <- rvn_apply_wyearly(x, FUN=mean,na.rm=TRUE,mm=mm,dd=dd)
temp <- rvn_apply_wyearly(x, FUN=colMeans,na.rm=TRUE,mm=mm,dd=dd)

if (year(temp[nrow(temp)]) == year(temp[(nrow(temp)-1)])) {
temp <- temp[1:(nrow(temp)-1),]
Expand Down
6 changes: 3 additions & 3 deletions R/rvn_hyd_extract.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#' form "subXX", for example "sub24".
#'
#' The hyd object is the full hydrograph object (hyd and units in one data
#' frame) created by the hyd.read function. Both the hyd and units are
#' frame) created by the rvn_hyd_read function. Both the hyd and units are
#' required, since the units are placed onto the plots if one is created. This
#' is useful to at least see the units of the plotted variable, even if the
#' plot is later modified.
Expand All @@ -28,7 +28,7 @@
#' no period is supplied, the entire time series will be used.
#'
#' @param subs column name for plotting/extracting
#' @param hyd full hydrograph data frame (including units) produced by hyd.read
#' @param hyd full hydrograph data frame (including units) produced by rvn_hyd_read
#' @param prd time period for plotting, as string. See details
#' @param rename_cols boolean for whether to rename columns to generic terms (sim, obs, etc.) or leave
#' column names as they appear in hyd
Expand Down Expand Up @@ -72,7 +72,7 @@ rvn_hyd_extract <- function(subs=NA, hyd=NA, prd=NULL, rename_cols=TRUE) {
stop("subs is required for this function.")
}
if (missing(hyd)) {
stop("hyd is required for this function; please supply the full output file from hyd.read.")
stop("hyd is required for this function; please supply the full output file from rvn_hyd_read.")
}

mysub <- ind <- NULL
Expand Down
3 changes: 2 additions & 1 deletion R/rvn_hyd_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ rvn_hyd_plot <- function(sim=NULL,obs=NULL,inflow=NULL,precip=NULL,prd=NULL,
ylab(expression("Flow ("*m^3*"/s)"))+
rvn_theme_RavenR()+
theme(legend.position = "bottom") +
scale_colour_brewer(type = "qual", palette = 3)
# scale_colour_brewer(type = "qual", palette = 3)+
scale_colour_manual(name='Legend',values=c("Obs"='black',"Sim"='darkorange',"Inflow"="purple"))

#Shade Winter Months
if (winter_shading){
Expand Down
28 changes: 21 additions & 7 deletions R/rvn_met_recordplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#' from the \pkg{weathercan} package and extracts the start and end dates of the record
#' from each station for plotting.
#'
#' Outputs from \code{stations_search()} indicate when data collection at a station generally
#' began but do not contain information for specific climate variables and thus should
#' only be used for a "first look". Plots created with station metadata do not refer to
#' specific climate variables.
#'
#' Station records are plotted chronologically on a timeline, and can be colored
#' according to either the station's elevation (default, works for both types of inputs)
#' or the station's distance from a point of interest (works only when supplying
Expand All @@ -22,7 +27,7 @@
#' the effect of lapse rates on climate forcings driving a model response.
#'
#' @param metadata tibble of the station meta-data from \code{weathercan::stations_search()}
#' @param stndata tibble of the station data from \code{weathercan::weather_dl()}
#' @param stndata tibble of the station data from \code{weathercan::weather_dl()}. Used in conjunction with \code{variables} argument.
#' @param variables if using \code{weathercan::weather_dl()}, column names for variables of interest (currently only accepts 1 per call)
#' @param colorby column name by which to color station records. Set to 'elev' (elevation) by default. Can be set to
#' "dist" (distance from coordinates of interest) if supplying \code{weathercan::stations_search} results.
Expand Down Expand Up @@ -66,9 +71,18 @@ rvn_met_recordplot <- function(metadata=NULL,stndata=NULL,variables=NULL,colorby

start <- station_name <- nstations <- NA

# ensure there is a list of stations to read
if(!is.null(metadata) & !is.null(stndata)){
stop('Please supply either one of the outputs from weathercan::weather_dl() OR weathercan::stations_search(), not both')}

# prevent user from searching climate variable records from stations_search( ) results
if(!is.null(metadata) & !is.null(variables)){
stop(paste("Metadata argument returns overall station record periods (which may not reflect the record period for a specific climate variable observed at that station).",
"If looking for records pertaining to a specific climate variable, please use the 'stndata' and 'variables' arguments together.",sep='\n'
))
}

# restrict user to only plotting a subset of climate variables (not all at once)
if(!is.null(stndata) & is.null(variables)){
stop('Please specify which variable you would like to view record lengths for')
}
Expand All @@ -92,8 +106,8 @@ rvn_met_recordplot <- function(metadata=NULL,stndata=NULL,variables=NULL,colorby
metadata$station_name=factor(metadata$station_name,levels=metadata$station_name[order(-metadata$start)])

# plot records to show overlap
xmax = max(metadata$end)
xmin = min(metadata$start)
xmax = max(na.omit(metadata$end))
xmin = min(na.omit(metadata$start))

if(is.null(variables)){variables = 'overall station records'} # plot title

Expand Down Expand Up @@ -123,13 +137,13 @@ rvn_met_recordplot <- function(metadata=NULL,stndata=NULL,variables=NULL,colorby
scale_x_continuous(limits=c(xmin,xmax),breaks=seq(xmin,xmax,1))+
theme_bw()+
theme(plot.title=element_text(hjust=0.5),plot.subtitle=element_text(hjust = 0.5),
legend.position = 'bottom',axis.title.y=element_blank())
legend.position = 'bottom',axis.title.y=element_blank(),axis.text.x=element_text(angle=90))
}

# Count number of station records available for each year
year = min(metadata$start):max(metadata$end)
year = min(na.omit(metadata$start)):max(na.omit(metadata$end))
recordsum = do.call('rbind',lapply(year,function(y){
n = sum(metadata$start <= y & metadata$end >= y)
n = sum(metadata$start <= y & metadata$end >= y,na.rm=T)
return(data.frame(year=y,nstations=n))
}))

Expand All @@ -141,7 +155,7 @@ rvn_met_recordplot <- function(metadata=NULL,stndata=NULL,variables=NULL,colorby
ylab('stations')+
scale_x_continuous(breaks=seq(xmin,xmax,1))+
theme_bw()+
theme(plot.title=element_text(hjust = 0.5))
theme(plot.title=element_text(hjust = 0.5),axis.text.x=element_text(angle=90))

out <- plot_grid(overlapPlot,stncount,nrow=2 )
return(out)
Expand Down
2 changes: 1 addition & 1 deletion R/rvn_monthly_vbias.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#' @importFrom ggplot2 ggplot geom_bar aes scale_y_continuous scale_x_continuous geom_hline geom_text
#' @importFrom xts apply.monthly
#' @importFrom lubridate month
rvn_monthly_vbias <- function (sim, obs, add_line = TRUE, normalize = TRUE, add_labels = TRUE,
rvn_monthly_vbias <- function(sim, obs, add_line = TRUE, normalize = TRUE, add_labels = TRUE,
incomplete_month = FALSE)
{

Expand Down
2 changes: 1 addition & 1 deletion R/rvn_rvh_blankSBdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ rvn_rvh_blankSBdf <- function(nSubBasins = 1) {
df <- data.frame('SBID' = 1:nSubBasins,
'Name' = subnames,
'Downstream_ID' = downstreamid,
'Profile' = "DEFAULT",
'Profile' = "NONE",
'ReachLength' = 0.0,
'Gauged' = 0)
return(df)
Expand Down
47 changes: 22 additions & 25 deletions R/rvn_rvh_write_subbasingroup.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,28 @@
#' @export rvn_rvh_write_subbasingroup
rvn_rvh_write_subbasingroup <- function(rvh=NULL, sbgroup_name=NULL, outfile=NULL, subs_per_line=30, overwrite=TRUE)
{

# input checking
if (is.null(rvh) | is.null(rvh$SBtable)) {
stop("rvn_rvh_summarize: valid rvh object is required")
}

if (is.null(sbgroup_name)) {
sbgroup_name <- "subgroup_RavenR_generated"
}

if (is.null(outfile)) {
outfile <- "subbasingroup_RavenR.rvh"
}

fc <- file(outfile, open = "wt")
writeLines(sprintf(":SubBasinGroup %s",sbgroup_name), fc)
for (i in seq(from=1,to=min(nrow(rvh$SBtable),subs_per_line), by=subs_per_line)) {
temp <- rvh$SBtable$SBID[i:(min(i+subs_per_line-1,nrow(rvh$SBtable)))] %>%
paste0(collapse=", ")
sprintf(" %s",temp) %>%
writeLines(fc)
}
writeLines(":EndSubBasinGroup", fc)
close(fc)

message(sprintf("Successfully wrote SubBasinGroup '%s' to file %s",sbgroup_name,outfile))
return(TRUE)
stop("rvn_rvh_write_subbasingroup: valid rvh object is required")
}
if (is.null(sbgroup_name)) {
sbgroup_name <- "subgroup_RavenR_generated"
}
if (is.null(outfile)) {
outfile <- "subbasingroup_RavenR.rvh"
}
fc <- file(outfile, open = "wt")
writeLines(sprintf(":SubBasinGroup %s", sbgroup_name),
fc)
iseq <- seq(from = 1, to = nrow(rvh$SBtable),
by = (subs_per_line-1))
for (i in 1:(length(iseq)-1) ) {
temp <- rvh$SBtable$SBID[iseq[i]:iseq[i+1]] %>% paste0(collapse = ", ")
sprintf(" %s", temp) %>% writeLines(fc)
}
writeLines(":EndSubBasinGroup", fc)
close(fc)
message(sprintf("Successfully wrote SubBasinGroup '%s' to file %s on %i lines",
sbgroup_name, outfile, length(iseq)+1))
return(TRUE)
}
Loading

0 comments on commit 71d32ae

Please sign in to comment.