Code and data for:
Stachelek et al. In prep. Regional scale process-based estimates of phosphorus loading to lakes
# python
conda env create -f environment.yml
source activate pgml_ploading
# R
Rscript -e 'remotes::install_github("jsta/rinvest")'
Rscript -e 'rinvest::install_invest()'
Rscript -e 'install.packages("renv")'
Rscript -e 'install.packages(unique(renv::dependencies()$Package))'
A workflow for an example lake (Lake Mendota, Yahara) using included data:
# source utils script
source("scripts/99_utils.R")
site_no <- "05427718" # yahara at windsor
year <- 2012
custom_params <- data.frame(
median = c(k_param = 28.71, threshold_flow_accumulation = 98.56, load_fac = 2.43),
stringsAsFactors = FALSE
)
params <- ndr_params_default(custom_params)
run_ndr(params$median, site_no = site_no, year = year)
Calibration that "fixes" all parameters except k, tfa, and load_fac
# see ndr_params_default()[c(12, 13, 14),]
# target load
read.csv("data/nwis/nwis.csv",
colClasses = c("flow_station_id" = "character")) %>%
dplyr::filter(flow_station_id == site_no) %>%
pull(LOAD_A_00665) %>%
round(2) # kg/yr
params <- params[c(12, 13, 14),]
parscale <- 1 / (params$median - as.numeric(scale(params$median)))
unlink("log.csv")
FME::modFit(run_ndr,
p = params$median,
lower = params$lower, upper = params$upper,
site_no = site_no, year = year,
p_position = c(12, 13, 14),
method = "Nelder-Mead",
control = list(parscale = parscale))
calibration_viz("log.csv")
calibration_viz("calibration/log_2012_05427718.csv")

make data
make -C calibration -f Makefile log_2012_05427718.csv
make calibration_local
Rscript -e 'testthat::test_dir("tests")'
Rscript -e 'testthat::test_file("tests/test-run_ndr.R")'
Content type
Image
Digest
Size
1.7 GB
Last updated
over 5 years ago
docker pull jsta/watershed_ploading