Skip to content

Commit

Permalink
added hc-plot
Browse files Browse the repository at this point in the history
  • Loading branch information
biopsichas committed Jul 3, 2024
1 parent 1fe8d74 commit 88de071
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: SWATtunR
Type: Package
Title: Soft & Hard Calibration, Validation Package for SWAT+ models
Version: 0.0.1.9008
Version: 0.0.1.9009
Authors@R: c(
person("Svajunas", "Plunge", , "svajunas.plunge@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = '0000-0001-8897-3349')),
Expand Down
3 changes: 3 additions & 0 deletions R/prepare.R
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ calculate_wyr <- function(sim) {
#' obj_tbl <- calculate_performance(sim = sim_flow, obs, "flo_day", c("kge", "nse"), "month", "sum")
#' }
#' @keywords calculate
#' @seealso \code{\link{calculate_performance_2plus}}

calculate_performance <- function(sim, obs, par_name = NULL, perf_metrics = NULL,
period = NULL,
Expand Down Expand Up @@ -326,6 +327,8 @@ calculate_performance <- function(sim, obs, par_name = NULL, perf_metrics = NULL
#' vector_weights = c(0.5, 0.3, 0.2),
#' perf_metrics = c("nse", "kge", "pbias", "r2", "mae")
#' }
#' @keywords calculate
#' @seealso \code{\link{calculate_performance}}

calculate_performance_2plus <- function(sim, vector_var, list_obs, list_periods = NULL,
vector_weights = NULL,
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ articles:
navbar: Hard calibration
contents:
- hc
- hc-plot
10 changes: 10 additions & 0 deletions vignettes/hc-plot.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Plotting results"
subtitle: "Plotting SWAT+ model results"
output: html_document
bibliography: ref.bib
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
37 changes: 7 additions & 30 deletions vignettes/hc.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -306,44 +306,21 @@ The performance metrics can also be applied to multiple variables within the sim
```{r calc_perf_mv, message = FALSE, warning = FALSE, eval = FALSE, echo = FALSE}
# Example of usage:
var_to_use <- list("flo_day_52", "no3_day_52_conc", "gwd_day")
var_to_use <- c("flo_day_52", "no3_day_52_conc", "gwd_day")
var_weights <- c(0.5, 0.3, 0.2) ## The sum of weights should be 1.
periods <- list(q_cal_period, wq_cal_period, c('2007-01-01', '2011-12-26'))
# Read the another observed data
# In case you want to use water quality data, read it here before applying the following code.
# In case you want to use water quality data, read it here before applying the
# following code.
obs2 <- read_csv(wqobs_path)
obs3 <- read_csv(gwobs_path)
# Calculate the performance metrics for each variable separately.
calculate_performance_mv <- function(sim, vector_var, list_obs, list_periods = NULL,
vector_weights = 1,
perf_metrics = c("nse", "kge", "pbias", "r2", "mae")){
obj_tbl_list <- pmap(list(vector_var, list_obs, list_periods), function(.x, .y, .z){
if(!is.NULL(.z)){
tmp <- fix_dates(sim, .y, trim_start = .z[1], trim_end = .z[2])
}
tmp <- fix_dates(sim, .y, trim_start = .z[1], trim_end = .z[2])
calculate_performance(tmp$sim, tmp$obs, par_name = .x,
perf_metrics = perf_metrics)}) %>%
set_names(vector_var)
# Calculate the mean of the performance rank for all parameter sets. In this case
# the weights for each variable should be defined and result could be used with
# only option 1 in step 8
obj_tbl <- map2(obj_tbl_list, vector_weights, function(.x, .y){
select(.x, c(run_id, rank_tot)) %>%
mutate(rank_tot = rank_tot * .y)}) %>%
reduce(., left_join, by = 'run_id')%>%
mutate(sum_rank = rowSums(across(starts_with("rank_tot")))) %>%
mutate(rank_tot = as.integer(rank(sum_rank))) %>%
select(run_id, rank_tot)
return(list(obj_tbl_list = obj_tbl_list, obj_tbl = obj_tbl))
}
obj_tbl_m <- calculate_performance_2plus(sim_flow, var_to_use,
list(obs, obs2, obs3), periods,
var_weights)
```


```

0 comments on commit 88de071

Please sign in to comment.