Title: | R Package for Soil Water Balance and Solute Transport Modelling Scenarios for Project Flextreat |
---|---|
Description: | R Package for Soil Water Balance and Solute Transport Modelling Scenarios for Project Flextreat. |
Authors: | Michael Rustler [aut, cre] , Hauke Sonnenberg [ctb] , FlexTreat [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
Maintainer: | Michael Rustler <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-11-16 04:36:13 UTC |
Source: | https://github.com/KWB-R/flextreat.hydrus1d |
Helper function: add times
add_times(df, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"))
add_times(df, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"))
df |
df |
sim_datetime_start |
simulation start as datetime object (default: as.POSIXct("2017-05-01", tz = "UTC")) |
data frame with added times
for hydrologic years
aggregate_atmosphere(atm_selected, format = "wide")
aggregate_atmosphere(atm_selected, format = "wide")
atm_selected |
atm_selected as retrieved by |
format |
"wide" or "long |
aggregated data
Aggregate Solute
aggregate_solute( solute, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"), col_aggr = "date" )
aggregate_solute( solute, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"), col_aggr = "date" )
solute |
solute as retrieved by |
sim_datetime_start |
simulation start as datetime object (default: as.POSIXct("2017-05-01", tz = "UTC")) |
col_aggr |
column to be aggregated. One of "date", "yearmonth", "year" or "year_hydrologic" (default: "date") |
aggregated solute
only for columns starting with "sum" and matching "volume"
aggregate_tlevel( t_level, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"), col_aggr = "date" )
aggregate_tlevel( t_level, sim_datetime_start = as.POSIXct("2017-05-01", tz = "UTC"), col_aggr = "date" )
t_level |
t_level as retrieved by |
sim_datetime_start |
simulation start as datetime object (default: as.POSIXct("2017-05-01", tz = "UTC")) |
col_aggr |
column to be aggregated. One of "date", "yearmonth", "year" or "year_hydrologic" (default: "date") |
aggregated t_level data
Aggregate Atmospheric Data to Monthly Values
create_monthly_atm(atm = prepare_atmosphere_data())
create_monthly_atm(atm = prepare_atmosphere_data())
atm |
atm as retrieved by |
tibble with yearly atmospheric data values
create_monthly_atm()
create_monthly_atm()
Median daily potential evaporation for irrigation area (i.e. ~44km2), based
on 1x1km2 grids of DWD. Downloaded with read_daily_data_over_shape
between 2017-01-01 and 2020-12-31
evapo_p
evapo_p
A data.frame with 1461 rows and 10 variables:
name of downloaded grid file source
date
year
month
day
spatially averaged, mean
spatially averaged, standard deviation
spatially averaged, min
spatially averaged, max
number of grid-cells used for spatial averaging
## Not run: ### Data download remotes::install_github("kwb-r/kwb.dwd") shape_file <- system.file("extdata/input-data/gis/Abwasserverregnungsgebiet.shp", package = "flextreat.hydrus1d") # Only data of full months can currently be read! evapo_p <- kwb.dwd::read_daily_data_over_shape( file = shape_file, variable = "evapo_p", from = "201701", to = "202012" ) ## End(Not run) head(flextreat.hydrus1d::evapo_p)
## Not run: ### Data download remotes::install_github("kwb-r/kwb.dwd") shape_file <- system.file("extdata/input-data/gis/Abwasserverregnungsgebiet.shp", package = "flextreat.hydrus1d") # Only data of full months can currently be read! evapo_p <- kwb.dwd::read_daily_data_over_shape( file = shape_file, variable = "evapo_p", from = "201701", to = "202012" ) ## End(Not run) head(flextreat.hydrus1d::evapo_p)
Get Hydrologic Years
get_hydrologic_years(datetime)
get_hydrologic_years(datetime)
datetime |
datetime string |
integer vector with hydrologic year
Monthly irrigation values provided by AVB (in cubicmeters) downscaled to daily values (by dividing with "days_in_month" and normalised to mm/squaremeter by dividing with assumed irrigation area (44111068 m2)
irrigation
irrigation
A data.frame with 8835 rows and 3 variables:
year
month
days in month
date start
date end
irrigation area in squaremeter
irrigation using "groundwater" (mm/sqm)
irrigation using "clearwater" (mm/sqm)
)
## Not run: install.packages(c("dplyr", "tidyr")) irrigation_file <- system.file("extdata/input-data/Beregnungsmengen_AVB.csv", package = "flextreat.hydrus1d") # irrigation_area <- rgdal::readOGR(dsn = shape_file) # irrigation_area_sqm <- irrigation_area$area # 44111068m2 ## 2700ha (https://www.abwasserverband-bs.de/de/was-wir-machen/verregnung/) irrigation_area_sqm <- 27000000 irrigation <- read.csv2(irrigation_file) %>% dplyr::select(- .data$Monat) %>% dplyr::rename(irrigation_m3 = .data$Menge_m3, source = .data$Typ, month = .data$Monat_num, year = .data$Jahr) %>% dplyr::mutate(date_start = as.Date(sprintf("%d-%02d-01", .data$year, .data$month)), days_in_month = as.numeric(lubridate::days_in_month(.data$date_start)), date_end = as.Date(sprintf("%d-%02d-%02d", .data$year, .data$month, .data$days_in_month)), source = kwb.utils::multiSubstitute(.data$source, replacements = list("Grundwasser" = "groundwater.mmPerDay", "Klarwasser" = "clearwater.mmPerDay")), irrigation_cbmPerDay = .data$irrigation_m3/.data$days_in_month, irrigation_area_sqm = irrigation_area_sqm, irrigation_mmPerDay = 1000*irrigation_cbmPerDay/irrigation_area_sqm) %>% dplyr::select(.data$year, .data$month, .data$days_in_month, .data$date_start, .data$date_end, .data$source, .data$irrigation_mmPerDay, .data$irrigation_area_sqm) %>% tidyr::pivot_wider(names_from = .data$source, values_from = .data$irrigation_mmPerDay) ## End(Not run) head(flextreat.hydrus1d::irrigation)
## Not run: install.packages(c("dplyr", "tidyr")) irrigation_file <- system.file("extdata/input-data/Beregnungsmengen_AVB.csv", package = "flextreat.hydrus1d") # irrigation_area <- rgdal::readOGR(dsn = shape_file) # irrigation_area_sqm <- irrigation_area$area # 44111068m2 ## 2700ha (https://www.abwasserverband-bs.de/de/was-wir-machen/verregnung/) irrigation_area_sqm <- 27000000 irrigation <- read.csv2(irrigation_file) %>% dplyr::select(- .data$Monat) %>% dplyr::rename(irrigation_m3 = .data$Menge_m3, source = .data$Typ, month = .data$Monat_num, year = .data$Jahr) %>% dplyr::mutate(date_start = as.Date(sprintf("%d-%02d-01", .data$year, .data$month)), days_in_month = as.numeric(lubridate::days_in_month(.data$date_start)), date_end = as.Date(sprintf("%d-%02d-%02d", .data$year, .data$month, .data$days_in_month)), source = kwb.utils::multiSubstitute(.data$source, replacements = list("Grundwasser" = "groundwater.mmPerDay", "Klarwasser" = "clearwater.mmPerDay")), irrigation_cbmPerDay = .data$irrigation_m3/.data$days_in_month, irrigation_area_sqm = irrigation_area_sqm, irrigation_mmPerDay = 1000*irrigation_cbmPerDay/irrigation_area_sqm) %>% dplyr::select(.data$year, .data$month, .data$days_in_month, .data$date_start, .data$date_end, .data$source, .data$irrigation_mmPerDay, .data$irrigation_area_sqm) %>% tidyr::pivot_wider(names_from = .data$source, values_from = .data$irrigation_mmPerDay) ## End(Not run) head(flextreat.hydrus1d::irrigation)
A dataset containing hydraulic soil characteristics from Hydrus1D GUI database
materials
materials
A data frame with 12 rows and 7 variables:
Name of soil
Residual soil water content
Saturated soil water content
Parameter a in the soil water retention function (L-1, here: cm)
Parameter n in the soil water retention function
Saturated hydraulic conductivity (unit: LT-1, here: cm/day)
Tortuosity parameter in the conductivity function (-)
Hydrus1D GUI -> Soil Hydraulic Properties (Pre-Processing Menu, Water Flow Submenu)
materials
materials
Plot Atmosphere
plot_atmosphere(atm_selected_hydro_long)
plot_atmosphere(atm_selected_hydro_long)
atm_selected_hydro_long |
as retrieved by |
plot atmosphere
Plot Monthly Atmospheric Data
plot_monthly_atm()
plot_monthly_atm()
plot of monthly atmospheric data
plot_monthly_atm()
plot_monthly_atm()
Plot Solute
plot_solute(solute_aggr, y_label = "Share of 'clearwater' (%)")
plot_solute(solute_aggr, y_label = "Share of 'clearwater' (%)")
solute_aggr |
solute_aggr as retrieved by |
y_label |
y_label (default: "Share of 'clearwater' (%)") |
plot solute
Plot Water Balance
plot_waterbalance( tlevel_aggr, y_label = "Water Balance Component", unit_org = "cm", unit_target = "mm" )
plot_waterbalance( tlevel_aggr, y_label = "Water Balance Component", unit_org = "cm", unit_target = "mm" )
tlevel_aggr |
aggregated t_level as retrieved by |
y_label |
default: "Water Balance Component (mm)" |
unit_org |
original unit in "t_level" (default: "cm") |
unit_target |
target unit for plot (default: "mm") |
plot water balance
Hourly precipitation data downloaded from DWD for monitoring station Braunschweig (id = 662) between 1997-10-22 and 2021-12-31, which were aggregated to daily values within R
precipitation_daily
precipitation_daily
A data.frame with 8835 rows and 3 variables:
year
month
days in month
date start
date end
irrigation area in squaremeter
irrigation using "groundwater" (mm/sqm)
irrigation using "clearwater" (mm/sqm)
)
## Not run: install.packages(c("dplyr", "rdwd")) library(dplyr) rdwd::updateRdwd() rdwd::findID("Braunschweig") rdwd::selectDWD(name = "Braunschweig", res = "daily") url_bs_rain <- rdwd::selectDWD(name = "Braunschweig", res = "hourly", var = "precipitation", per = "historical" ) bs_rain <- rdwd::dataDWD(url_bs_rain) precipitation_hourly <- rdwd::dataDWD(url_bs_rain) %>% dplyr::select(.data$MESS_DATUM, .data$R1) %>% dplyr::rename("datetime" = "MESS_DATUM", "precipitation_mm" = "R1") precipitation_daily <- precipitation_hourly %>% dplyr::mutate("date" = as.Date(datetime)) %>% dplyr::group_by(date) %>% dplyr::summarise(rain_mm = sum(precipitation_mm)) ## End(Not run) head(flextreat.hydrus1d::precipitation_daily)
## Not run: install.packages(c("dplyr", "rdwd")) library(dplyr) rdwd::updateRdwd() rdwd::findID("Braunschweig") rdwd::selectDWD(name = "Braunschweig", res = "daily") url_bs_rain <- rdwd::selectDWD(name = "Braunschweig", res = "hourly", var = "precipitation", per = "historical" ) bs_rain <- rdwd::dataDWD(url_bs_rain) precipitation_hourly <- rdwd::dataDWD(url_bs_rain) %>% dplyr::select(.data$MESS_DATUM, .data$R1) %>% dplyr::rename("datetime" = "MESS_DATUM", "precipitation_mm" = "R1") precipitation_daily <- precipitation_hourly %>% dplyr::mutate("date" = as.Date(datetime)) %>% dplyr::group_by(date) %>% dplyr::summarise(rain_mm = sum(precipitation_mm)) ## End(Not run) head(flextreat.hydrus1d::precipitation_daily)
Hourly precipitation data downloaded from DWD for monitoring station Braunschweig (id = 662) between 1997-10-22 and 2021-12-31
precipitation_hourly
precipitation_hourly
A data.frame with 211629 rows and 2 variables:
date time
precipitation in mm
## Not run: install.packages(c("dplyr", "rdwd")) library(dplyr) rdwd::updateRdwd() rdwd::findID("Braunschweig") rdwd::selectDWD(name = "Braunschweig", res = "daily") url_bs_rain <- rdwd::selectDWD(name = "Braunschweig", res = "hourly", var = "precipitation", per = "historical" ) bs_rain <- rdwd::dataDWD(url_bs_rain) precipitation_hourly <- rdwd::dataDWD(url_bs_rain) %>% dplyr::select(.data$MESS_DATUM, .data$R1) %>% dplyr::rename("datetime" = "MESS_DATUM", "precipitation_mm" = "R1") ## End(Not run) head(flextreat.hydrus1d::precipitation_hourly)
## Not run: install.packages(c("dplyr", "rdwd")) library(dplyr) rdwd::updateRdwd() rdwd::findID("Braunschweig") rdwd::selectDWD(name = "Braunschweig", res = "daily") url_bs_rain <- rdwd::selectDWD(name = "Braunschweig", res = "hourly", var = "precipitation", per = "historical" ) bs_rain <- rdwd::dataDWD(url_bs_rain) precipitation_hourly <- rdwd::dataDWD(url_bs_rain) %>% dplyr::select(.data$MESS_DATUM, .data$R1) %>% dplyr::rename("datetime" = "MESS_DATUM", "precipitation_mm" = "R1") ## End(Not run) head(flextreat.hydrus1d::precipitation_hourly)
Prepares atmospheric input data structure required by HYDRUS1D and by default uses a conservative tracer in irrigation source "clearwater" ( set to 1) in order to track the share of cleaned wastewater in the system inflow rate (as "Prec" column is a combined value of irrigation using either "groundwater" or "clearwater" and real "rainfall").
prepare_atmosphere( atm, conc_irrig_clearwater = 100, conc_irrig_groundwater = 0, conc_rain = 0, defaults = kwb.hydrus1d::defaults_atmosphere() )
prepare_atmosphere( atm, conc_irrig_clearwater = 100, conc_irrig_groundwater = 0, conc_rain = 0, defaults = kwb.hydrus1d::defaults_atmosphere() )
atm |
atm as retrieved by |
conc_irrig_clearwater |
substance concentration in source "clearwater" used for irrigation (default: 100, set all other source concentrations in default to 0 in order to calculate share of "clearwater" infiltration to groundwater) |
conc_irrig_groundwater |
substance concentration in source "groundwater" used for irrigation (default: 0) |
conc_rain |
substance concentration in rainfall (default: 0) |
defaults |
defaults for undefined parameters |
tibble with peoered
atm <- prepare_atmosphere_data() atm_selected <- select_hydrologic_years(atm) prepare_atmosphere(atm_selected)
atm <- prepare_atmosphere_data() atm_selected <- select_hydrologic_years(atm) prepare_atmosphere(atm_selected)
Prepare Atmospheric Data
prepare_atmosphere_data()
prepare_atmosphere_data()
data frame with atmospheric data for Braunschweig
atm <- prepare_atmosphere_data() atm
atm <- prepare_atmosphere_data() atm
Select hydrologic years
select_hydrologic_years(atm = prepare_atmosphere_data())
select_hydrologic_years(atm = prepare_atmosphere_data())
atm |
atm as retrieved by |
select hydrologic years
atm <- prepare_atmosphere_data() atm_selected <- select_hydrologic_years(atm) head(atm_selected) tail(atm_selected)
atm <- prepare_atmosphere_data() atm_selected <- select_hydrologic_years(atm) head(atm_selected) tail(atm_selected)