| Title: | NWS Hydrology Models: SAC-SMA, SNOW17, UH, CONSUSE, CHANLOSS |
|---|---|
| Description: | Interface to the National Weather Service operational hydrology models, Sacramento Soil Moisture Accounting (SAC-SMA), Snow Accumulation and Ablation (SNOW17). Also provides an interface to the unit hydrograph routing model (UH), consumptive use (CONSUSE) and channel loss/gain modules (CHANLOSS). The Fortran code used in this package is considered "legacy" and is not supported officially by NWS, but it should not have any significant differences from current operational models. |
| Authors: | Cameron Bracken [aut, cre] (ORCID: <https://orcid.org/0000-0003-1917-402X>), Geoffrey Walters [aut] (ORCID: <https://orcid.org/0009-0009-3804-8898>), Eric Anderson [ctb] (Original SNOW-17 and SAC-SMA Fortran code (NOAA/HRL)), George F. Smith [ctb] (Original LAG-K Fortran code (NOAA/HRL)), Janice M. Lewis [ctb] (Interpolation and LAG-K Fortran code (NOAA/HRL)), John E. Pask [ctb] (Original sorting routines (LLNL); see inst/COPYRIGHTS), Ondrej Certik [ctb] (MIT-licensed fortran-utils sorting and types modules; see inst/COPYRIGHTS), John Burkhardt [ctb] (MIT-licensed implementation of Brendt's zero finder; see inst/COPYRIGHTS), National Oceanic and Atmospheric Administration [cph] (International-rights holder for U.S. Government-authored components, including legacy NWSRFS Fortran and contributions by NOAA employees (C. Bracken through 2022-06-30, G. Walters); see inst/COPYRIGHTS), Battelle Memorial Institute [cph] (Copyright holder for PNNL-authored contributions by C. Bracken from 2022-07-01 onward; see inst/COPYRIGHTS) |
| Maintainer: | Cameron Bracken <[email protected]> |
| License: | Apache License (>= 2) |
| Version: | 1.0.2 |
| Built: | 2026-07-17 09:35:55 UTC |
| Source: | https://github.com/cran/nwsrfsr |
adc=a*x^b+(1.0-a)*x^c
adc3(a, b, c)adc3(a, b, c)
a |
a parameter (0<a<1) |
b |
b parameter (b>=0) |
c |
c parameter (c>=0) |
11 element vector representing the ADC
adc <- adc3(.5, 0.1, 2)adc <- adc3(.5, 0.1, 2)
Replicates the CHPS FEWS AdjustQ tool. Adjusts observed mean daily discharges using observed instantaneous and simulated discharges. If both observed mean daily and instantaneous data are missing, simulated discharge is used.
adjustq( daily_flow, inst_flow, sim = NULL, blend = 10L, interp_type = "ratio", error_tol = 0.01, max_iterations = 15L )adjustq( daily_flow, inst_flow, sim = NULL, blend = 10L, interp_type = "ratio", error_tol = 0.01, max_iterations = 15L )
daily_flow |
Data.frame with columns year, month, day, flow_cfs (daily obs) |
inst_flow |
Data.frame with columns year, month, day, hour, flow_cfs (instantaneous obs) |
sim |
Data.frame with columns year, month, day, hour, flow_cfs (simulated 6hr flow), or NULL. If provided, small/large gap filling uses simulation as fallback. |
blend |
Integer; threshold for small vs large gap in timesteps. Default 10. |
interp_type |
"ratio" or "difference". Default "ratio". |
error_tol |
Numeric; daily volume matching tolerance (fraction). Default 0.01. |
max_iterations |
Integer; max daily correction iterations. Default 15. |
A data.frame with columns: datetime (POSIXct), flow_cfs (adjusted flow)
Runs AdjustQ using bundled NRKW1 data.
adjustq_load_example(sim = TRUE, ...)adjustq_load_example(sim = TRUE, ...)
sim |
Logical; include simulation in AdjustQ. Default TRUE. |
... |
Additional arguments passed to |
A data.frame (see adjustq())
A dataset containing the percent area covered at a complete range of
elevations for the two zones of Salmon Falls Creek (SFLN2). Used as
input to rsnwelev().
area_elev_curvearea_elev_curve
A data.frame with 21 rows and 3 columns:
Cumulative area fraction of the basin below the reference elevation
Reference elevations for zone 1 (ft)
Reference elevations for zone 2 (ft)
Seasonal chanloss
chanloss(flow, forcing, dt_hours, pars)chanloss(flow, forcing, dt_hours, pars)
flow |
streamflow vector |
forcing |
forcing data |
dt_hours |
timestep in hours |
pars |
parameters |
Vector of flow modified by the chanloss pattern
Daily consuse model
consuse(input, pars, cfs = TRUE)consuse(input, pars, cfs = TRUE)
input |
A data frame (or matrix with col names), must have columns: flow, pet (units of mm), year, month, day |
pars |
model parameters in the same format as the sac and snow models, with type=='consuse' |
cfs |
if TRUE, then flow units of cfs are expected, if FALSE then cms are expected. |
data frame with consuse variables
Conduct NWRFC style forcing adjustments
fa_adj_nwrfc( dt_hours, forcing, pars, climo = NULL, dry_run = FALSE, return_climo = FALSE )fa_adj_nwrfc( dt_hours, forcing, pars, climo = NULL, dry_run = FALSE, return_climo = FALSE )
dt_hours |
timestep in hours |
forcing |
data frame with with columns for forcing inputs |
pars |
sac parameters |
climo |
climotology matrix |
dry_run |
Do a run without any forcing adjustments, only compute pet and etd |
return_climo |
Return the computed climo, instead of adjustments |
Matrix (1 column per zone) of unrouted channel inflow
data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 adj <- fa_adj_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars)data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 adj <- fa_adj_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars)
Conduct NWRFC style forcing adjustments
fa_nwrfc( dt_hours, forcing, pars, climo = NULL, dry_run = FALSE, return_adj = FALSE, return_climo = FALSE )fa_nwrfc( dt_hours, forcing, pars, climo = NULL, dry_run = FALSE, return_adj = FALSE, return_climo = FALSE )
dt_hours |
timestep in hours |
forcing |
data frame with with columns for forcing inputs |
pars |
sac parameters |
climo |
climotology matrix |
dry_run |
Do a run without any forcing adjustments, only compute pet and etd |
return_adj |
return monthly adjustment factors only |
return_climo |
return the computed monthly climo |
Matrix (1 column per zone) of unrouted channel inflow
data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars)data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars)
description
forcing_adjust_map_pet_ptps( climo, pars, ll = 0.9 * climo, ul = 1.1 * climo, return_climo = FALSE )forcing_adjust_map_pet_ptps( climo, pars, ll = 0.9 * climo, ul = 1.1 * climo, return_climo = FALSE )
climo |
blah |
pars |
blah |
ll |
blah |
ul |
blah |
return_climo |
blah |
stuff
climo <- rep(2, 12) pars <- c(.5, 0, 10, 0) forcing_adjust_map_pet_ptps(climo, pars)climo <- rep(2, 12) pars <- c(.5, 0, 10, 0) forcing_adjust_map_pet_ptps(climo, pars)
description
forcing_adjust_mat( climo, pars, ll = climo * ifelse(climo > 0, 0.9, 1.1), ul = climo * ifelse(climo > 0, 1.1, 0.9), return_climo = FALSE )forcing_adjust_mat( climo, pars, ll = climo * ifelse(climo > 0, 0.9, 1.1), ul = climo * ifelse(climo > 0, 1.1, 0.9), return_climo = FALSE )
climo |
blah |
pars |
blah |
ll |
blah |
ul |
blah |
return_climo |
blah |
stuff
climo <- rep(2, 12) pars <- c(.5, 0, 10, 0) forcing_adjust_mat(climo, pars)climo <- rep(2, 12) pars <- c(.5, 0, 10, 0) forcing_adjust_mat(climo, pars)
Format state output from sac_snow_states
format_states(x)format_states(x)
x |
output list from sac_snow_states |
a data.frame with formatted output
This function interpolates 12 forcing adjustment factors (1 per month) by placing them at the 15th of the month then interpolating between the previous and next months values for every time step in between.
interp_fa(factors, month, day, hour)interp_fa(factors, month, day, hour)
factors |
12 element vector of monthly adjustment factors |
month |
a vector of month values for each time step |
day |
a vector of day values for each time step |
hour |
a vector of hour values for each time step |
A vector matching the length of month, containing interpolated adjustment factors
d1 <- as.POSIXct("2001-01-01 00:00:00", tz = "UTC") d2 <- as.POSIXct("2001-12-31 18:00:00", tz = "UTC") dates <- seq.POSIXt(d1, d2, by = "6 hours") month <- as.integer(format(dates, "%m")) day <- as.integer(format(dates, "%d")) hour <- as.integer(format(dates, "%H")) factors <- c(.5, 2, 1, 1.5, 2, .5, 1, 2.5, 3, -1.5, 0, 1) ifa <- interp_fa(factors, month, day, hour) plot(dates, ifa, t = "l") points(as.POSIXct(paste0("2001-", 1:12, "-15"), tz = "UTC"), factors, col = "red")d1 <- as.POSIXct("2001-01-01 00:00:00", tz = "UTC") d2 <- as.POSIXct("2001-12-31 18:00:00", tz = "UTC") dates <- seq.POSIXt(d1, d2, by = "6 hours") month <- as.integer(format(dates, "%m")) day <- as.integer(format(dates, "%d")) hour <- as.integer(format(dates, "%H")) factors <- c(.5, 2, 1, 1.5, 2, .5, 1, 2.5, 3, -1.5, 0, 1) ifa <- interp_fa(factors, month, day, hour) plot(dates, ifa, t = "l") points(as.POSIXct(paste0("2001-", 1:12, "-15"), tz = "UTC"), factors, col = "red")
Lag-K Routing for any number of upstream points
lagk(dt_hours, uptribs, pars, sum_routes = TRUE, return_states = FALSE)lagk(dt_hours, uptribs, pars, sum_routes = TRUE, return_states = FALSE)
dt_hours |
timestep in hours |
uptribs |
a matrix where each column contains flow data (in cfs) for an upstream point |
pars |
parameters |
sum_routes |
add all routed values together or leave separate |
return_states |
return the lagk states |
vector of routed flows
NULLNULL
Loads NRKW1 or SFLN2 bundled example data and runs the full NWSRFS model chain.
load_example(lid = "NRKW1", forcing_adj = TRUE, shift_sf = TRUE)load_example(lid = "NRKW1", forcing_adj = TRUE, shift_sf = TRUE)
lid |
Station identifier: "NRKW1" or "SFLN2" |
forcing_adj |
Logical; apply forcing adjustments. Default TRUE. |
shift_sf |
Logical; shift UH flow forward one timestep. Default TRUE. |
A list with class "nwsrfs_run" (see nwsrfs_run())
run = load_example("NRKW1") plot(run$sim, type = "l")run = load_example("NRKW1") plot(run$sim, type = "l")
Daily average observed streamflow at NRKW1.
nrkw1_daily_flownrkw1_daily_flow
A data.frame with columns:
Date columns
Daily average streamflow (cfs)
Data source identifier
6-hour forcing data for Nooksack River at North Cedarville (NRKW1), 2 zones, period of record.
nrkw1_forcingnrkw1_forcing
A named list of 2 data.frames (NRKW1-1, NRKW1-2), each with columns:
Datetime columns
Mean areal precipitation (mm)
Mean areal temperature (deg C)
Fraction of precipitation as snow
Instantaneous (6-hour) observed streamflow at NRKW1.
nrkw1_inst_flownrkw1_inst_flow
A data.frame with columns:
Datetime columns
Instantaneous streamflow (cfs)
Data source identifier
Optimal parameters from NWRFC autocalibration for Nooksack River at North Cedarville, WA (USGS-12210700). 2-zone SAC-SMA/SNOW17/UH model with 3-reach Lag-K routing (6 hour timestep).
nrkw1_parsnrkw1_pars
A data.frame with 5 columns:
Unique parameter identifier
Parameter name
Model type (sac, snow, uh, fa, lagk)
Zone or upstream reach name
Parameter value
6-hour upstream flow timeseries for 3 upstream reaches (MFNW1, NFNW1, NSSW1) routed via Lag-K to Nooksack River at North Cedarville.
nrkw1_upflownrkw1_upflow
A named list of 3 data.frames, each with columns:
Datetime columns
Streamflow (cfs)
Reads parameter, forcing, flow, and upflow CSVs from an NWRFC autocalibration directory, auto-detects which model components are present, and runs the full chain: FA -> SAC-SMA/SNOW17 -> UH -> Lag-K -> Chanloss -> Consuse.
nwsrfs_run(autocalb_dir, run_dir = NULL, forcing_adj = TRUE, shift_sf = TRUE)nwsrfs_run(autocalb_dir, run_dir = NULL, forcing_adj = TRUE, shift_sf = TRUE)
autocalb_dir |
Path to an NWRFC autocalibration directory |
run_dir |
Name of results subdirectory (e.g. "results_por_02"). If NULL, uses the first results_* directory found. |
forcing_adj |
Logical; apply monthly climatological forcing adjustments. Default TRUE. |
shift_sf |
Logical; shift UH-derived streamflow forward one timestep (required for NWRFC calibrations). Default TRUE. |
The returned list contains:
Numeric vector of simulated flow (cfs)
Numeric vector of SAC-SMA/SNOW17/UH flow per zone (cfs), or NULL
Matrix of total channel inflow per zone (mm), or NULL
Numeric vector of Lag-K routed flow (cfs), or NULL
List of adjusted forcing data.frames, or NULL
Parameter data.frame
List of raw (unadjusted) forcing data.frames
List of upstream flow data.frames, or NULL
Daily observed flow data.frame
Instantaneous observed flow data.frame, or NULL
Model timestep in hours
Character vector of zone names
Character vector of upstream reach names, or NULL
Logical; SAC-SMA/SNOW17/UH present
Logical; Lag-K routing present
Logical; chanloss present
Logical; consuse present
A list with class "nwsrfs_run" containing model results and metadata. See Details.
R interface to NWSRFS Fortran hydrologic models used operationally by NOAA's National Weather Service River Forecast Centers. Includes SAC-SMA soil moisture accounting, SNOW-17 snow accumulation/ablation, gamma unit hydrograph routing, Lag-K channel routing, channel loss/gain, and consumptive use modules.
Individual model components callable via Fortran interface:
sac_snow(), uh(), lagk(), chanloss(), consuse(), fa_nwrfc()
nwsrfs_run() reads NWRFC autocalibration directories and runs the full
model chain. load_example() provides bundled example data for NRKW1 and SFLN2.
adjustq() replicates the CHPS FEWS AdjustQ tool for creating upstream
flow timeseries from observed and simulated data.
Maintainer: Cameron Bracken [email protected] (ORCID)
Authors:
Geoffrey Walters [email protected] (ORCID)
Other contributors:
Eric Anderson (Original SNOW-17 and SAC-SMA Fortran code (NOAA/HRL)) [contributor]
George F. Smith (Original LAG-K Fortran code (NOAA/HRL)) [contributor]
Janice M. Lewis (Interpolation and LAG-K Fortran code (NOAA/HRL)) [contributor]
John E. Pask (Original sorting routines (LLNL); see inst/COPYRIGHTS) [contributor]
Ondrej Certik (MIT-licensed fortran-utils sorting and types modules; see inst/COPYRIGHTS) [contributor]
Jacob Williams (BSD-3-clause roots-fortran library (src/root_module.f90); see inst/LICENSE_roots_fortran.md and inst/COPYRIGHTS) [contributor, copyright holder]
National Oceanic and Atmospheric Administration (International-rights holder for U.S. Government-authored components, including legacy NWSRFS Fortran and contributions by NOAA employees (C. Bracken through 2022-06-30, G. Walters); see inst/COPYRIGHTS) [copyright holder]
Battelle Memorial Institute (Copyright holder for PNNL-authored contributions by C. Bracken from 2022-07-01 onward; see inst/COPYRIGHTS) [copyright holder]
Useful links:
Report bugs at https://github.com/NOAA-NWRFC/nwsrfs-hydro-models/issues
Daily Potential Evapotranspiration using Hargreaves-Semani equations
pet_hs(lat, jday, tave, tmax, tmin)pet_hs(lat, jday, tave, tmax, tmin)
lat |
Latitude in decimal degrees |
jday |
Julian day (Day of year since Jan 1) |
tave |
Average daily temperature (C) |
tmax |
Max daily temperature (C) |
tmin |
Min daily temerature (C) |
Daily PET (vectorized over all inputs)
pet <- pet_hs(42, 200, 20, 25, 15)pet <- pet_hs(42, 200, 20, 25, 15)
Print method for nwsrfs_run objects
## S3 method for class 'nwsrfs_run' print(x, ...)## S3 method for class 'nwsrfs_run' print(x, ...)
x |
An nwsrfs_run object |
... |
Ignored |
x (invisibly)
Replace ptps column with ptps derived using rain snow line code (lapse rate + MAT)
rsnwelev(forcing, pars, ae_tbl)rsnwelev(forcing, pars, ae_tbl)
forcing |
data frame with columns for forcing inputs |
pars |
rsnwelev and snow17 parameters |
ae_tbl |
data.table with col1 containing quantile info and subsequent col with elev for each zone |
Matrix (1 column per zone) of the forcing input argument with ptps replaced with that derived from rsnwelev model
# area_elev_curve is bundled for SFLN2 (2 zones); pair it with SFLN2 data. data(sfln2_forcing) data(sfln2_pars) data(area_elev_curve) # rsnwelev only needs the zones that match the area-elevation table, # so drop the SFLN2-CU consumptive-use zone before calling. forcing_zones <- sfln2_forcing[c("SFLN2-1", "SFLN2-2")] forcing_adj <- rsnwelev(forcing_zones, sfln2_pars, area_elev_curve)# area_elev_curve is bundled for SFLN2 (2 zones); pair it with SFLN2 data. data(sfln2_forcing) data(sfln2_pars) data(area_elev_curve) # rsnwelev only needs the zones that match the area-elevation table, # so drop the SFLN2-CU consumptive-use zone before calling. forcing_zones <- sfln2_forcing[c("SFLN2-1", "SFLN2-2")] forcing_adj <- rsnwelev(forcing_zones, sfln2_pars, area_elev_curve)
Execute SAC-SMA, SNOW17, return total channel inflow per zone, and model states
sac_snow(dt_hours, forcing, pars, return_states = FALSE)sac_snow(dt_hours, forcing, pars, return_states = FALSE)
dt_hours |
timestep in hours |
forcing |
data frame with with columns for forcing inputs |
pars |
sac parameters |
return_states |
logical value indicating if the states should be output as well as the tci |
data.frame (1 column per zone) of unrouted channel inflow (tci), sac states uztwc, uzfwc, lztwc, lzfsc, lzfpc, adimc, and snow water equivalent (swe), and adjusted forcing data.
# Simple: full model chain via the bundled example run <- load_example("NRKW1") head(run$sacsnow_tci) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, # then call the SAC-SMA / SNOW17 wrapper directly. sac_snow() requires # forcing data frames that already contain etd_mm. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) tci <- sac_snow(dt_hours, forcing_adj, nrkw1_pars)# Simple: full model chain via the bundled example run <- load_example("NRKW1") head(run$sacsnow_tci) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, # then call the SAC-SMA / SNOW17 wrapper directly. sac_snow() requires # forcing data frames that already contain etd_mm. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) tci <- sac_snow(dt_hours, forcing_adj, nrkw1_pars)
Execute SAC-SMA, SNOW17, return total channel inflow per zone, and model states
sac_snow_states(dt_hours, forcing, pars)sac_snow_states(dt_hours, forcing, pars)
dt_hours |
timestep in hours |
forcing |
data frame with with columns for forcing inputs |
pars |
sac parameters |
data.frame (1 column per zone) of unrouted channel inflow (tci), sac states uztwc, uzfwc, lztwc, lzfsc, lzfpc, adimc, and snow water equivalent (swe), and adjusted forcing data.
# Simple: full model chain via the bundled example, tci and states returned together run <- load_example("NRKW1") head(run$sacsnow_tci) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, then # get per-zone tci and states directly. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) states <- sac_snow_states(dt_hours, forcing_adj, nrkw1_pars)# Simple: full model chain via the bundled example, tci and states returned together run <- load_example("NRKW1") head(run$sacsnow_tci) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, then # get per-zone tci and states directly. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) states <- sac_snow_states(dt_hours, forcing_adj, nrkw1_pars)
Execute SAC-SMA, SNOW17 and UH with given parameters
sac_snow_uh(dt_hours, forcing, pars)sac_snow_uh(dt_hours, forcing, pars)
dt_hours |
timestep in hours |
forcing |
data frame with columns for forcing inputs |
pars |
sac parameters |
Vector of routed flow in cfs
# Simple: full model chain via the bundled example run <- load_example("NRKW1") head(run$sim) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, # then call the combined SAC-SMA / SNOW17 / UH wrapper. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) flow_cfs <- sac_snow_uh(dt_hours, forcing_adj, nrkw1_pars)# Simple: full model chain via the bundled example run <- load_example("NRKW1") head(run$sim) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, # then call the combined SAC-SMA / SNOW17 / UH wrapper. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) flow_cfs <- sac_snow_uh(dt_hours, forcing_adj, nrkw1_pars)
Execute SAC-SMA, SNOW17, UH and LAG-K with given parameters
sac_snow_uh_lagk(dt_hours, forcing, uptribs, pars)sac_snow_uh_lagk(dt_hours, forcing, uptribs, pars)
dt_hours |
timestep in hours |
forcing |
data frame with columns for forcing inputs |
uptribs |
data frame with columns for upstream flow data |
pars |
sac parameters |
Vector of routed flow in cfs
# Simple: full model chain via the bundled example (NRKW1 has upstream tribs) run <- load_example("NRKW1") head(run$sim) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, then chain # SAC-SMA / SNOW17 / UH with Lag-K routing of upstream tributaries. data(nrkw1_forcing) data(nrkw1_pars) data(nrkw1_upflow) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) flow_cfs <- sac_snow_uh_lagk(dt_hours, forcing_adj, nrkw1_upflow, nrkw1_pars)# Simple: full model chain via the bundled example (NRKW1 has upstream tribs) run <- load_example("NRKW1") head(run$sim) # Low-level: populate etd_mm / pet_mm via fa_nwrfc first, then chain # SAC-SMA / SNOW17 / UH with Lag-K routing of upstream tributaries. data(nrkw1_forcing) data(nrkw1_pars) data(nrkw1_upflow) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) flow_cfs <- sac_snow_uh_lagk(dt_hours, forcing_adj, nrkw1_upflow, nrkw1_pars)
Find a reasonable scale upper limit for optimization
scale_uplimit(shape, dt_hours)scale_uplimit(shape, dt_hours)
shape |
shape parameter |
dt_hours |
timestep |
numeric value indicating the upper limit for the scale
Conputes surface pressure in hPa from a given elevation
sfc_pressure(elev)sfc_pressure(elev)
elev |
surface elevation in meters |
Surface pressure in hPa
sp <- sfc_pressure(0)sp <- sfc_pressure(0)
Daily average observed streamflow at SFLN2.
sfln2_daily_flowsfln2_daily_flow
A data.frame with columns:
Date columns
Daily average streamflow (cfs)
Data source identifier
6-hour forcing data for Salmon Falls Creek (SFLN2), 2 zones plus a consumptive use zone, period of record.
sfln2_forcingsfln2_forcing
A named list of 3 data.frames (SFLN2-1, SFLN2-2, SFLN2-CU), each with columns:
Datetime columns
Mean areal precipitation (mm)
Mean areal temperature (deg C)
Fraction of precipitation as snow
Instantaneous (6-hour) observed streamflow at SFLN2.
sfln2_inst_flowsfln2_inst_flow
A data.frame with columns:
Datetime columns
Instantaneous streamflow (cfs)
Data source identifier
Optimal parameters from NWRFC autocalibration for Salmon Falls Creek NR San Jacinto NV (USGS-13105000). 2-zone SAC-SMA/SNOW17/UH model with chanloss and consuse (6 hour timestep).
sfln2_parssfln2_pars
A data.frame with 5 columns:
Unique parameter identifier
Parameter name
Model type (sac, snow, uh, fa, chanloss, consuse)
Zone name
Parameter value
Two parameter unit hydrograph routing for one or more basin zones
uh( dt_hours, tci, pars, sum_zones = TRUE, start_of_timestep = TRUE, backfill = TRUE )uh( dt_hours, tci, pars, sum_zones = TRUE, start_of_timestep = TRUE, backfill = TRUE )
dt_hours |
timestep in hours |
tci |
channel inflow matrix, one column per zone |
pars |
parameters |
sum_zones |
should routed flows from multiple zones be added and returned as a vector, or kept separate and returned as a matrix |
start_of_timestep |
should the output flow data be shifted by one timestep to account for forcing data that uses beginning of timestep labeling |
backfill |
when start_of_timestep is TRUE, should the first value be duplicated |
Vector of routed flow in cfs
# Simple: full model chain via the bundled example; routed flow per zone run <- load_example("NRKW1") head(run$sacsnow_sf) # Low-level: run FA -> SAC-SMA/SNOW17 to get TCI, then route it with UH. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) tci <- sac_snow(dt_hours, forcing_adj, nrkw1_pars) flow_cfs <- uh(dt_hours, tci, nrkw1_pars)# Simple: full model chain via the bundled example; routed flow per zone run <- load_example("NRKW1") head(run$sacsnow_sf) # Low-level: run FA -> SAC-SMA/SNOW17 to get TCI, then route it with UH. data(nrkw1_forcing) data(nrkw1_pars) dt_hours <- 6 forcing_adj <- fa_nwrfc(dt_hours, nrkw1_forcing, nrkw1_pars) tci <- sac_snow(dt_hours, forcing_adj, nrkw1_pars) flow_cfs <- uh(dt_hours, tci, nrkw1_pars)
Returns ordinates for a 2 parameter (shape,scale) gamma unit hydrograph. The ordinates are based on the given timestep (in hours). To match the Fortran code, a max length is used. A warning is issued if the UH does not terminate before the given max length.
uh2p(shape, scale, timestep, max_len = 1000)uh2p(shape, scale, timestep, max_len = 1000)
shape |
gamma shape parameter |
scale |
gamma scale parameter |
timestep |
timestep in hours |
max_len |
max length of the uh |
vector of ordinates for a 2 parameter (shape,scale) gamma unit hydrograph
dt <- 6 shape <- 2 scale <- 1 y <- uh2p(2, 1, 6) x <- seq(dt, dt * length(y), by = dt) plot(x, y, t = "l")dt <- 6 shape <- 2 scale <- 1 y <- uh2p(2, 1, 6) x <- seq(dt, dt * length(y), by = dt) plot(x, y, t = "l")
Create a 2 parameter gamma unit hydrograph with units cfs/in
uh2p_cfs_in(shape, scale, timestep, area)uh2p_cfs_in(shape, scale, timestep, area)
shape |
gamma shape parameter |
scale |
gamma scale parameter |
timestep |
timestep in hours |
area |
basin area in square miles |
stuff
dt <- 6 shape <- 2 scale <- 1 y <- uh2p_cfs_in(2, 1, 6, 1000) x <- seq(dt, dt * length(y), by = dt) plot(x, y, t = "l")dt <- 6 shape <- 2 scale <- 1 y <- uh2p_cfs_in(2, 1, 6, 1000) x <- seq(dt, dt * length(y), by = dt) plot(x, y, t = "l")
Get the scale parameter from a 2 parameter gamma unit hydrograph given the shape parameter and time of concentration.
uh2p_get_scale(shape, toc, dt_hours)uh2p_get_scale(shape, toc, dt_hours)
shape |
gamma shape parameter |
toc |
time of concentration (hours) |
dt_hours |
UH timestep (hours) |
scalar scale parameter
uh2p_get_scale(2, 50, 1)uh2p_get_scale(2, 50, 1)
Get the scale parameter from a 2 parameter gamma unit hydrograph given the shape parameter and time of concentration.
uh2p_get_scale_r(shape, toc, dt_hours)uh2p_get_scale_r(shape, toc, dt_hours)
shape |
gamma shape parameter |
toc |
time of concentration (hours) |
dt_hours |
UH timestep (hours) |
stuff
uh2p_get_scale_r(2, 50, 1)uh2p_get_scale_r(2, 50, 1)
root finding function for finding a scale parameter given shape and toc
uh2p_root(scale, shape, dt_hours, toc)uh2p_root(scale, shape, dt_hours, toc)
scale |
scale parameter |
shape |
shape parameter |
dt_hours |
timestep |
toc |
time of concentration |
function value for root finding
Objective function for finding a scale parameter given shape and toc
uh2p_seek(scale, shape, dt_hours, toc)uh2p_seek(scale, shape, dt_hours, toc)
scale |
blah |
shape |
blah |
dt_hours |
blah |
toc |
blah |
objective function value
Objective function for finding a scale parameter given shape and toc
uh2p_seek2(scale, shape, dt_hours, toc)uh2p_seek2(scale, shape, dt_hours, toc)
scale |
blah |
shape |
blah |
dt_hours |
blah |
toc |
blah |
function value for root finding
Update parameters and re-run model chain
update_pars(run, new_pars)update_pars(run, new_pars)
run |
An "nwsrfs_run" object from |
new_pars |
A data.frame with columns "p_name" and "value" containing parameters to update. All p_name values must exist in the current pars. |
A new "nwsrfs_run" object with updated parameters