Skip to content

Commit

Permalink
Merge pull request #12 from CSHS-CWRA/ch_prefix
Browse files Browse the repository at this point in the history
added prefix ch_ to all functions
  • Loading branch information
KevinShook authored Nov 20, 2019
2 parents 092da69 + 74e4ab2 commit 89f6135
Show file tree
Hide file tree
Showing 58 changed files with 844 additions and 572 deletions.
Binary file modified CSHShydRology.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: CSHShydRology
Title: Canadian hydrological analyses
Version: 1.0.1
Date: 2019-05-07
Version: 1.1.0
Date: 2019-09-03
Authors@R: c(person("Kevin", "Shook", email = "Kevin.Shook@usask.ca", role = c("cre")),
person("Paul", "Whitfield", email = "paul.h.whitfield@gmail.com", role = c("aut")),
person("Robert", "Chlumsky", email = "rchlumsk@gmail.com", role = c("aut")),
Expand Down
34 changes: 17 additions & 17 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
# Generated by roxygen2: do not edit by hand

export(binned_MannWhitney)
export(booth_plot)
export(ch_binned_MannWhitney)
export(ch_booth_plot)
export(ch_fdcurve)
export(ch_flow_raster)
export(ch_flow_raster_qa)
export(ch_flow_raster_trend)
export(ch_get_AHCCD_monthly)
export(ch_get_peaks)
export(ch_get_wscstation)
export(ch_hydrograph_plot)
export(ch_polar_plot)
export(ch_polar_plot_prep)
export(ch_read_AHCCD_daily)
export(ch_read_AHCCD_monthly)
export(ch_read_ECDE_flows)
export(ch_regime_plot)
export(ch_wtr_yr)
export(cut_block)
export(date_subset)
export(doys)
export(fdcurve)
export(flow_raster)
export(flow_raster_qa)
export(flow_raster_trend)
export(get_AHCCD_monthly)
export(get_peaks)
export(get_wscstation)
export(hydrograph_plot)
export(polar_plot)
export(polar_plot_prep)
export(read_AHCCD_daily)
export(read_AHCCD_monthly)
export(read_ECDE_flows)
export(regime_plot)
export(slice)
export(stack_EC)
export(sub_set_Years)
export(wtr_yr)
import(curl)
import(fields)
import(grDevices)
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# CSHShydRology 1.1.0
* Renamed all functions to have the prefix "ch"

# CSHShydRology 1.0.0
* First official version
* Contains functions by Paul Whitfield and Rob Chlumsky
Expand Down
10 changes: 5 additions & 5 deletions R/Basic_data-manipulations-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#' @name Basic_data_manipulation-functions
#' @description These functions read in or convert values among formats
#' \describe{
#' \item{read_ECDE_flows}{Reads a file of WSC daily flows from ECDataExplorer}
#' \item{get_wscstation}{Reads station information from a data file produced by ECDE}
#' \item{get_AHCCD_monthly}{Downloads monthly Adjusted and Homogenized Canadian Climate Data (AHCCD) values}
#' \item{read_AHCCD_daily}{Reads file of daily AHCCD values}
#' \item{read_AHCCD_monthly}{Reads file of monthly AHCCD values}
#' \item{ch_read_ECDE_flows}{Reads a file of WSC daily flows from ECDataExplorer}
#' \item{ch_get_wscstation}{Reads station information from a data file produced by ECDE}
#' \item{ch_get_AHCCD_monthly}{Downloads monthly Adjusted and Homogenized Canadian Climate Data (AHCCD) values}
#' \item{ch_read_AHCCD_daily}{Reads file of daily AHCCD values}
#' \item{ch_read_AHCCD_monthly}{Reads file of monthly AHCCD values}
#' }
NULL
6 changes: 3 additions & 3 deletions R/StatisticalHydrology-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#' @name StatisticalHydrology-functions
#' @description These functions perform statistical analyses
#' \describe{
#' \item{binned_MannWhitney}{ Compares two time periods of data using Mann-Whitney test}
#' \item{fdcurve}{Finds flow exceedence probabilities}
#' \item{get_peaks}{Finds peak flows over a specified threshold}
#' \item{ch_binned_MannWhitney}{ Compares two time periods of data using Mann-Whitney test}
#' \item{ch_fdcurve}{Finds flow exceedence probabilities}
#' \item{ch_get_peaks}{Finds peak flows over a specified threshold}
#' }
NULL
14 changes: 7 additions & 7 deletions R/Visualization-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
#' @description These functions are primarily intended for graphing, although
#' some analyses may also be done.
#' \describe{
#' \item{booth_plot}{Plot of peaks over a threshold}
#' \item{flow_raster}{Raster plot of streamflows}
#' \item{flow_raster_qa}{Raster plot of streamflows with WSC quality flags}
#' \item{flow_raster_trend}{Raster plot and simple trends of observed streamflows}
#' \item{hydrograph_plot}{Plots hydrographs and/or precipitation}
#' \item{polar_plot}{Polar plot of daily streamflows}
#' \item{regime_plot}{Plots the regime of daily streamflows}
#' \item{ch_booth_plot}{Plot of peaks over a threshold}
#' \item{ch_flow_raster}{Raster plot of streamflows}
#' \item{ch_flow_raster_qa}{Raster plot of streamflows with WSC quality flags}
#' \item{ch_flow_raster_trend}{Raster plot and simple trends of observed streamflows}
#' \item{ch_hydrograph_plot}{Plots hydrographs and/or precipitation}
#' \item{ch_polar_plot}{Polar plot of daily streamflows}
#' \item{ch_regime_plot}{Plots the regime of daily streamflows}
#' }
NULL
12 changes: 6 additions & 6 deletions R/binned_MannWhitney.R → R/ch_binned_MannWhitney.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' Compares two time periods of data using Mann-Whitney test
#'
#' It bins data based upon a bin size, extracting data for two time periods
#' It bins data based upon a specified size, extracting data for two time periods
#' and tests for change between two such periods. Result can be passed to
#' \code{polar_plot} for visualization
#' \code{ch_polar_plot} for visualization
#'
#' @author Paul Whitfield <paul.h.whitfield@gmail.com>
#' @references
Expand Down Expand Up @@ -40,21 +40,21 @@
#' }
#' @import stats
#' @export
#' @seealso \code{\link{polar_plot}} \code{\link{polar_plot_prep}}
#' @seealso \code{\link{ch_polar_plot}} \code{\link{ch_polar_plot_prep}}
#' @examples
#' \dontrun{
#' # fails due to missing data in both periods
#' range1 <- c(1960,1969)
#' range2 <- c(1990,1999)
#' b_MW <- binned_MannWhitney(W05AA008, step=5, range1, range2, ptest=0.05)}
#' b_MW <- ch_binned_MannWhitney(W05AA008, step=5, range1, range2, ptest=0.05)}
#'
#' range1 <- c(1970,1979)
#' range2 <- c(1990,1999)
#' b_MW <- binned_MannWhitney(W05AA008, step = 5, range1, range2,
#' b_MW <- ch_binned_MannWhitney(W05AA008, step = 5, range1, range2,
#' ptest = 0.05, station_ID = "05AA008", station_name= "Crowsnest River at Frank")
#'

binned_MannWhitney <- function(mdata, step, range1, range2, ptest = 0.05,
ch_binned_MannWhitney <- function(mdata, step, range1, range2, ptest = 0.05,
station_ID = "", station_name = "",
variable = "discharge") {
fail <- FALSE
Expand Down
14 changes: 7 additions & 7 deletions R/booth_plot.R → R/ch_booth_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#' A Booth plot is a plot of peaks over threshold flood events with duration on the horizontal and
#' either magnitude (default) or volume on the vertical axis
#'
#' @param events A data frame of POT events from the function \code{get_peaks}
#' @param threshold The threshold used by \code{get_peaks}
#' @param events A data frame of POT events from the function \code{ch_get_peaks}
#' @param threshold The threshold used by \code{ch_get_peaks}
#' @param title Plot title
#' @param type The plot type, either \option{mag} (magnitude, the default) or \option{vol} (volume)
#' @param colour1 A vector of length 12 with line colours of rings or symbols. Defaults to those used by Booth.
Expand All @@ -21,15 +21,15 @@
#' @export
#' @return No value is returned; a standard \R graphic is created.
#' @keywords plot
#' @seealso \code{\link{get_peaks}}
#' @seealso \code{\link{ch_get_peaks}}
#' @examples
#' threshold <- 0.1 * max(W05AA008$Flow) # arbitrary threshold
#' peaks <- get_peaks(W05AA008, threshold)
#' peaks <- ch_get_peaks(W05AA008, threshold)
#' events <- peaks$POTevents
#' booth_plot(events, threshold, title = "05AA008", type='mag')
#' booth_plot(events, threshold, title = "05AA008", type='vol')
#' ch_booth_plot(events, threshold, title = "05AA008", type='mag')
#' ch_booth_plot(events, threshold, title = "05AA008", type='vol')

booth_plot <- function(events, threshold, title, type = "mag", colour1 = 1, colour2 = 1) {
ch_booth_plot <- function(events, threshold, title, type = "mag", colour1 = 1, colour2 = 1) {

# set common items
mname <- c("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
Expand Down
6 changes: 3 additions & 3 deletions R/fdcurve.R → R/ch_fdcurve.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
#' @examples
#' flow <- W05AA008$Flow
#' # plot with Gustard 1992 curves
#' test <- fdcurve(flow, title="Station", normal=FALSE, gust=TRUE)
#' test <- ch_fdcurve(flow, title = "Station", normal = FALSE, gust = TRUE)
#'
#' # plot with normalized exceedance probability
#' test <- fdcurve(flow, title="Station", normal=TRUE, gust=FALSE)
#' test <- ch_fdcurve(flow, title = "Station", normal = TRUE, gust = FALSE)
#

fdcurve <- function(flow, title = "", normal = FALSE, gust = TRUE) {
ch_fdcurve <- function(flow, title = "", normal = FALSE, gust = TRUE) {

## load the values for the Gustard curves for %mean flow for Type Curves Gustard et al 1992.
g <- array(NA, dim = c(19, 7))
Expand Down
6 changes: 3 additions & 3 deletions R/flow_raster.R → R/ch_flow_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
#' @importFrom graphics axis legend par plot points polygon image
#' @importFrom fields image.plot
#' @export
#' @seealso \code{\link{flow_raster_trend}} \code{\link{flow_raster_qa}}
#' @seealso \code{\link{ch_flow_raster_trend}} \code{\link{ch_flow_raster_qa}}
#'
#' @examples
#' flow_raster(W05AA008)
#' ch_flow_raster(W05AA008)
#'

flow_raster <- function(dframe, title="", rastercolours = c("lightblue", "cyan", "blue", "slateblue", "orange", "red")) {
ch_flow_raster <- function(dframe, title="", rastercolours = c("lightblue", "cyan", "blue", "slateblue", "orange", "red")) {

##### Fixed labels and text strings
DOY <- "Day of Year"
Expand Down
6 changes: 3 additions & 3 deletions R/flow_raster_qa.R → R/ch_flow_raster_qa.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#' @importFrom timeDate dayOfYear as.timeDate
#' @importFrom fields image.plot
#' @export
#' @seealso \code{\link{flow_raster_trend}} \code{\link{flow_raster}}
#' @seealso \code{\link{ch_flow_raster_trend}} \code{\link{ch_flow_raster}}
#'

#' @examples
#' flow_raster_qa(W05AA008, "Station W05AA008")
#' ch_flow_raster_qa(W05AA008, "Station W05AA008")

flow_raster_qa <- function(dframe, title = "") {
ch_flow_raster_qa <- function(dframe, title = "") {
##### Fixed labels and text strings
DOY <- "Day of Year"
ylabelq <- expression(paste("Discharge m"^{3}, "/sec"))
Expand Down
9 changes: 4 additions & 5 deletions R/flow_raster_trend.R → R/ch_flow_raster_trend.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@
#' @importFrom fields image.plot
#' @importFrom graphics axis legend par plot points polygon
#' @export
#' @seealso \code{\link{flow_raster}}
#' @seealso \code{\link{ch_flow_raster}}
#' @examples
#' mdoy <- doys(W05AA008$Date)
#' mplot <- flow_raster_trend(W05AA008$Date, W05AA008$Flow, step=5, station="05AA008")
#' mplot <- ch_flow_raster_trend(W05AA008$Date, W05AA008$Flow, step = 5, station = "05AA008")
#'

flow_raster_trend <- function(date, flow, step = 5, stationID = "", title = "", missing = FALSE,
ch_flow_raster_trend <- function(date, flow, step = 5, stationID = "", title = "", missing = FALSE,
colours = c("lightblue", "cyan", "blue", "slateblue", "darkblue", "red")) {
l_disch <- expression(paste("m"^{3}, "/sec"))

Expand Down Expand Up @@ -116,7 +116,6 @@ flow_raster_trend <- function(date, flow, step = 5, stationID = "", title = "",
arrow <- array(1, length(period))

for (i in 1:length(period)) { ### loop over getting values for periods of year

med_n[i] <- median(qsliced[i, ], na.rm = TRUE)
max_n[i] <- max(qsliced[i, ], na.rm = TRUE)
min_n[i] <- min(qsliced[i, ], na.rm = TRUE)
Expand Down Expand Up @@ -167,7 +166,7 @@ flow_raster_trend <- function(date, flow, step = 5, stationID = "", title = "",
par(oma = c(0, 0, 3, 0))
qcols <- colorRampPalette(colours)

nf <- layout(matrix(c(2, 4, 1, 3), 2, 2, byrow = TRUE), c(3, 1), c(1, 3), TRUE)
# nf <- layout(matrix(c(2, 4, 1, 3), 2, 2, byrow = TRUE), c(3, 1), c(1, 3), TRUE)


##################################################### panel one raster image
Expand Down
16 changes: 8 additions & 8 deletions R/get_AHCCD_monthly.R → R/ch_get_AHCCD_monthly.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#' @return Returns a data frame with the monthly values and associated variables.
#' @author Kevin Shook
#' @seealso \code{\link{read_AHCCD_daily}} \code{\link{read_AHCCD_monthly}}
#' @seealso \code{\link{ch_read_AHCCD_daily}} \code{\link{ch_read_AHCCD_monthly}}
#' @references Use of the data must cite \cite{Mekis, E and L.A. Vincent, 2011: An overview of
#' the second generation adjusted daily temperature and precipitation dataset for trend analysis in Canada.
#' Atmosphere-Ocean, 49 (2), 163-177.}
Expand All @@ -30,26 +30,26 @@
#' @export
#'
#' @examples
#' stoon_monthly_precip <- get_AHCCD_monthly("4057120", "SK", "PCP")
get_AHCCD_monthly <- function(station, province, variable, url = "http://dd.weather.gc.ca/climate/ahccd/geojson/historical/monthly/") {
#' stoon_monthly_precip <- ch_get_AHCCD_monthly("4057120", "SK", "PCP")
ch_get_AHCCD_monthly <- function(station, province, variable, url = "http://dd.weather.gc.ca/climate/ahccd/geojson/historical/monthly/") {

provinces <- c("AB", "BC", "MB", "NB", "NL","NS", "NT", "NU", "ON", "PE", "QC", "SK", "YT")
variables <- c("PCP", "RA", "SN", "TMAX", "TMIN", "TMEAN", "PSFC", "SFCWND", "SLP")

# check that parameters are passed
if (station == "" | is.null(station) ){
if (station == "" | is.null(station) ) {
stop("station not specified")
}

if (province == "" | is.null(province)){
if (province == "" | is.null(province)) {
stop("province not specified")
}

if (variable == "" | is.null(variable) ){
if (variable == "" | is.null(variable) ) {
stop("variable not specified")
}

if (url == "" | is.null(url) ){
if (url == "" | is.null(url) ) {
stop("url not specified")
}

Expand All @@ -68,7 +68,7 @@ get_AHCCD_monthly <- function(station, province, variable, url = "http://dd.weat

# make sure station name is valid, i.e. that the variable exists

all <- fromJSON(station_file, flatten=FALSE)
all <- fromJSON(station_file, flatten = FALSE)
vals <- all$features$properties
return(vals)
}
6 changes: 3 additions & 3 deletions R/get_peaks.R → R/ch_get_peaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
#' for analysis of the 2013 flood in the Upper Bow River, Canada. Hydrological Processes 30:4657-73. doi:
#' 10.1002/hyp.10957.
#' @export
#' @seealso \code{\link{booth_plot}}
#' @seealso \code{\link{ch_booth_plot}}
#' @examples
#' threshold <- 0.9*max(W05AA008$Flow) # arbitrary threshold
#' my_peaks <- get_peaks(W05AA008, threshold)
#' my_peaks <- ch_get_peaks(W05AA008, threshold)
#' str(my_peaks)

get_peaks <- function(dataframe, threshold) {
ch_get_peaks <- function(dataframe, threshold) {
data <- dataframe$Flow
Date <- dataframe$Date
event <- array(0, dim = length(data))
Expand Down
4 changes: 2 additions & 2 deletions R/get_wscstation.R → R/ch_get_wscstation.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
#'
#' @examples
#' df <- HYDAT_list
#' s_info <- get_wscstation("05BB001", df)
#' s_info <- ch_get_wscstation("05BB001", df)
#' title <- s_info[21]
#' print(title)
#'

get_wscstation <- function(stnID, stn) {
ch_get_wscstation <- function(stnID, stn) {

rhbn <- NULL
stninfo <- stn[stn$Station == stnID, ]
Expand Down
10 changes: 5 additions & 5 deletions R/hydrograph_plot.R → R/ch_hydrograph_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,19 @@
#' precip <- data.frame("Date" = dd," precip" = abs(rnorm(length(dd))) * 10)
#'
#' # basic hydrograph plot
#' hydrograph_plot(flows = df, winter_shading = FALSE)
#' ch_hydrograph_plot(flows = df, winter_shading = FALSE)
#'
#' # with different labels
#' hydrograph_plot(flows = df, winter_shading = FALSE, flow_labels = c("simulated", "observed"))
#' ch_hydrograph_plot(flows = df, winter_shading = FALSE, flow_labels = c("simulated", "observed"))
#'
#' # with a few more options turned on
#' hydrograph_plot(flows = df, precip = precip)
#' ch_hydrograph_plot(flows = df, precip = precip)
#'
#' # increase the plot ranges to separate flows and precip; add a legend box
#' hydrograph_plot(flows = df, precip = precip, range_mult_flow = 1.7,
#' ch_hydrograph_plot(flows = df, precip = precip, range_mult_flow = 1.7,
#' range_mult_precip = 2, leg_box = TRUE)

hydrograph_plot <- function(flows = NULL,
ch_hydrograph_plot <- function(flows = NULL,
precip = NULL,
prd = NULL,
winter_shading = FALSE,
Expand Down
Loading

0 comments on commit 89f6135

Please sign in to comment.