| Type: | Package |
| Title: | River Hydrograph Separation and Analysis |
| Version: | 0.1 |
| Date: | 2025-10-02 |
| Description: | River hydrograph separation and daily runoff time series analysis. Provides various filters to separate baseflow and quickflow. Implements advanced separation technique by Rets et al. (2022) <doi:10.1134/S0097807822010146> which involves meteorological data to reveal genetic components of the runoff: ground, rain, thaw and spring (seasonal thaw). High-performance C++17 computation, annually aggregated variables, statistical testing and numerous plotting functions for high-quality visualization. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/tsamsonov/grwat,https://tsamsonov.github.io/grwat/ |
| BugReports: | https://github.com/tsamsonov/grwat/issues |
| Encoding: | UTF-8 |
| Language: | en-US |
| LinkingTo: | Rcpp |
| SystemRequirements: | pandoc |
| LazyData: | true |
| RoxygenNote: | 7.3.3 |
| VignetteBuilder: | knitr |
| Depends: | R (≥ 4.1) |
| Imports: | cli, Rcpp, dplyr, tidyr, lubridate, stringr, rlang, grid,ggplot2, zoo, trend, mblm, R.utils |
| Suggests: | ggridges, ggHoriPlot, ggthemes, kableExtra, knitr, ncdf4,rmarkdown, sf, testthat, stringi |
| NeedsCompilation: | yes |
| Packaged: | 2025-10-02 16:20:18 UTC; tsamsonov |
| Author: | Timofey Samsonov |
| Maintainer: | Timofey Samsonov <tsamsonov@geogr.msu.ru> |
| Repository: | CRAN |
| Date/Publication: | 2025-10-02 17:50:09 UTC |
Extract baseflow
Description
Extract baseflow from hydrological series using the filtering approach
Usage
gr_baseflow( Q, a = 0.925, k = 0.975, C = 0.05, aq = -0.5, passes = 3, padding = 30, method = "lynehollick")Arguments
Q | Numeric runoff vector. |
a | Numeric value of a filtering parameter used in |
k | Numeric value of a filtering parameter used in |
C | Numeric value of a separation shape parameter used in |
aq | Numeric value of a filtering parameter used in |
passes | Integer number of filtering iterations. The first iteration is forward, second is backward, third is forward and so on. Defaults to |
padding | Integer number of elements padded at the beginning and ending of runoff vector to reduce boundary effects. Defaults to |
method | Character string to set baseflow filtering method. Available methods are |
Value
Numeric baseflow vector with length equal toQ
Examples
library(grwat)library(ggplot2)library(dplyr)library(tidyr)library(lubridate)data(spas) # example Spas-Zagorye data is included with grwat package# Calculate baseflow using Line-Hollick approachhdata = spas |> mutate(Qbase = gr_baseflow(Q, method = 'lynehollick', a = 0.925, passes = 3))# Visualize for 1980 yearggplot(hdata) + geom_area(aes(Date, Q), fill = 'steelblue', color = 'black') + geom_area(aes(Date, Qbase), fill = 'orangered', color = 'black') + scale_x_date(limits = c(ymd(19800101), ymd(19801231)))# Compare various approacheshdata = spas |> mutate(lynehollick = gr_baseflow(Q, method = 'lynehollick', a = 0.9), boughton = gr_baseflow(Q, method = 'boughton', k = 0.9), jakeman = gr_baseflow(Q, method = 'jakeman', k = 0.9), maxwell = gr_baseflow(Q, method = 'maxwell', k = 0.9)) |> pivot_longer(lynehollick:maxwell, names_to = 'Method', values_to = 'Qbase')# Visualize for 1980 yearggplot(hdata) + geom_area(aes(Date, Q), fill = 'steelblue', color = 'black') + geom_area(aes(Date, Qbase), fill = 'orangered', color = 'black') + scale_x_date(limits = c(ymd(19810101), ymd(19811231))) + facet_wrap(~Method)# Compare Lyne to Kudelinp = gr_get_params('center')p$filter = 'kudelin'hdata = spas |> mutate(lynehollick = gr_baseflow(Q, method = 'lynehollick', a = 0.925, passes = 3), kudelin = gr_separate(spas, p)$Qbase) |> pivot_longer(lynehollick:kudelin, names_to = 'Method', values_to = 'Qbase')# Visualize for 1980 yearggplot(hdata) + geom_area(aes(Date, Q), fill = 'steelblue', color = 'black') + geom_area(aes(Date, Qbase), fill = 'orangered', color = 'black') + scale_x_date(limits = c(ymd(19800101), ymd(19801231))) + facet_wrap(~Method)Quasi-geographic buffering
Description
Generate the buffer of spatial object in geographic coordinates. The function transforms the object into Azimuthal equidistant projection, then buffers it by the specified radius and then reprojects into geographical coordinate system (WGS84)
Usage
gr_buffer_geo(g, bufsize)Arguments
g |
|
bufsize | Numeric value of a buffer distance, in meters. |
Value
sf orsfg object, buffered tobufsize and projected into geographic coordinates (WGS84).
Examples
if (require("sf")) { library(grwat) library(ggplot2) path = system.file("extdata", "spas-zagorye.gpkg", package = "grwat") basin = sf::st_read(path, layer = 'basin') # read basin region basin_buffer = gr_buffer_geo(basin, 25000) ggplot() + geom_sf(data = basin_buffer, fill = 'orangered', color = 'black') + geom_sf(data = basin, fill = 'steelblue', color = 'black')}Check the correctness of data frame for separating
Description
This function is called insidegr_separate(), but can be used explicitly inside your code.
Usage
gr_check_data(df)Arguments
df |
|
Value
stops execution ifdf contains the wrong number of columns, or the columns have the wrong types, or the data in columns is incorrect (e.g. runoff or precipitation are negative).
Examples
library(grwat)# example Spas-Zagorye data is included with grwat packagedata(spas)head(spas)gr_check_data(spas)# raw Spas-Zagorye data represents date components# in columns and does not contain meteorologgical variablespath = system.file("extdata", "spas-zagorye.txt", package = "grwat")hdata_raw = read.delim(path, header = FALSE, sep = ' ', na.strings = c('-999', '-999.0', '-'), col.names = c('d', 'm', 'y', 'q'))print(hdata_raw)try(gr_check_data(hdata_raw))Check the correctness of parameters list for separating
Description
Check the correctness of parameters list for separating
Usage
gr_check_params(params, df = NULL)Arguments
params |
|
df |
|
Value
stops the execution if anything is wrong and prints the exact reason of the error. Otherwise prints the message that everything is OK
Examples
library(grwat)# example Spas-Zagorye data is included with grwat packagedata(spas)params = gr_get_params(reg = 'center')gr_check_params(params)# set the unknown parameterparams$new = -2# use try if you do not want to stop at errortry(gr_check_params(params))# remove wrong parameterparams$new = NULL# remove right parameterparams$grad1 = NULLtry(gr_check_params(params))# resetparams = gr_get_params(reg = 'center')sep = gr_separate(spas, params, debug = TRUE)parlist = attributes(sep)$paramsparlist[['2002']]$grad1 = 4# if the parlist is used for separation# then data frame must be specifiedtry(gr_check_params(parlist))gr_check_params(parlist, spas)# grad parameter is not knownparlist[['2002']]$grad = 4try(gr_check_params(parlist, spas))# remove wrong parameterparlist[['2002']]$grad = NULL# remove yearparlist[['2002']] = NULLtry(gr_check_params(parlist, spas))parlist[['2002']] = parlist[['2001']]gr_check_params(parlist, spas)Fill missing daily data
Description
Use the function to fill the missing daily data by linear interpolation. These can be both missing dates and missing runoff or temperature values. A preliminary summary of missing data can be viewed bygr_get_gaps()
Usage
gr_fill_gaps(hdata, autocorr = 0.7, nobserv = NULL)Arguments
hdata |
|
autocorr | Autocorrelation value that defines possible length of the period that can be filled. Defaults to 0.7. If |
nobserv | Maximum number of contiguous observations that can be interpolated. Defaults to |
Value
data.frame which is a filled version ofhdata
Examples
library(grwat)library(dplyr)# example Spas-Zagorye data is included with grwat packagepath = system.file("extdata", "spas-zagorye.txt", package = "grwat")hdata_raw = read.delim(path, header = FALSE, sep = ' ', na.strings = c('-999', '-999.0', '-'), col.names = c('d', 'm', 'y', 'q'))hdata = hdata_raw |> transmute(Date = lubridate::make_date(y, m, d), Q = q)head(hdata)# identify gapsgr_get_gaps(hdata) # fill gapsfhdata = gr_fill_gaps(hdata, autocorr = 0.8)# check the resultsgr_get_gaps(fhdata)# fill gapsfhdata = gr_fill_gaps(hdata, nobserv = 7)# check the resultsgr_get_gaps(fhdata)Convert data frame of parameters to list
Description
Convert data frame of parameters to list
Usage
gr_from_pardf(pardf)Arguments
pardf |
|
Value
list oflists of hydrograph separation parameters as returned inparams attribute bygr_separate() withdebug = TRUE.
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat packagehead(spas)# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# Visualizegr_plot_sep(sep, c(1978, 1989)) # Debug mode gives access to additional informationsep_debug = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE)# a vector of years with jittered paramsjit = attributes(sep_debug)$jitteredprint(jit)# actual params used for each yearparlist = attributes(sep_debug)$params# tweak parameters for selected yearparlist[['1989']]$grad1 = 3parlist[['1989']]$grad2 = 6# tabular representation of parameterspartab = gr_to_pardf(parlist)head(partab)partab |> dplyr::filter(year == 1989) |> head()parlist_back = gr_from_pardf(partab)head(parlist_back[['1989']])Get gaps in the daily data
Description
Use the function to detect periods of missing data. The first column must be ofDate type. The data is considered to be a gap if any value in the row is missing.
Usage
gr_get_gaps(hdata)Arguments
hdata |
|
Value
data.frame with periods of data and periods of gaps, containing five columns: number of the period (num), start of the period (start_date), end of the period (end_date), duration of the period (duration) and type of the period (type).
Examples
library(grwat)library(dplyr)# example Spas-Zagorye data is included with grwat packagepath = system.file("extdata", "spas-zagorye.txt", package = "grwat")hdata_raw = read.delim(path, header = FALSE, sep = ' ', na.strings = c('-999', '-999.0', '-'), col.names = c('d', 'm', 'y', 'q'))hdata = hdata_raw |> transmute(Date = lubridate::make_date(y, m, d), Q = q)head(hdata)# identify gapsgr_get_gaps(hdata) # fill gapsfhdata = gr_fill_gaps(hdata, autocorr = 0.8)# check the resultsgr_get_gaps(fhdata)# fill gapsfhdata = gr_fill_gaps(hdata, nobserv = 7)# check the resultsgr_get_gaps(fhdata)Get hydrograph separation parameters
Description
The function returns the list of parameters that can be used bygr_separate(). Since the parameters are region-specific, the location must be selected. It can be identified by region name or geographic coordinates. If both are specified, then region have a higher priority
Usage
gr_get_params(reg = "center", lon = NULL, lat = NULL)Arguments
reg | Character string — the name of the region. Defaults to |
lon | Numeric value of the longitude. Ignored if |
lat | Numeric value of the latitude. Ignored if |
Value
List of separation parameters that can be used ingr_separate() function.
Examples
library(grwat)params = gr_get_params(reg = 'center')print(params)Get the information about parameters used to separate the hydrograph
Description
Get the information about parameters used to separate the hydrograph
Usage
gr_help_params()Value
data.frame with description of hydrograph separation parameters that are used ingr_separate() .
Examples
library(grwat)gr_help_params()Hydrograph separation variables
Description
Use this function to learn the meaning of the variables that are calculated bygr_summarize().
Usage
gr_help_vars()Value
data.frame of hydrograph separation variables
Examples
library(grwat)gr_help_vars()Join reanalysis data
Description
The function performs spatial join of meteorological variables (temperature and precipitation) fromgrwat reanalysis to the daily runoff time series. Reanalysis covers the East European Plain with 0.75 degrees spatial resolution and is obtained based on CIRES-DOE (1880-1949) and ERA5 (1950-2021) data. This function is useful when the data from meteorological stations are missing inside the basin.
Usage
gr_join_rean(hdata, rean, buffer)Arguments
hdata |
|
rean |
|
buffer |
|
Details
Download the reanalysis archive fromhere.
Value
data.frame with four columns: date, runoff, temperature, precipitation.
Examples
if (require("sf") && require("ncdf4")) { library(grwat) library(dplyr) # example Spas-Zagorye daily runoff data is included with grwat package data_path = system.file("extdata", "spas-zagorye.txt", package = "grwat") hdata_raw = read.delim(data_path, header = FALSE, sep = ' ', na.strings = c('-999', '-999.0', '-'), col.names = c('d', 'm', 'y', 'q')) hdata = hdata_raw |> transmute(Date = lubridate::make_date(y, m, d), Q = q) head(hdata) # read basin basin_path = system.file("extdata", "spas-zagorye.gpkg", package = "grwat") basin = sf::st_read(basin_path, layer = 'basin') # read basin region basin_buffer = gr_buffer_geo(basin, 25000) ## Not run: # read reanalysis data rean = gr_read_rean( '/Volumes/Data/Spatial/Reanalysis/grwat/pre_1880-2021.nc', '/Volumes/Data/Spatial/Reanalysis/grwat/temp_1880-2021.nc' ) # spatial join of reanalysis data to runoff data hdata_rean = gr_join_rean(hdata, rean, basin_buffer) head(hdata_rean) ## End(Not run)}Tabular representation of tests
Description
This function is used to represent the results ofgr_test_vars() in a tabular form. Used mainly ingr_report(), but can be used for your own purposes.
Usage
gr_kable_tests(tests, format = "html")Arguments
tests |
|
format | Character string encoding the type of output. Currently |
Value
HTML table as returned byknitr::kable() function.
Examples
if (require("kableExtra")) { library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # summarize from 1965 to 1990 vars = gr_summarize(sep, 1965, 1990) # test all variables tests = gr_test_vars(vars) # kable tests gr_kable_tests(tests)}Plot runoff ACF
Description
The function plots the autocorrelation function (ACF) for daily runoff time series. A number of days corresponding to the specifiedautocorr value is highlighted.
Usage
gr_plot_acf(hdata, autocorr = 0.7, maxlag = 30, print = TRUE)Arguments
hdata |
|
autocorr | Numeric value of the autocorrelation for which the time period will be highlighted. Defaults to |
maxlag | Integer value of the maximum daily lag used to calculate the correlation. Defaults to |
print | Boolean. Print plot? Defaults to |
Value
ggplot2 object representing the autocorrelation function (ACF) for daily runoff time series
Examples
library(grwat)# example Spas-Zagorye data is included with grwat packagedata(spas)head(spas)# plot ACFgr_plot_acf(spas, 0.65)Horizon hydrograph plot
Description
A convenient wrapper aroundggHoriPlot::geom_horizon() to visualize multiple river hydrographs at once.
Usage
gr_plot_hori(df, years, pal = "Blues", rev = TRUE, scale = 6, print = TRUE)Arguments
df |
|
years | Integer vector of years to be plotted. |
pal | Numeric or character string. Color palette identifier passed to |
rev | Boolean. Reverse the palette? Defaults to |
scale | Numeric scale factor passed to |
print | Boolean. Print plot? Defaults to |
Value
ggplot2 object representing multiple river hydrographs at once using the horizon plot approach
Examples
if (require("ggHoriPlot") && require("ggthemes")) { library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # horizon plot for selected years gr_plot_hori(sep, years = 1960:1980) }Runoff matrix plot
Description
The function plots runoff values, components and seasons using the matrix-based approach. The X axis corresponds to the day of the year, and the Y axis corresponds to the year. The function is useful when the whole picture of river runoff needs to be assessed.
Usage
gr_plot_matrix(df, years = NULL, type = "runoff", print = TRUE)Arguments
df |
|
years | Integer vector of years to be plotted. Defaults to |
type | Character string. Supported options are |
print | Boolean. Print plot? Defaults to |
Value
ggplot2 object representing the runoff values, components or seasons using the matrix-based approach
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# matrix plot for runoffgr_plot_matrix(sep, type = 'runoff')# matrix plot for seasonsgr_plot_matrix(sep, type = 'season')# matrix plot for genetic componentsgr_plot_matrix(sep, type = 'component')Plot minimum runoff month
Description
Generate a histogram of a minimum runoff month for two periods: before and after the change year set byyear parameter.
Usage
gr_plot_minmonth( df, year = NULL, exclude = NULL, tests = NULL, pagebreak = FALSE, print = TRUE)Arguments
df |
|
year | Integer. Change year value to separate two periods. |
exclude | Integer vector of years to be excluded from plotting. |
tests | Tests list for the same variables (generated by |
pagebreak | Logical. Whether to break page between plots (needed for reporting). Defaults to |
print | Boolean. Print plot? Defaults to |
Value
list of twoggplot2 objects, representing the histogram of a minimum runoff month for two periods: before and after the change year
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarize from 1965 to 1990vars = gr_summarize(sep, 1965, 1990)# plot minimum runoff month for two periods divided by Pettitt testgr_plot_minmonth(vars, tests = gr_test_vars(vars))# plot minimum runoff month for two periods divided by fixed yeargr_plot_minmonth(vars, year = 1978)Plot long-term hydrograph variable changes
Description
This function generates boxplots of the hydrograph separation variables produced bygr_summarize(). The data for each variable is divided into two samples: before and after the change year either set byyear parameter or extracted fromtests (statistically estimated). Different background fill colors are used to differentiate seasons types.
Usage
gr_plot_periods( df, ..., year = NULL, exclude = NULL, tests = NULL, layout = as.matrix(1), pagebreak = FALSE, print = TRUE)Arguments
df |
|
... | Quoted sequence of variable names. |
year | Integer. Change year value to separate two periods (overridden by tests if it is supplied). |
exclude | Integer vector of years to be excluded from plotting. |
tests | Tests list for the same variables (generated by |
layout |
|
pagebreak | Logical. Whether to break page between plots (needed for reporting). Defaults to |
print | Boolean. Print plot? Defaults to |
Value
list ofggplot2 objects, one for each variable, representing its long-term changes
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarize from 1965 to 1990vars = gr_summarize(sep, 1965, 1990)# plot periods with fixed change yeargr_plot_periods(vars, Qygr, year = 1978)# plot periods with change year from Pettitt testgr_plot_periods(vars, Qygr, tests = TRUE)# calculate test beforehandtests = gr_test_vars(vars)gr_plot_periods(vars, Qspmax, tests = tests)# use matrix layout to plot multiple variablesgr_plot_periods(vars, Qygr, Qspmax, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2), tests = tests)Ridgeline hydrograph plot
Description
A convenient wrapper aroundggridges::geom_ridgeline() to visualize multiple river hydrographs at once.
Usage
gr_plot_ridge( df, years, pal = 4, rev = FALSE, scale = 0.01, alpha = 0.8, print = TRUE)Arguments
df |
|
years | Integer vector of years to be plotted. |
pal | Numeric or character string. Color palette identifier passed to |
rev | Boolean. Reverse the palette? Defaults to |
scale | Numeric scale factor passed to |
alpha | Numeric opacity value of the ridgeline plot. Defaults to |
print | Boolean. Print plot? Defaults to |
Value
ggplot2 object representing the multiple river hydrographs at once using the ridgeline plot approach
Examples
if (require("ggridges")) { library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # ridgline plot for selected years gr_plot_ridge(sep, years = c(1960, 1965, 1989, 2001, 2012)) }Plot hydrograph separation
Description
The function plots river hydrograph by filling the different flow types using colors. Matrix layouts can be used if multiple plots are needed. Temperature and precipitation can be overlaid.
Usage
gr_plot_sep( df, years = NULL, layout = as.matrix(1), pagebreak = FALSE, temp = FALSE, prec = FALSE, span = 5, print = TRUE, yrange = "uniform")Arguments
df |
|
years | Integer vector of years to be plotted. |
layout |
|
pagebreak | Logical. Whether to break page between plots (used by |
temp | Boolean. Add temperature curve to the plot? Defaults to |
prec | Boolean. Add precipitation curve to the plot? Defaults to |
span | Integer number of days to accumulate precipitation for plotting. |
print | Boolean. Print plot? Defaults to |
yrange | Boolean. Y range for each plot. Defaults to |
Value
list ofggplot2 objects, one for each year, representing the hydrograph separation
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# One yeargr_plot_sep(sep, 1978) # Two yearsgr_plot_sep(sep, c(1978, 1989)) # Two years in a matrix layoutgr_plot_sep(sep, 1987:1988, layout = matrix(1:2, nrow = 2, byrow = TRUE)) # Four years in a matrix layout with free Y scalegr_plot_sep(sep, 1987:1990, layout = matrix(1:4, nrow = 2, byrow = TRUE), yrange = 'each') # Add temperature and precipitationgr_plot_sep(sep, 1991, temp = TRUE, prec = TRUE)Plot change year density
Description
The function extracts change years from results ofgr_test_vars() and plots their probability density. Since for every variable the change year is individual, this procedure allows finding the one most probable year, which is the mode of the distribution. This year is highlighted by the line and labeled on the plot.
Usage
gr_plot_tests(tests, type = "year", print = TRUE)Arguments
tests |
|
type | Character string type of the plot. Currently only |
print | Boolean. Print plot? Defaults to |
Value
ggplot2 object representing the selected type of the tested variable
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarize from 1965 to 1990vars = gr_summarize(sep, 1965, 1990)# test all variablestests = gr_test_vars(vars)# plot change year from Pettitt testgr_plot_tests(tests, type = 'year')Plot interannual hydrograph variable changes
Description
This function plots the hydrograph separation variables produced bygr_summarize(). Different background fill colors and line types are used to differentiate seasons and variable types.
Usage
gr_plot_vars( df, ..., tests = NULL, exclude = NULL, smooth = TRUE, layout = as.matrix(1), pagebreak = FALSE, print = TRUE)Arguments
df |
|
... | Quoted sequence of variable names. |
tests |
|
exclude | Integer vector of years to be excluded from plotting. |
smooth | Logical. If |
layout |
|
pagebreak | Logical. Whether to break page between plots ( |
print | Boolean. Print plot? Defaults to |
Value
list ofggplot2 objects, one for each variable, representing its interannual changes
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarize from 1965 to 1990vars = gr_summarize(sep, 1965, 1990)# plot one selected variablegr_plot_vars(vars, Qygr) # plot two variables sequentiallygr_plot_vars(vars, D10w1, Wsprngr)# four variables in matrix layout with tests calculated on the flygr_plot_vars(vars, Qspmax, Qygr, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2, byrow = TRUE), tests = TRUE)Read reanalysis data
Description
The function reads meteorological variables (temperature and precipitation) fromgrwat reanalysis for using withgr_join_rean(). Reanalysis covers the East European Plain with 0.75 degrees spatial resolution and is obtained based on CIRES-DOE (1880-1949) and ERA5 (1950-2021) data.
Usage
gr_read_rean(file_prec, file_temp)Arguments
file_prec | Character string path to precipitation NetCDF file. |
file_temp | Character string path to temperature NetCDF file. |
Details
Download the reanalysis archive fromhere.
Value
list containing time series, precipitation series, temperature seriesand spatial points (sf)
Examples
if (require("sf") && require("ncdf4")) { library(grwat) # read reanalysis data ## Not run: rean = gr_read_rean( '/Volumes/Data/Spatial/Reanalysis/grwat/pre_1880-2021.nc', '/Volumes/Data/Spatial/Reanalysis/grwat/temp_1880-2021.nc' ) str(rean) ## End(Not run) }Report hydrograph separation and variables
Description
This function generates a graphical HTML report that summarizes separation of hydrograph, its variables and their statistical properties. See examplereport generated by this command forspas dataset included in grwat package.
Usage
gr_report( sep, vars, output = "Report.html", year = NULL, exclude = NULL, temp = FALSE, prec = FALSE, span = 5, locale = "EN")Arguments
sep |
|
vars |
|
output | Character string path to the output file. Must have |
year | Integer value of year used to divide series in two samples compared by Student and Fisher tests. Defaults to |
exclude | Integer vector of years to be excluded from reporting. Defaults to |
temp | Boolean. Plot temperature on the top of hydrograph? Defaults to |
prec | Boolean. Plot precipitation on the top of hydrograph? Defaults to |
span | Integer number of days to accumulate precipitation for plotting. Defaults to |
locale | Character string locale. Currently only English ( |
Value
No return value, called for side effects
Examples
## Not run: if (require("knitr") && require("rmarkdown") && require("kableExtra")) { library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # summarize vars = gr_summarize(sep) # report report = '~/Spas-Zagorye.html' gr_report(sep, vars, output = report) browseURL(report) }## End(Not run)Advanced hydrograph separation
Description
Separates the runoff into genetic components: groundwater, thaw, rain and spring.
Usage
gr_separate(df, params = gr_get_params(), debug = FALSE)Arguments
df |
|
params |
|
debug | Boolean. If |
Value
Adata.frame with 11 columns:
| Column | Description |
Date | date |
Q | total runoff |
Temp | temperature |
Prec | precipitation |
Qbase | baseflow |
Quick | quickflow |
Qspri | spring flood |
Qrain | rain floods |
Qthaw | thaw floods |
Season | a season of the year |
Year | a water-resources year |
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat packagehead(spas)# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# Visualizegr_plot_sep(sep, c(1978, 1989)) # Debug mode gives access to additional informationsep_debug = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE)# a vector of years with jittered paramsjit = attributes(sep_debug)$jitteredprint(jit)# actual params used for each yearparlist = attributes(sep_debug)$params# tabular representation of parameterspartab = gr_to_pardf(parlist)head(partab)parlist2 = partab |> dplyr::select(-year) |> apply(1, as.list) |> lapply(\(X) { n = length(X) X[1:(n - 1)] <- lapply(X[1:(n - 1)], as.numeric) return(X) }) |> setNames(partab$year)# extract and tweak parameters for selected yearp = parlist[['1989']]p$grad1 = 1p$grad2 = 2.5# use tweaked parameters for all yearssep_debug = gr_separate(spas, params = p, debug = TRUE)# Visualizegr_plot_sep(sep_debug, c(1978, 1989)) # actual params used for each yearparlist = attributes(sep_debug)$params# tweak parameters for selected yearparlist[['1989']]$grad1 = 3parlist[['1989']]$grad2 = 6# set the sprecdays parameter for multiple yearsparlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15)# set the spcomp parameter for all yearsparlist = gr_set_param(parlist, spcomp, value = 2.5)# use the list of parameters for separationsep_debug = gr_separate(spas, params = parlist, debug = TRUE)# Visualizegr_plot_sep(sep_debug, c(1978, 1989))Set the language that is used for plotting
Description
Run this function once at the beginning of the session. All plots will be labeled using the selected language.
Usage
gr_set_locale(locale = "EN")Arguments
locale | Character string locale. Currently only English ( |
Details
Note to Linux users: the desired locale may not be installed on the system. A list of available locales can be obtained in bash terminal:
locale -a
Russian locale isru_RU.UTF-8, and Ukrainian locale isuk_UA.UTF-8. If absent in the list, then install the desired locales by:
sudo locale-gen ru_RU.UTF-8
sudo locale-gen uk_UA.UTF-8
sudo update-locale
Then restart R session, and localization should work as expected.
Value
No return value, called for side effects
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# Default is Englishgr_set_locale('EN')gr_plot_sep(sep, 1978)Set the value of hydrograph separation parameter
Description
The value is set for selected years in parameter list. Such list is returned bygr_separate() withdebug = TRUE set.
Usage
gr_set_param(params, p, value, years = NULL)Arguments
params |
|
p | Name of the parameter. |
value | Numeric value to set. |
years | Integer vector of years to modify. Defaults to |
Value
list oflists — a modified version ofparams
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# Debug mode gives access to additional informationsep = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE)# Visualizegr_plot_sep(sep, c(1978, 1989)) # actual params used for each yearparlist = attributes(sep)$params# set the sprecdays parameter for multiple yearsparlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15)# use the list of parameters for separationsep_new = gr_separate(spas, params = parlist, debug = TRUE)# Visualizegr_plot_sep(sep_new, c(1978, 1989))Summarize hydrograph separation
Description
Use this function to get meaningful summary statistics for hydrograph separation. Resulting variables are described bygr_help_vars(). This function is a convenient wrapper arounddplyr'sdf |> group_by |> summarize idiom.
Usage
gr_summarize(df, year_min = NULL, year_max = NULL)Arguments
df |
|
year_min |
|
year_max |
|
Value
data.frame with one row for each water-resources year and multiple columns of statistics explained bygr_help_vars().
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarizevars = gr_summarize(sep)head(vars)gr_plot_vars(vars, Qygr, tests = TRUE)Test hydrograph changes
Description
Use this function to test interannual changes or hydrograph separation variables returned bygr_summarize(). Pettitt test is used to detect the change year — i.e. the year which divides the time series into the statistically most differing samples. Student (Welch) and Fisher tests are used to estimate the significance of mean and variance differences of these samples. Theil-Sen test calculates the trend slope value. Mann-Kendall test is performed to reveal the significance of the trend.
Usage
gr_test_vars(df, ..., year = NULL, exclude = NULL)Arguments
df |
|
... | Names of the tested variables (quoted). |
year | Integer value of year used to divide series in two samples compared by Student and Fisher tests. Defaults to |
exclude | Integer vector of years to be excluded from tests. |
Details
Number of observations formally required for various tests: Pettitt > 0, Mann-Kendall > 2, Theil-Sen > 1, Student > 1, Fisher > 1.
Value
list of testing results with following elements:
| Element | Description |
ptt | Pettitt tests for change year |
mkt | Mann-Kendall test for trend significance |
tst | Theil-Sen test for slope estimation |
ts_fit | Theil-Sen linear model fit |
tt | Student (Welch) test for significance of mean differences between two periods |
ft | Fisher test for significance of variance differences between two periods |
year | Integer value of year used to divide series in two samples compared by Student and Fisher tests |
maxval | Maximum value for the variable along the full time series |
fixed_year | BooleanTRUE orFALSE value indicating if the year was fixed |
pvalues | p-values of all tests summarized as a single table for all variables |
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat package# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# summarize from 1965 to 1990vars = gr_summarize(sep, 1965, 1990)# test all variablestests = gr_test_vars(vars)# view Pettitt test for Qygrtests$ptt$Qygr# view Fisher test for Q30stests$ft$Q30s# test only Qygr and Q30s using 1978 as fixed year and excluding 1988-1991 yrsgr_test_vars(vars, Qygr, Q30s, year = 1978, exclude = 1981:1983)Convert list of parameters to data frame
Description
Convert list of parameters to data frame
Usage
gr_to_pardf(params)Arguments
params |
|
Value
tibble data frame with tabular representation of hydrograph separation parameters
Examples
library(grwat)data(spas) # example Spas-Zagorye data is included with grwat packagehead(spas)# separatesep = gr_separate(spas, params = gr_get_params(reg = 'center'))# Visualizegr_plot_sep(sep, c(1978, 1989)) # Debug mode gives access to additional informationsep_debug = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE)# a vector of years with jittered paramsjit = attributes(sep_debug)$jitteredprint(jit)# actual params used for each yearparlist = attributes(sep_debug)$params# tweak parameters for selected yearparlist[['1989']]$grad1 = 3parlist[['1989']]$grad2 = 6# tabular representation of parameterspartab = gr_to_pardf(parlist)head(partab)partab |> dplyr::filter(year == 1989) |> head()Spas-Zagorye daily runoff data
Description
A dataset containing the daily runoff data forSpas-Zagorye gauge onProtva river in Central European plane. The dataset is supplemented by meteorological variables (temperature and precipitation) obtained from CIRES-DOE (1880-1949) and ERA5 (1950-2021) data.
Usage
spasFormat
A data frame with 23742 rows and 4 variables:
- Date
date, in dates
- Q
daily runoff, in m3/s
- Temp
daily temperature, in Celsius degrees
- Prec
daily precipitation, in mm
Source
https://allrivers.info/gauge/protva-obninsk
https://www.ecmwf.int/en/forecasts/dataset/ecmwf-reanalysis-v5