This vignette demonstrates the main functionality of the sacsmaR package. We first begin with introducing the input files required for the functions. Next, we introduce each different module included (PET, SNOW17, SAC-SMA, Lohmann routing). Finally, we'll show the usage of the hydrologigical simulation function, which is a wrapper for the individual modules.
#Rmarkdown setup knitr::opts_chunk$set( collapse = TRUE, comment = "#>" ) #Required packages library(sacsmaR) library(dplyr) library(lubridate) library(ggplot2)
We'll use the St. Croix Watershed data, which is included in this package
r data(stcroix)
watershed <- "stcroix" # starting date of the simulation str_date <- as.Date("1970/01/1") # ending date of the simulation end_date <- as.Date("1980/12/31") # Grid info file, consists of essential information for each grid cell: # latitude (Deg), longitude (Deg), area, elevation (meters), # flowlegth Each row belongs to a different HRU hru_info <- stcroix$hru.info as_tibble(grid_info)
Calibration parameters for the hydrology, pet, snow, and routing modules. Each row belongs to a different HRU
hru_par <- stcroix$hru.par as_tibble(hru_par)
#time-series of precipitation and temperature for each HRU. hru_prcp <- stcroix$prcp.grid hru_tavg <- stcroix$tavg.grid
Simulate daily potential evapotranspiration for a single HRU based on Hamon equation. The pet equation takes four inputs: par (pet parameter), tavg (time-series of average temperature), latitude information, and jday (day of the year from 1 to 365)
pet <- hamon(par = par_petHamon[1], tavg = hru_tavg[[1]], lat = hru_lat[[1]], jday = jday) df <- data_frame(date = seq_date, pet = pet) ggplot(df, aes(date, pet)) + geom_line() + labs(x = "", y = "PET (mm/day)")
Simulates snow based on the SNOW17 model
snowMelt <- snow17(par = par_snow17[1,], prcp = hru_prcp[[1]], tavg = hru_tavg[[1]], elev = hru_elev[[1]], jday = jday)
Simulates runoff at each grid cell
simflow <- sacsma(par = par_sacsma[1,], prcp = hru_prcp[[1]], pet = pet, lat = hru_lat[1], elev = hru_elev[1])
Simulates routing along the river using the lohmann model
flow <- lohmann(par = par_routLah[1,], flength = hru_flowlen[1])
Complete hydrological simulation using the Hydrosim() function, which is a wrapper for the PET, SAC-SMA, SNOW17, and Lohmann modules
hru_par <- hru_par %>% as.matrix() par_sacsma = hru_par[,1:16] par_petHamon = hru_par[,17] par_snow17 = hru_par[,18:27] par_routLah = hru_par[,28:31] flowR <- hydroSim( par.hamon = hru_par[,17], par.snow17 = hru_par[,18:27], par.sacsma = hru_par[,1:16], par.lohmann = hru_par[,28:31], tavg.grid = hru_tavg, prcp.grid = hru_prcp, lat.grid = hru_lat, elev.grid = hru_elev, area.grid = hru_area, flength.grid = hru_flowlen, jday = jday) df <- data_frame(date = seq_date, flowR = flowR) ggplot(df, aes(date, flowR)) + geom_line() + labs(x = "", y = "flow (mm/day)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.