HARPgroup / HARParchive

This repo houses HARP code development items, resources, and intermediate work products.
1 stars 0 forks source link

Implement Memoise in WSP generator #1163

Open rburghol opened 7 months ago

rburghol commented 7 months ago

The following functions will cache nhd results. These are preferable to reduce timeouts. We should put them in a function file, then call that file (later to be migrated to vahydro or hydroools). Ex: memo_get_nhdplus()

# set up a caching function for NWIS
library("memoise")
dir <- Sys.getenv("USGS_cache_dir")
if (dir == "") {
  dir <- tools::R_user_dir(package="dataRetrieval", which="cache")
}
if (!dir.exists(dir)) {
  dir.create(dir, recursive=TRUE)
}
# maybe don't use this just yet.
#unlink(dir, recursive = TRUE, force = TRUE)
db <- memoise::cache_filesystem(dir)
one_day <- 24*60^2
one_year <- 365 * one_day
memo_readNWISdv <- memoise::memoise(dataRetrieval::readNWISdv, ~memoise::timeout(one_day), cache = db)
memo_readNWISsite <- memoise::memoise(dataRetrieval::readNWISsite, ~memoise::timeout(one_day), cache = db)
memo_get_nhdplus <- memoise::memoise(nhdplusTools::get_nhdplus, ~memoise::timeout(one_year), cache = db)
memo_get_UT <- memoise::memoise(nhdplusTools::get_UT, ~memoise::timeout(one_year), cache = db)
memo_plot_nhdplus <- memoise::memoise(nhdplusTools::plot_nhdplus, ~memoise::timeout(one_year), cache = db)
memo_navigate_nldi <- memoise::memoise(nhdplusTools::navigate_nldi, ~memoise::timeout(one_year), cache = db)
megpritch commented 7 months ago

Memoise is Working in WSP_Regional_Summaries.Rmd!

Time Saved:

Next Steps