Title: | An R package for Computing Robust, Mass Preserving Hydraulic Geometries and Rating Curves |
---|---|
Description: | Compute mass preserving 'At a station Hydraulic Geometry' (AHG) fits from river measurements. |
Authors: | Mike Johnson [aut, cre] , Arash Modaresi Rad [ctb] , NOAA OWP [fnd], NSF [fnd] |
Maintainer: | Mike Johnson <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.3.1 |
Built: | 2024-12-05 23:23:05 UTC |
Source: | https://github.com/mikejohnson51/AHGestimation |
Properly estimate AHG values
ahg_estimate( df, allowance = 0.05, gen = 192, pop = 200, cprob = 0.4, mprob = 0.4, times = 1, scale = 1.5, full_fitting = FALSE, verbose = FALSE )
ahg_estimate( df, allowance = 0.05, gen = 192, pop = 200, cprob = 0.4, mprob = 0.4, times = 1, scale = 1.5, full_fitting = FALSE, verbose = FALSE )
df |
hydraulic data.frame with columns named (Q, V, TW, Y). Q and at least one other are required. |
allowance |
allowed deviation from continuity |
gen |
Number of generations to breed. |
pop |
Size of population |
cprob |
Crossover probability |
mprob |
Mutation probability |
times |
how many times (seeds) should nsga2 be run |
scale |
should a scale factor be applied to data pre NSGA-2 fitting |
full_fitting |
should all fits be returned? |
verbose |
should messages be emitted? |
list
Other AHG:
best_optimal()
,
calc_nsga()
,
compute_ahg()
,
min_max()
,
mismash()
Report best optimal
best_optimal(best, check, verbose = TRUE)
best_optimal(best, check, verbose = TRUE)
best |
best performing method (character string) |
check |
values to check against |
verbose |
should messages be emitted |
vector
Other AHG:
ahg_estimate()
,
calc_nsga()
,
compute_ahg()
,
min_max()
,
mismash()
Calculate NSGA2 AHG
calc_nsga( df, allowance = 0.05, r, scale = 2, gen = 96, pop = 500, cprob = 0.8, mprob = 0.05, times = 1 )
calc_nsga( df, allowance = 0.05, r, scale = 2, gen = 96, pop = 500, cprob = 0.8, mprob = 0.05, times = 1 )
df |
hydraulic data.frame |
allowance |
allowable deviation from continuity |
r |
fit list |
scale |
should a scale factor be applied to data pre NSGA-2 fitting |
gen |
Number of generations to breed. |
pop |
Size of population |
cprob |
Crossover probability |
mprob |
Mutation probability |
times |
how many times (seeds) should nsga2 be run |
data.frame
Other AHG:
ahg_estimate()
,
best_optimal()
,
compute_ahg()
,
min_max()
,
mismash()
Approximate AHG relationships using both OLS and NLS methods
compute_ahg(Q, P, type = "relation")
compute_ahg(Q, P, type = "relation")
Q |
a stream flow time series |
P |
a corresponding time series of a second hydraulic variable |
type |
relationship being tested |
data.frame
Other AHG:
ahg_estimate()
,
best_optimal()
,
calc_nsga()
,
min_max()
,
mismash()
Given a sf object with 'XYZ' coordinates, return a vector of numeric values representing the average slope of each linestring in the sf data frame input.
The default calculates the slope using 'slope_weighted()'. You can also use 'slope_mean()' or any other function that takes the same inputs as these functions.
compute_channel_slope(path, fun = slope_weighted, directed = FALSE)
compute_channel_slope(path, fun = slope_weighted, directed = FALSE)
path |
an XYZ LINESTRING representing the path of travel |
fun |
The slope function to calculate per element, 'slope_weighted' is the default. |
directed |
Should the value be directed? 'FALSE' by default. If 'TRUE' the result will be negative when it represents a downslope (when the end point is lower than the start point). |
A vector of slopes associated with each linear element The value is a proportion representing the change in elevation for a given change in horizontal distance.
Other hydraulics:
compute_hydraulic_params()
,
compute_n()
,
cross_section()
,
extract_thalweg()
,
slope_matrix()
Approximate the hydraulic values from AHG fit
compute_hydraulic_params(fit)
compute_hydraulic_params(fit)
fit |
output of ahg_estimate |
numeric
Other hydraulics:
compute_channel_slope()
,
compute_n()
,
cross_section()
,
extract_thalweg()
,
slope_matrix()
Approximate median roughness using Manning Equation
compute_n(df, S = 0.02)
compute_n(df, S = 0.02)
df |
a data.frame with at least Y and V. |
S |
reach scale longitudinal slope (m/m). Default mean of the nhdplusV2 |
numeric
Other hydraulics:
compute_channel_slope()
,
compute_hydraulic_params()
,
cross_section()
,
extract_thalweg()
,
slope_matrix()
Get a list of points from x axis of a cross section and max depth and produce depth values for those points based on channel shape
cross_section(r, TW = 30, Ymax = 2, n = 30)
cross_section(r, TW = 30, Ymax = 2, n = 30)
r |
The corresponding Dingman's r coefficient |
TW |
width of the channel at bankfull |
Ymax |
maximum depth of the channel at bankfull |
n |
the number of points to construct in the XS |
depth values every 1m along the cross section
Other hydraulics:
compute_channel_slope()
,
compute_hydraulic_params()
,
compute_n()
,
extract_thalweg()
,
slope_matrix()
Data is filtered when it is beyond a specified year threshold (e.g. 5 years old). The relative date is based on the newest observation in the data set. Optionally, the maximum flow (Q) record can be retained.
date_filter(df, years, keep_max = FALSE)
date_filter(df, years, keep_max = FALSE)
df |
a data.frame with at least a date and Q field. |
years |
the number of allowed history |
keep_max |
Should the largest flow record be kept, even if older then "years" |
data.frame
Other filters:
mad_filter()
,
nls_filter()
,
qva_filter()
,
significance_check()
Extract Thalweg From a data.frame of cross sections, a classified thalweg can be extracted as the connected LINESTRING
extract_thalweg(xs, crs = 5070)
extract_thalweg(xs, crs = 5070)
xs |
a data.frame containing cross sectional data. Required columns are hf_id, cs_id, X, Y, Z |
crs |
the CRS of the XY coordinates |
XYZ LINESTRING object
Other hydraulics:
compute_channel_slope()
,
compute_hydraulic_params()
,
compute_n()
,
cross_section()
,
slope_matrix()
An iterative outlier detection procedure is run based on to the linear regression residuals. Values of log-transformed TW, V, and Y residuals falling outside a specified median absolute deviation (MAD) envelope are excluded. Regression coefficients were recalculated and the outlier detection procedure was reapplied until no outliers are detected. This method was identified in HyG
mad_filter(df, envelope = 3)
mad_filter(df, envelope = 3)
df |
a data.frame with at least a Q and one other AHG field (Y. TW, V). |
envelope |
MAD envelope |
data.frame
Other filters:
date_filter()
,
nls_filter()
,
qva_filter()
,
significance_check()
Find thresholds for coefficient and exponent limits.
min_max(df, scale = 2)
min_max(df, scale = 2)
df |
hydraulic data.frame |
scale |
Scale by set factor. This limits the exponent at coefficients to the range of (1/s) * nls; s * nls |
list
Other AHG:
ahg_estimate()
,
best_optimal()
,
calc_nsga()
,
compute_ahg()
,
mismash()
Compute all combos!
mismash(v, V, TW, Y, Q, r, allowance)
mismash(v, V, TW, Y, Q, r, allowance)
v |
values |
V |
Velocity time series |
TW |
Top width time series |
Y |
Depth time series |
Q |
Discharge time series |
r |
rrr TODO |
allowance |
Allowable deviation from continuity |
list
Other AHG:
ahg_estimate()
,
best_optimal()
,
calc_nsga()
,
compute_ahg()
,
min_max()
An NLS fit provides the best relation by relation fit. For each provided relationship, an NLS fit is computed and used to estimate the predicted V,TW,Y for a given Q. If the actual value is outside the specified allowance it is removed.
nls_filter(df, allowance = 0.5)
nls_filter(df, allowance = 0.5)
df |
a data.frame with at least a Q and one other AHG field (Y. TW, V). |
allowance |
how much deviation from observed should be allowed (default = .5) |
data.frame
Other filters:
date_filter()
,
mad_filter()
,
qva_filter()
,
significance_check()
Normalized root mean square error (NRMSE) between sim and obs, with treatment of missing values
nrmse(sim, obs)
nrmse(sim, obs)
sim |
numeric vector simulated values |
obs |
numeric vector observed values |
numeric
Other evaluation:
pbias()
Sample gage data Manual measurements made at NWIS site 01096500 Q_cms is a mandatory argument and at least one of TW_m, V_ms, or Y_m.
nwis
nwis
A data frame with 245 rows and 6 columns:
NWIS ID
date of measurement
Steamflow (cubic meters per second)
Depth (meters)
Velocity (meters per second)
Top width (meters)
Percent Bias between sim and obs, with treatment of missing values.
pbias(sim, obs)
pbias(sim, obs)
sim |
numeric vector simulated values |
obs |
numeric vector observed values |
numeric
Other evaluation:
nrmse()
The function tests if the measured Q is outside of the expected range based on the product of measured velocity, top-width, and depth (e.g. Q≠vA)
qva_filter(df, allowance = 0.05)
qva_filter(df, allowance = 0.05)
df |
a data.frame with a Q, Y, TW, V and field. |
allowance |
how much deviation from equality should be allowed (default = .05) |
data.frame
Other filters:
date_filter()
,
mad_filter()
,
nls_filter()
,
significance_check()
The relationship between all supplied log transformed variables are computed. If the p-value of any of these is less then the supplied p-value an error message is emitted.
significance_check(df, pvalue = 0.05)
significance_check(df, pvalue = 0.05)
df |
a data.frame with at least a Q and one other AHG field (Y. TW, V). |
pvalue |
Significant p-value (default = .05) |
data.frame
Other filters:
date_filter()
,
mad_filter()
,
nls_filter()
,
qva_filter()
Calculate the gradient of line segments from a 3D matrix of coordinates
slope_matrix(mat, lonlat = TRUE) slope_weighted(mat, lonlat = TRUE, directed = FALSE) slope_mean(mat, lonlat = TRUE, directed = FALSE)
slope_matrix(mat, lonlat = TRUE) slope_weighted(mat, lonlat = TRUE, directed = FALSE) slope_mean(mat, lonlat = TRUE, directed = FALSE)
mat |
Matrix containing coordinates and elevations. The matrix should have three columns: X, Y, and Z. In data with geographic coordinates, Z values are assumed to be in meters. In data with projected coordinates, Z values are assumed to have the same units as the X and Y coordinates. |
lonlat |
Are the elements provided in longitude/latitude coordinates? By default, value is from the CRS of the routes ('sf::st_is_longlat(...)'). |
A vector of slopes associated with each LINE element The output value is a proportion representing the change in elevation for a given change in horizontal distance.
Other hydraulics:
compute_channel_slope()
,
compute_hydraulic_params()
,
compute_n()
,
cross_section()
,
extract_thalweg()