habitat_predict.Rd
Predict Habitat Area using a Flow-to-Suitable-Area Curve
habitat_predict(
x,
reach,
mainstem,
watershed,
streamgage,
fsa_x,
fsa_y,
habitat_type = "rearing",
units = "ft",
run = "fall",
wy_group = "Dry",
gradient = "Valley Foothill"
)
A vector of flows at which to predict suitable habitat values
Integer comid
identifier for reach (must provide either reach, mainstem, OR watershed)
String name for mainstem (refer to cv_mainstems
dataset for options)
String name for watershed (refer to cv_watersheds
dataset for options)
(optional) Three-letter CDEC identifier for a streamgage
(optional) Vector of flows for manually defined flow-to-suitable-area curve. If provided, overrides reach, mainstem, or watershed lookup.
(optional) Vector of habitat values for manually defined flow-to-suitable-area curve, of same length as fsa_x
Either "rearing" (default) or "spawning"
Desired units for output, either "ft" for square ft per linear ft, or "ac" for total acres
(required if streamgage is provided) One of "fall" (default), "late fall", "winter", "spring", or "steelhead"
(required if streamgage is provided) Either "Dry" or "Wet" for water year type scenario
(required if streamgage is provided) For rearing, either "Valley Foothill" (default) or "Valley Lowland"
A vector of the same length as x
containing predicted suitable habitat values
# example non-temporal prediction given comid
habitat_predict(c(0, 10, 150, 300, 9999), reach = 7978069)
#> [1] 0.1450576 0.1450576 0.1576878 0.1605605 5.0666604
# example temporal prediction given comid and streamgage
habitat_predict(c(0, 10, 150, 300, 9999), reach = 7978069, streamgage = "FSB")
#> Error in approx(x = fsa_weighted$q, xout = fsa$flow_cfs, y = fsa_weighted$durwua, rule = 2:2, na.rm = F): need at least two non-NA values to interpolate
# example non-temporal prediction given mainstem
habitat_predict(c(0, 10, 150, 300, 9999), mainstem = "Feather River")
#> [1] 0.09182488 0.09182488 0.11423968 1.23489964 25.60762872
# example temporal prediction given comid and streamgage
habitat_predict(c(0, 10, 150, 300, 9999), mainstem = "Feather River", streamgage = "FSB")
#> Error in mutate(mutate(mutate(filter(flow_xw, comid %in% comids), fsa = map2(comid, multiplier, function(x, y) { habistat::habitat_fsa_reach_scaled(reach = x, multiplier = y, habitat_type = habitat_type, units = "ft") })), drc = map2(comid, streamgage, function(x, y) { habistat::habitat_drc_weighted(reach = x, streamgage = y, run = run, wy_group = wy_group, gradient = gradient, scale = "flow")})), fsa_x_drc = map2(fsa, drc, function(f, d) { fsa_weighted <- habistat::duration_apply_dhsi_to_fsa_curve(fsa = f, drc = d, fsa_q = flow_cfs, fsa_wua = habitat, drc_q = flow_cfs, drc_dhsi = durhsi) return(tibble(flow_cfs = f$flow_cfs, habitat = approx(x = fsa_weighted$q, xout = f$flow_cfs, y = fsa_weighted$durwua, rule = 2:2, na.rm = F)$y))})): i In argument: `fsa_x_drc = map2(...)`.
#> i In group 1: `river_cvpia = "Feather River"`.
#> Caused by error in `map2()`:
#> i In index: 1.
#> Caused by error in `approx()`:
#> ! need at least two non-NA values to interpolate
# example manual prediction given custom provided flow-to-suitable-area curve
habitat_predict(c(0, 10, 150, 300, 9999), fsa_x = c(0, 100, 1000), fsa_y = c(47, 470, 4700))
#> [1] 47.000 258.500 1214.866 2488.223 4700.000