Skip to content
Snippets Groups Projects
Commit 238faaab authored by Christoph Schürz's avatar Christoph Schürz
Browse files

Implement print mgt and plot hu functions

parent 03535f37
No related branches found
No related tags found
No related merge requests found
Package: SWATdoctR
Type: Package
Title: Finding the right diagnoses and treatments for SWAT+ models
Version: 0.1.0.9002
Version: 0.1.0.9003
Author: c(person("Svajunas", "Plunge",
email = "svajunas_plunge@sggw.edu.pl",
role = c("aut")),
......
#' Print the triggered management operations from the mgt outputs for a certain HRU
#'
#' print_triggered_mgt extracts the triggered management operation which are written
#' into mgt_out.txt and reformats them to resemble the scheduled operations in
#' managment.sch to ease a comparison between them.
#'
#' @param sim_verify Simulation output of the function \code{run_swat_verification()}.
#' To print the management at least the output option \code{outputs = 'mgt'} must
#' be set in \code{run_swat_verification()}
#' @param hru_id id of the HRU for which the triggered management operations should
#' be printed
#' @param start_year Integer value to define the first year of printing.
#' @param end_year Integer value to define the last year of printing.
#'
#' @return Prints a tibble with triggered operations to the R console.
#'
#' @importFrom dplyr filter mutate rename select %>%
#' @export
#'
print_triggered_mgt <- function(sim_verify, hru_id, start_year = 1900, end_year = 2100) {
cat('Triggered managament for\n', ' hru: ', hru_id, '\n',
' management:', sim_verify$lum_mgt$mgt[sim_verify$lum_mgt$id == hru_id], '\n\n')
sim_verify$mgt_out %>%
filter(hru == hru_id) %>%
filter(year %in% start_year:end_year) %>%
rename(op_data1 = op_typ,
op_data3 = var1) %>%
mutate(op_data3 = ifelse(operation != 'FERT', 0, op_data3)) %>%
# mutate()
# mutate(date = ymd(paste(year, mon, day, sep = '-'))) %>%
select(., year, mon, day, phuplant, operation, op_data1, op_data3) %>%
print(., n = Inf)
}
#' Boxplot of heat unit fractions for crops at harvest-kill operation
#'
#' plot_phuplant_harvest plots boxplots of the collected heat unit fractions
#' at harvest-kill of a crop separated for all identified crops.
#'
#' @param sim_verify Simulation output of the function \code{run_swat_verification()}.
#' To plot the heat units at least the output option \code{outputs = 'mgt'} must
#' be set in \code{run_swat_verification()}
#'
#' @return ggplot boxplot with crop heat unit fractions at harvest-kill.
#'
#' @importFrom dplyr filter group_by mutate rename select ungroup %>%
#' @importFrom ggplot2 aes ggplot geom_boxplot geom_hline labs theme_bw
#' @export
#'
plot_phuplant_harvest <- function(sim_verify) {
hu_harv <- sim_verify$mgt_out %>%
filter(operation %in% c('HARVEST', 'KILL')) %>%
group_by(hru,year, mon, day) %>%
mutate(n = n()) %>%
ungroup() %>%
filter(n == 2, operation == 'HARVEST') %>%
select(op_typ, phuplant)
ggplot(data = hu_harv) +
geom_boxplot(aes(x = op_typ, y = phuplant)) +
geom_hline(yintercept = 1, lty = 2) +
labs(x = 'Crops', y = 'Crop HUs at harvest') +
theme_bw()
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/print_mgt.R
\name{plot_phuplant_harvest}
\alias{plot_phuplant_harvest}
\title{Boxplot of heat unit fractions for crops at harvest-kill operation}
\usage{
plot_phuplant_harvest(sim_verify)
}
\arguments{
\item{sim_verify}{Simulation output of the function \code{run_swat_verification()}.
To plot the heat units at least the output option \code{outputs = 'mgt'} must
be set in \code{run_swat_verification()}}
}
\value{
ggplot boxplot with crop heat unit fractions at harvest-kill.
}
\description{
plot_phuplant_harvest plots boxplots of the collected heat unit fractions
at harvest-kill of a crop separated for all identified crops.
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/print_mgt.R
\name{print_triggered_mgt}
\alias{print_triggered_mgt}
\title{Print the triggered management operations from the mgt outputs for a certain HRU}
\usage{
print_triggered_mgt(sim_verify, hru_id, start_year = 1900, end_year = 2100)
}
\arguments{
\item{sim_verify}{Simulation output of the function \code{run_swat_verification()}.
To print the management at least the output option \code{outputs = 'mgt'} must
be set in \code{run_swat_verification()}}
\item{hru_id}{id of the HRU for which the triggered management operations should
be printed}
\item{start_year}{Integer value to define the first year of printing.}
\item{end_year}{Integer value to define the last year of printing.}
}
\value{
Prints a tibble with triggered operations to the R console.
}
\description{
print_triggered_mgt extracts the triggered management operation which are written
into mgt_out.txt and reformats them to resemble the scheduled operations in
managment.sch to ease a comparison between them.
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment