## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(nwaa)

## ----wu-models, eval = FALSE--------------------------------------------------
# nwaa_wu_models()

## ----wu-vars-irrwd, eval = FALSE----------------------------------------------
# nwaa_wu_variables("wu-irrigation-wd")

## ----wu-vars-thermo, eval = FALSE---------------------------------------------
# nwaa_wu_variables("wu-thermoelectric")

## ----wu-irrwd, eval = FALSE---------------------------------------------------
# irrwd <- nwaa_water_use(
#   model_id      = "wu-irrigation-wd",
#   variable_ids  = c("irrwdtot", "irrwdgw", "irrwdsw"),
#   location_type = "huc8",
#   location_id   = "18030001",
#   time_res      = "annualwy",
#   range         = "custom",
#   start         = "2018",
#   end           = "2020"
# )
# head(irrwd)

## ----wu-irrcu, eval = FALSE---------------------------------------------------
# irrcu <- nwaa_water_use(
#   model_id      = "wu-irrigation-cu",
#   variable_ids  = "irrcutot",
#   location_type = "huc8",
#   location_id   = "18030001",
#   time_res      = "annualwy",
#   range         = "historical"
# )
# head(irrcu)

## ----wu-pswd, eval = FALSE----------------------------------------------------
# pswd <- nwaa_water_use(
#   model_id      = "wu-public-supply-wd",
#   variable_ids  = c("pswdtot", "pswdgw", "pswdsw"),
#   location_type = "countycd",
#   location_id   = "06029",
#   time_res      = "annualcy",
#   range         = "recent"
# )
# head(pswd)

## ----wu-pscu, eval = FALSE----------------------------------------------------
# pscu <- nwaa_water_use(
#   model_id      = "wu-public-supply-cu",
#   variable_ids  = "pscutot",
#   location_type = "countycd",
#   location_id   = "06029",
#   time_res      = "annualcy",
#   range         = "historical"
# )
# head(pscu)

## ----wu-thermo, eval = FALSE--------------------------------------------------
# thermo <- nwaa_water_use(
#   model_id      = "wu-thermoelectric",
#   variable_ids  = c("tewdftot", "tecuftot"),
#   location_type = "statecd",
#   location_id   = "ca",
#   time_res      = "annualcy",
#   range         = "historical",
#   intersection  = "overlap"
# )
# head(thermo)

## ----wu-state, eval = FALSE---------------------------------------------------
# state_irrig <- nwaa_water_use(
#   model_id      = "wu-irrigation-wd",
#   variable_ids  = "irrwdtot",
#   location_type = "statecd",
#   location_id   = "ca",
#   time_res      = "annualcy",
#   range         = "historical",
#   intersection  = "envelop"  # stricter: only HUC12s ≥98% inside California
# )
# head(state_irrig)

## ----wu-loop, eval = FALSE----------------------------------------------------
# library(purrr)
# library(dplyr)
# 
# county_fips <- c("06029", "06031", "06107", "06019")  # Kern, Kings, Tulare, Fresno
# 
# irrig_sjv <- map_dfr(county_fips, function(fips) {
#   nwaa_water_use(
#     model_id      = "wu-irrigation-wd",
#     variable_ids  = c("irrwdtot", "irrwdgw", "irrwdsw"),
#     location_type = "countycd",
#     location_id   = fips,
#     time_res      = "annualwy",
#     range         = "historical"
#   ) |>
#     mutate(county_fips = fips)
# })
# 
# head(irrig_sjv)

## ----wu-recent, eval = FALSE--------------------------------------------------
# # Just the most recent calendar year
# recent_pswd <- nwaa_water_use(
#   model_id      = "wu-public-supply-wd",
#   variable_ids  = "pswdtot",
#   location_type = "countycd",
#   location_id   = "06029",
#   time_res      = "annualcy",
#   range         = "recent"
# )

