Title: | River Hydrograph Separation and Analysis |
---|---|
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. |
Authors: | Timofey Samsonov [aut, cre] , Ekaterina Rets [ctb] , Maria Kireeva [ctb] |
Maintainer: | Timofey Samsonov <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.4.9000 |
Built: | 2024-11-18 04:10:02 UTC |
Source: | https://github.com/tsamsonov/grwat |
Extract baseflow from hydrological series using the filtering approach
gr_baseflow( Q, a = 0.925, k = 0.975, C = 0.05, aq = -0.5, passes = 3, padding = 30, method = "lynehollick" )
gr_baseflow( Q, a = 0.925, k = 0.975, C = 0.05, aq = -0.5, passes = 3, padding = 30, method = "lynehollick" )
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 |
Numeric baseflow vector with length equal to Q
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 approach hdata = spas %>% mutate(Qbase = gr_baseflow(Q, method = 'lynehollick', a = 0.925, passes = 3)) # Visualize for 1980 year ggplot(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 approaches hdata = 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 year ggplot(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 Kudelin p = 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 year ggplot(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)
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 approach hdata = spas %>% mutate(Qbase = gr_baseflow(Q, method = 'lynehollick', a = 0.925, passes = 3)) # Visualize for 1980 year ggplot(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 approaches hdata = 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 year ggplot(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 Kudelin p = 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 year ggplot(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)
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)
gr_buffer_geo(g, bufsize)
gr_buffer_geo(g, bufsize)
g |
|
bufsize |
Numeric value of a buffer distance, in meters. |
sf
or sfg
object, buffered to bufsize
and projected into geographic coordinates (WGS84).
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') }
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') }
This function is called inside gr_separate()
, but can be used explicitly inside your code.
gr_check_data(df)
gr_check_data(df)
df |
|
stops execution if df
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).
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) head(spas) gr_check_data(spas) # raw Spas-Zagorye data represents date components # in columns and does not contain meteorologgical variables path = 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))
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) head(spas) gr_check_data(spas) # raw Spas-Zagorye data represents date components # in columns and does not contain meteorologgical variables path = 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
gr_check_params(params, df = NULL)
gr_check_params(params, df = NULL)
params |
|
df |
|
stops the execution if anything is wrong and prints the exact reason of the error. Otherwise prints the message that everything is OK
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) params = gr_get_params(reg = 'center') gr_check_params(params) # set the unknown parameter params$new = -2 # use try if you do not want to stop at error try(gr_check_params(params)) # remove wrong parameter params$new = NULL # remove right parameter params$grad1 = NULL try(gr_check_params(params)) # reset params = gr_get_params(reg = 'center') sep = gr_separate(spas, params, debug = TRUE) parlist = attributes(sep)$params parlist[['2002']]$grad1 = 4 # if the parlist is used for separation # then data frame must be specified try(gr_check_params(parlist)) gr_check_params(parlist, spas) # grad parameter is not known parlist[['2002']]$grad = 4 try(gr_check_params(parlist, spas)) # remove wrong parameter parlist[['2002']]$grad = NULL # remove year parlist[['2002']] = NULL try(gr_check_params(parlist, spas)) parlist[['2002']] = parlist[['2001']] gr_check_params(parlist, spas)
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) params = gr_get_params(reg = 'center') gr_check_params(params) # set the unknown parameter params$new = -2 # use try if you do not want to stop at error try(gr_check_params(params)) # remove wrong parameter params$new = NULL # remove right parameter params$grad1 = NULL try(gr_check_params(params)) # reset params = gr_get_params(reg = 'center') sep = gr_separate(spas, params, debug = TRUE) parlist = attributes(sep)$params parlist[['2002']]$grad1 = 4 # if the parlist is used for separation # then data frame must be specified try(gr_check_params(parlist)) gr_check_params(parlist, spas) # grad parameter is not known parlist[['2002']]$grad = 4 try(gr_check_params(parlist, spas)) # remove wrong parameter parlist[['2002']]$grad = NULL # remove year parlist[['2002']] = NULL try(gr_check_params(parlist, spas)) parlist[['2002']] = parlist[['2001']] gr_check_params(parlist, spas)
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 by gr_get_gaps()
gr_fill_gaps(hdata, autocorr = 0.7, nobserv = NULL)
gr_fill_gaps(hdata, autocorr = 0.7, nobserv = NULL)
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 |
data.frame
which is a filled version of hdata
library(grwat) library(dplyr) # example Spas-Zagorye data is included with grwat package path = 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 gaps gr_get_gaps(hdata) # fill gaps fhdata = gr_fill_gaps(hdata, autocorr = 0.8) # check the results gr_get_gaps(fhdata) # fill gaps fhdata = gr_fill_gaps(hdata, nobserv = 7) # check the results gr_get_gaps(fhdata)
library(grwat) library(dplyr) # example Spas-Zagorye data is included with grwat package path = 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 gaps gr_get_gaps(hdata) # fill gaps fhdata = gr_fill_gaps(hdata, autocorr = 0.8) # check the results gr_get_gaps(fhdata) # fill gaps fhdata = gr_fill_gaps(hdata, nobserv = 7) # check the results gr_get_gaps(fhdata)
Use the function to detect periods of missing data. The first column must be of Date
type. The data is considered to be a gap if any value in the row is missing.
gr_get_gaps(hdata)
gr_get_gaps(hdata)
hdata |
|
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).
library(grwat) library(dplyr) # example Spas-Zagorye data is included with grwat package path = 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 gaps gr_get_gaps(hdata) # fill gaps fhdata = gr_fill_gaps(hdata, autocorr = 0.8) # check the results gr_get_gaps(fhdata) # fill gaps fhdata = gr_fill_gaps(hdata, nobserv = 7) # check the results gr_get_gaps(fhdata)
library(grwat) library(dplyr) # example Spas-Zagorye data is included with grwat package path = 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 gaps gr_get_gaps(hdata) # fill gaps fhdata = gr_fill_gaps(hdata, autocorr = 0.8) # check the results gr_get_gaps(fhdata) # fill gaps fhdata = gr_fill_gaps(hdata, nobserv = 7) # check the results gr_get_gaps(fhdata)
The function returns the list of parameters that can be used by gr_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
gr_get_params(reg = "center", lon = NULL, lat = NULL)
gr_get_params(reg = "center", lon = NULL, lat = NULL)
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 |
List of separation parameters that can be used in gr_separate()
function.
library(grwat) params = gr_get_params(reg = 'center') print(params)
library(grwat) params = gr_get_params(reg = 'center') print(params)
Get the information about parameters used to separate the hydrograph
gr_help_params()
gr_help_params()
data.frame
with description of hydrograph separation parameters that are used in gr_separate()
.
library(grwat) gr_help_params()
library(grwat) gr_help_params()
Use this function to learn the meaning of the variables that are calculated by gr_summarize()
.
gr_help_vars()
gr_help_vars()
data.frame
of hydrograph separation variables
library(grwat) gr_help_vars()
library(grwat) gr_help_vars()
The function performs spatial join of meteorological variables (temperature and precipitation) from grwat 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.
gr_join_rean(hdata, rean, buffer)
gr_join_rean(hdata, rean, buffer)
hdata |
|
rean |
|
buffer |
|
Download the reanalysis archive from here.
data.frame
with four columns: date, runoff, temperature, precipitation.
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) }
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) }
This function is used to represent the results of gr_test_vars()
in a tabular form. Used mainly in gr_report()
, but can be used for your own purposes.
gr_kable_tests(tests, format = "html")
gr_kable_tests(tests, format = "html")
tests |
|
format |
Character string encoding the type of output. Currently |
HTML table as returned by knitr::kable()
function.
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) }
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) }
The function plots the autocorrelation function (ACF) for daily runoff time series. A number of days corresponding to the specified autocorr
value is highlighted.
gr_plot_acf(hdata, autocorr = 0.7, maxlag = 30, print = TRUE)
gr_plot_acf(hdata, autocorr = 0.7, maxlag = 30, print = TRUE)
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 |
ggplot2
object representing the autocorrelation function (ACF) for daily runoff time series
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) head(spas) # plot ACF gr_plot_acf(spas, 0.65)
library(grwat) # example Spas-Zagorye data is included with grwat package data(spas) head(spas) # plot ACF gr_plot_acf(spas, 0.65)
A convenient wrapper around ggHoriPlot::geom_horizon()
to visualize multiple river hydrographs at once.
gr_plot_hori(df, years, pal = "Blues", rev = TRUE, scale = 6, print = TRUE)
gr_plot_hori(df, years, pal = "Blues", rev = TRUE, scale = 6, print = TRUE)
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 |
ggplot2
object representing multiple river hydrographs at once using the horizon plot approach
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) }
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) }
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.
gr_plot_matrix(df, years = NULL, type = "runoff", print = TRUE)
gr_plot_matrix(df, years = NULL, type = "runoff", print = TRUE)
df |
|
years |
Integer vector of years to be plotted. Defaults to |
type |
Character string. Supported options are |
print |
Boolean. Print plot? Defaults to |
ggplot2
object representing the runoff values, components or seasons using the matrix-based approach
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # matrix plot for runoff gr_plot_matrix(sep, type = 'runoff') # matrix plot for seasons gr_plot_matrix(sep, type = 'season') # matrix plot for genetic components gr_plot_matrix(sep, type = 'component')
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # matrix plot for runoff gr_plot_matrix(sep, type = 'runoff') # matrix plot for seasons gr_plot_matrix(sep, type = 'season') # matrix plot for genetic components gr_plot_matrix(sep, type = 'component')
Generate a histogram of a minimum runoff month for two periods: before and after the change year set by year
parameter.
gr_plot_minmonth( df, year = NULL, exclude = NULL, tests = NULL, pagebreak = FALSE, print = TRUE )
gr_plot_minmonth( df, year = NULL, exclude = NULL, tests = NULL, pagebreak = FALSE, print = TRUE )
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 |
list
of two ggplot2
objects, representing the histogram of a minimum runoff month for two periods: before and after the change year
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) # plot minimum runoff month for two periods divided by Pettitt test gr_plot_minmonth(vars, tests = gr_test_vars(vars)) # plot minimum runoff month for two periods divided by fixed year gr_plot_minmonth(vars, year = 1978)
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) # plot minimum runoff month for two periods divided by Pettitt test gr_plot_minmonth(vars, tests = gr_test_vars(vars)) # plot minimum runoff month for two periods divided by fixed year gr_plot_minmonth(vars, year = 1978)
This function generates boxplots of the hydrograph separation variables produced by gr_summarize()
. The data for each variable is divided into two samples: before and after the change year either set by year
parameter or extracted from tests
(statistically estimated). Different background fill colors are used to differentiate seasons types.
gr_plot_periods( df, ..., year = NULL, exclude = NULL, tests = NULL, layout = as.matrix(1), pagebreak = FALSE, print = TRUE )
gr_plot_periods( df, ..., year = NULL, exclude = NULL, tests = NULL, layout = as.matrix(1), pagebreak = FALSE, print = TRUE )
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 |
list
of ggplot2
objects, one for each variable, representing its long-term changes
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) # plot periods with fixed change year gr_plot_periods(vars, Qygr, year = 1978) # plot periods with change year from Pettitt test gr_plot_periods(vars, Qygr, tests = TRUE) # calculate test beforehand tests = gr_test_vars(vars) gr_plot_periods(vars, Qspmax, tests = tests) # use matrix layout to plot multiple variables gr_plot_periods(vars, Qygr, Qspmax, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2), tests = tests)
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) # plot periods with fixed change year gr_plot_periods(vars, Qygr, year = 1978) # plot periods with change year from Pettitt test gr_plot_periods(vars, Qygr, tests = TRUE) # calculate test beforehand tests = gr_test_vars(vars) gr_plot_periods(vars, Qspmax, tests = tests) # use matrix layout to plot multiple variables gr_plot_periods(vars, Qygr, Qspmax, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2), tests = tests)
A convenient wrapper around ggridges::geom_ridgeline()
to visualize multiple river hydrographs at once.
gr_plot_ridge( df, years, pal = 4, rev = FALSE, scale = 0.01, alpha = 0.8, print = TRUE )
gr_plot_ridge( df, years, pal = 4, rev = FALSE, scale = 0.01, alpha = 0.8, print = TRUE )
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 |
ggplot2
object representing the multiple river hydrographs at once using the ridgeline plot approach
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)) }
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)) }
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.
gr_plot_sep( df, years = NULL, layout = as.matrix(1), pagebreak = FALSE, temp = FALSE, prec = FALSE, span = 5, print = TRUE )
gr_plot_sep( df, years = NULL, layout = as.matrix(1), pagebreak = FALSE, temp = FALSE, prec = FALSE, span = 5, print = TRUE )
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 |
list
of ggplot2
objects, one for each year, representing the hydrograph separation
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # One year gr_plot_sep(sep, 1978) # Two years gr_plot_sep(sep, c(1978, 1989)) # Two years in a matrix layout gr_plot_sep(sep, 1988:1989, layout = matrix(1:2, nrow = 2, byrow = TRUE)) # Add temperature and precipitation gr_plot_sep(sep, 1991, temp = TRUE, prec = TRUE)
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # One year gr_plot_sep(sep, 1978) # Two years gr_plot_sep(sep, c(1978, 1989)) # Two years in a matrix layout gr_plot_sep(sep, 1988:1989, layout = matrix(1:2, nrow = 2, byrow = TRUE)) # Add temperature and precipitation gr_plot_sep(sep, 1991, temp = TRUE, prec = TRUE)
The function extracts change years from results of gr_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.
gr_plot_tests(tests, type = "year", print = TRUE)
gr_plot_tests(tests, type = "year", print = TRUE)
tests |
|
type |
Character string type of the plot. Currently only |
print |
Boolean. Print plot? Defaults to |
ggplot2
object representing the selected type of the tested variable
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) # plot change year from Pettitt test gr_plot_tests(tests, type = 'year')
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) # plot change year from Pettitt test gr_plot_tests(tests, type = 'year')
This function plots the hydrograph separation variables produced by gr_summarize()
. Different background fill colors and line types are used to differentiate seasons and variable types.
gr_plot_vars( df, ..., tests = NULL, exclude = NULL, smooth = TRUE, layout = as.matrix(1), pagebreak = FALSE, print = TRUE )
gr_plot_vars( df, ..., tests = NULL, exclude = NULL, smooth = TRUE, layout = as.matrix(1), pagebreak = FALSE, print = TRUE )
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 |
list
of ggplot2
objects, one for each variable, representing its interannual changes
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) # plot one selected variable gr_plot_vars(vars, Qygr) # plot two variables sequentially gr_plot_vars(vars, D10w1, Wsprngr) # four variables in matrix layout with tests calculated on the fly gr_plot_vars(vars, Qspmax, Qygr, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2, byrow = TRUE), tests = TRUE)
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) # plot one selected variable gr_plot_vars(vars, Qygr) # plot two variables sequentially gr_plot_vars(vars, D10w1, Wsprngr) # four variables in matrix layout with tests calculated on the fly gr_plot_vars(vars, Qspmax, Qygr, D10w1, Wsprngr, layout = matrix(1:4, nrow = 2, byrow = TRUE), tests = TRUE)
The function reads meteorological variables (temperature and precipitation) from grwat reanalysis for using with gr_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.
gr_read_rean(file_prec, file_temp)
gr_read_rean(file_prec, file_temp)
file_prec |
Character string path to precipitation NetCDF file. |
file_temp |
Character string path to temperature NetCDF file. |
Download the reanalysis archive from here.
list
containing time series, precipitation series, temperature series
and spatial points (sf)
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) }
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) }
This function generates a graphical HTML report that summarizes separation of hydrograph, its variables and their statistical properties. See example report generated by this command for spas
dataset included in grwat package.
gr_report( sep, vars, output = "Report.html", year = NULL, exclude = NULL, temp = FALSE, prec = FALSE, span = 5, locale = "EN" )
gr_report( sep, vars, output = "Report.html", year = NULL, exclude = NULL, temp = FALSE, prec = FALSE, span = 5, locale = "EN" )
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 ( |
No return value, called for side effects
## 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)
## 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)
Separates the runoff into genetic components: groundwater, thaw, rain and spring.
gr_separate(df, params = gr_get_params(), debug = FALSE)
gr_separate(df, params = gr_get_params(), debug = FALSE)
df |
|
params |
|
debug |
Boolean. If |
A data.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 |
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package head(spas) # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # Visualize gr_plot_sep(sep, c(1978, 1989)) # Debug mode gives access to additional information sep_debug = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE) # a vector of years with jittered params jit = attributes(sep_debug)$jittered print(jit) # actual params used for each year parlist = attributes(sep_debug)$params partab = do.call(dplyr::bind_rows, parlist) # View as table head(partab) # extract and tweak parameters for selected year p = parlist[['1989']] p$grad1 = 1 p$grad2 = 2.5 # use tweaked parameters for all years sep_debug = gr_separate(spas, params = p, debug = TRUE) # Visualize gr_plot_sep(sep_debug, c(1978, 1989)) # actual params used for each year parlist = attributes(sep_debug)$params # tweak parameters for selected year parlist[['1989']]$grad1 = 3 parlist[['1989']]$grad2 = 6 # set the sprecdays parameter for multiple years parlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15) # set the spcomp parameter for all years parlist = gr_set_param(parlist, spcomp, value = 2.5) # use the list of parameters for separation sep_debug = gr_separate(spas, params = parlist, debug = TRUE) # Visualize gr_plot_sep(sep_debug, c(1978, 1989))
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package head(spas) # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # Visualize gr_plot_sep(sep, c(1978, 1989)) # Debug mode gives access to additional information sep_debug = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE) # a vector of years with jittered params jit = attributes(sep_debug)$jittered print(jit) # actual params used for each year parlist = attributes(sep_debug)$params partab = do.call(dplyr::bind_rows, parlist) # View as table head(partab) # extract and tweak parameters for selected year p = parlist[['1989']] p$grad1 = 1 p$grad2 = 2.5 # use tweaked parameters for all years sep_debug = gr_separate(spas, params = p, debug = TRUE) # Visualize gr_plot_sep(sep_debug, c(1978, 1989)) # actual params used for each year parlist = attributes(sep_debug)$params # tweak parameters for selected year parlist[['1989']]$grad1 = 3 parlist[['1989']]$grad2 = 6 # set the sprecdays parameter for multiple years parlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15) # set the spcomp parameter for all years parlist = gr_set_param(parlist, spcomp, value = 2.5) # use the list of parameters for separation sep_debug = gr_separate(spas, params = parlist, debug = TRUE) # Visualize gr_plot_sep(sep_debug, c(1978, 1989))
Run this function once at the beginning of the session. All plots will be labeled using the selected language.
gr_set_locale(locale = "EN")
gr_set_locale(locale = "EN")
locale |
Character string locale. Currently only English ( |
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 is ru_RU.UTF-8
, and Ukrainian locale is uk_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.
No return value, called for side effects
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # Default is English gr_set_locale('EN') gr_plot_sep(sep, 1978)
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # separate sep = gr_separate(spas, params = gr_get_params(reg = 'center')) # Default is English gr_set_locale('EN') gr_plot_sep(sep, 1978)
The value is set for selected years in parameter list. Such list is returned by gr_separate()
with debug = TRUE
set.
gr_set_param(params, p, value, years = NULL)
gr_set_param(params, p, value, years = NULL)
params |
|
p |
Name of the parameter. |
value |
Numeric value to set. |
years |
Integer vector of years to modify. Defaults to |
list
of list
s — a modified version of params
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # Debug mode gives access to additional information sep = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE) # Visualize gr_plot_sep(sep, c(1978, 1989)) # actual params used for each year parlist = attributes(sep)$params # set the sprecdays parameter for multiple years parlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15) # use the list of parameters for separation sep_new = gr_separate(spas, params = parlist, debug = TRUE) # Visualize gr_plot_sep(sep_new, c(1978, 1989))
library(grwat) data(spas) # example Spas-Zagorye data is included with grwat package # Debug mode gives access to additional information sep = gr_separate(spas, params = gr_get_params(reg = 'center'), debug = TRUE) # Visualize gr_plot_sep(sep, c(1978, 1989)) # actual params used for each year parlist = attributes(sep)$params # set the sprecdays parameter for multiple years parlist = gr_set_param(parlist, sprecdays, years = c(1978, 1989:1995), value = 15) # use the list of parameters for separation sep_new = gr_separate(spas, params = parlist, debug = TRUE) # Visualize gr_plot_sep(sep_new, c(1978, 1989))
Use this function to get meaningful summary statistics for hydrograph separation. Resulting variables are described by gr_help_vars()
. This function is a convenient wrapper around dplyr's df %>% group_by %>% summarize
idiom.
gr_summarize(df, year_min = NULL, year_max = NULL)
gr_summarize(df, year_min = NULL, year_max = NULL)
df |
|
year_min |
|
year_max |
|
data.frame
with one row for each water-resources year and multiple columns of statistics explained by gr_help_vars()
.
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) head(vars) gr_plot_vars(vars, Qygr, tests = TRUE)
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) head(vars) gr_plot_vars(vars, Qygr, tests = TRUE)
Use this function to test interannual changes or hydrograph separation variables returned by gr_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.
gr_test_vars(df, ..., year = NULL, exclude = NULL)
gr_test_vars(df, ..., year = NULL, exclude = NULL)
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. |
Number of observations formally required for various tests: Pettitt > 0, Mann-Kendall > 2, Theil-Sen > 1, Student > 1, Fisher > 1.
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 |
Boolean TRUE or FALSE value indicating if the year was fixed |
pvalues |
p-values of all tests summarized as a single table for all variables |
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) # view Pettitt test for Qygr tests$ptt$Qygr # view Fisher test for Q30s tests$ft$Q30s # test only Qygr and Q30s using 1978 as fixed year and excluding 1988-1991 yrs gr_test_vars(vars, Qygr, Q30s, year = 1978, exclude = 1981:1983)
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) # view Pettitt test for Qygr tests$ptt$Qygr # view Fisher test for Q30s tests$ft$Q30s # test only Qygr and Q30s using 1978 as fixed year and excluding 1988-1991 yrs gr_test_vars(vars, Qygr, Q30s, year = 1978, exclude = 1981:1983)
A dataset containing the daily runoff data for Spas-Zagorye gauge on Protva 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.
spas
spas
A data frame with 23742 rows and 4 variables:
date, in dates
daily runoff, in m3/s
daily temperature, in Celsius degrees
daily precipitation, in mm
https://allrivers.info/gauge/protva-obninsk
https://www.ecmwf.int/en/forecasts/dataset/ecmwf-reanalysis-v5
https://psl.noaa.gov/data/gridded/data.20thC_ReanV3.html