Title: | R Package for Calculating Hydraulic Travel Times Based on Sinus Temperature Fitting |
---|---|
Description: | Requires daily temperature times series in a surface water body and one groundwater observation well (in case of an production well this data needs to be cleaned in order to reduce temperature fluctuations due to the operation scheme!). |
Authors: | Michael Rustler [aut, cre] , Hauke Sonnenberg [ctb] , Smart-Control [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph] |
Maintainer: | Michael Rustler <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.5 |
Built: | 2024-10-29 03:46:47 UTC |
Source: | https://github.com/KWB-R/kwb.heatsine |
Get Path to File in This Package
extdata_file(...)
extdata_file(...)
... |
parts of path passed to |
Get Predictions
get_predictions(sinusfit_sw, sinusfit_gw, retardation_factor = 2)
get_predictions(sinusfit_sw, sinusfit_gw, retardation_factor = 2)
sinusfit_sw |
as retrieved by |
sinusfit_gw |
as retrieved by |
retardation_factor |
hydraulic retardation factor (default: 2) |
list with sim/observation data ("data") fit parameters ("paras"), goodness-of-fit values ("gof") traveltimes ("traveltimes") and special (min, max, turning) points ("points")
Get tidy traveltimes
get_tidy_traveltimes(traveltimes)
get_tidy_traveltimes(traveltimes)
traveltimes |
traveltimes object as retrieved by
|
data frame with tidy traveltimes
Helper function: get traveltime
get_travel_time(sinusfit_sw, sinusfit_gw, retardation_factor = 1.8)
get_travel_time(sinusfit_sw, sinusfit_gw, retardation_factor = 1.8)
sinusfit_sw |
as retrieved by |
sinusfit_gw |
as retrieved by |
retardation_factor |
hydraulic retardation factor (default: 2) |
data frame with travel times for min/max and turning points
Load Temperature Data From CSV
load_temperature_from_csv(path)
load_temperature_from_csv(path)
path |
path to csv file with temperature data and columns: "date" (YYYY-MM-DD) and "value" |
tibble with temperature data and columns "date" and "value"
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) gw_data
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) gw_data
Optimise Sinus Fit Function
opt_func(period, df, opt_criteria = "RMSE", debug = TRUE)
opt_func(period, df, opt_criteria = "RMSE", debug = TRUE)
period |
period length |
df |
data frame with temperature data and columns "date" (YYYY-MM-DD) and "value" |
opt_criteria |
(default: "RMSE"), for other options check: ?hydroGOF::gof |
debug |
show debug messages (default: TRUE) |
scalar with optimisation result
Optimise Sinus Fit for Fixed Period
optimise_sinus_fixedPeriod(df, period_length = 365.25)
optimise_sinus_fixedPeriod(df, period_length = 365.25)
df |
data frame with temperature data and columns "date" (YYYY-MM-DD) and "value" |
period_length |
period length (default: 365.25) |
list with fit parameters ("paras"), goodness-of-fit values ("gof"), special points, i.e. min/max/turning-points ("points), fit model ("lm_model") and input data ("data")
https://stats.stackexchange.com/questions/77543/how-do-i-get-the-amplitude-and-phase-for-sine-wave-from-lm-summary
Optimise Sinus Fit for Variable Period
optimise_sinus_variablePeriod( temp_df, optFunc = opt_func, opt_limits = c(100, 500), opt_tolerance = 0.001, opt_debug = FALSE )
optimise_sinus_variablePeriod( temp_df, optFunc = opt_func, opt_limits = c(100, 500), opt_tolerance = 0.001, opt_debug = FALSE )
temp_df |
data frame with temperature data and columns "date" (YYYY-MM-DD) and "value" |
optFunc |
optimisation function (default: |
opt_limits |
optimisation limits for "period_length" (default: c(100,500)) |
opt_tolerance |
(default: 0.001) |
opt_debug |
show debug information (default: FALSE) |
list with fit parameters ("paras"), goodness-of-fit values ("gof"), special points, i.e. min/max/turning-points ("points), fit model ("lm_model") and input data ("data")
https://stats.stackexchange.com/questions/77543/how-do-i-get-the-amplitude-and-phase-for-sine-wave-from-lm-summary
Plot Prediction Interactive
plot_prediction_interactive(predictions)
plot_prediction_interactive(predictions)
predictions |
as retrieved by get_predictions() |
interactive prediction plot
Plot Temperature Interactive
plot_temperature_interactive(df)
plot_temperature_interactive(df)
df |
data frame with temperature data and columns "date" (YYYY-MM-DD) and "value" |
plot with interactive temperature data
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) kwb.heatsine::plot_temperature_interactive(gw_data)
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) kwb.heatsine::plot_temperature_interactive(gw_data)
Wrapper function for sinus optimisation
run_optimisation( data_sw_selected, data_gw_selected, retardation_factor = 2, sw_monitoring_id = ifelse(!is.null(attr(data_sw_selected, "monitoring_id")), attr(data_sw_selected, "monitoring_id"), "surface-water monitoring point"), gw_monitoring_id = ifelse(!is.null(attr(data_gw_selected, "monitoring_id")), attr(data_gw_selected, "monitoring_id"), "groundwater monitoring point"), limits = c(100, 500), tolerance = 0.001, debug = FALSE )
run_optimisation( data_sw_selected, data_gw_selected, retardation_factor = 2, sw_monitoring_id = ifelse(!is.null(attr(data_sw_selected, "monitoring_id")), attr(data_sw_selected, "monitoring_id"), "surface-water monitoring point"), gw_monitoring_id = ifelse(!is.null(attr(data_gw_selected, "monitoring_id")), attr(data_gw_selected, "monitoring_id"), "groundwater monitoring point"), limits = c(100, 500), tolerance = 0.001, debug = FALSE )
data_sw_selected |
data.frame with daily data temperature data of surface water monitoring point with columns "date" (format: "YYYY-MM-DD") and "value" (format: double, temperature in degree Celsius) for selected time period |
data_gw_selected |
data.frame with daily data temperature data of groundwater monitoring point with columns "date" (format: "YYYY-MM-DD") and "value" (format: double, temperature in degree Celsius) for selected time period |
retardation_factor |
hydraulic retardation factor (default: 2) |
sw_monitoring_id |
optional label for surface water monitoring id (default: "surface-water monitoring point"
or attr(data_sw_selected, "monitoring_id") if data imported with |
gw_monitoring_id |
optional label for groundwater monitoring id (default: "surface-water monitoring point"
or attr(data_sw_selected, "monitoring_id") if data imported with |
limits |
minimum/maximum period length for sinus optimisation in days (default: c(100, 500)) |
tolerance |
the desired accuracy (default: 0.001 |
debug |
show debug messages (default: FALSE) |
list with sim/observation data ("data") fit parameters ("paras"), goodness-of-fit values ("gof")
traveltimes ("traveltimes") and special (min, max, turning) points ("points") as returned by get_predictions
load_temp <- function(base_name) { kwb.heatsine::load_temperature_from_csv( kwb.heatsine::extdata_file(base_name) ) } data_sw <- load_temp("temperature_surface-water_Txxsxx-mxxxxsxxx.csv") data_gw <- load_temp("temperature_groundwater_Txxxx3.csv") data_sw_selected <- kwb.heatsine::select_timeperiod( data_sw, date_start = "2015-10-10", date_end = "2016-10-14" ) data_gw_selected <- kwb.heatsine::select_timeperiod( data_gw, date_start = "2015-12-28", date_end = "2016-12-26" ) kwb.heatsine::run_optimisation(data_sw_selected = data_sw_selected, data_gw_selected = data_gw_selected, retardation_factor = 1.8, sw_monitoring_id = attr(data_sw_selected, "monitoring_id"), gw_monitoring_id = attr(data_gw_selected, "monitoring_id"), limits = c(100, 500), tolerance = 0.001, debug = FALSE)
load_temp <- function(base_name) { kwb.heatsine::load_temperature_from_csv( kwb.heatsine::extdata_file(base_name) ) } data_sw <- load_temp("temperature_surface-water_Txxsxx-mxxxxsxxx.csv") data_gw <- load_temp("temperature_groundwater_Txxxx3.csv") data_sw_selected <- kwb.heatsine::select_timeperiod( data_sw, date_start = "2015-10-10", date_end = "2016-10-14" ) data_gw_selected <- kwb.heatsine::select_timeperiod( data_gw, date_start = "2015-12-28", date_end = "2016-12-26" ) kwb.heatsine::run_optimisation(data_sw_selected = data_sw_selected, data_gw_selected = data_gw_selected, retardation_factor = 1.8, sw_monitoring_id = attr(data_sw_selected, "monitoring_id"), gw_monitoring_id = attr(data_gw_selected, "monitoring_id"), limits = c(100, 500), tolerance = 0.001, debug = FALSE)
Helper function: select timeperiod
select_timeperiod( df, date_start, date_end = as.Date(date_start) + 365.25, col_date = "date" )
select_timeperiod( df, date_start, date_end = as.Date(date_start) + 365.25, col_date = "date" )
df |
data frame with date (defined in parameter "col_date) |
date_start |
start date of selection |
date_end |
end date of selection. If no value is given 365.25 days after "date_start" will be used (default: as.Date(date_start) + 365.25) |
col_date |
column for dates (default: "date") |
data frame with selected dates
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) gw_data_selected <- kwb.heatsine::select_timeperiod(gw_data, date_start = "2015-12-28", date_end = "2016-12-26") gw_data_selected
path <- kwb.heatsine::extdata_file("temperature_groundwater_Txxxx3.csv") gw_data <- kwb.heatsine::load_temperature_from_csv(path) gw_data_selected <- kwb.heatsine::select_timeperiod(gw_data, date_start = "2015-12-28", date_end = "2016-12-26") gw_data_selected