Skip to content

Commit 260ad46

Browse files
authored
Merge pull request #35 from KWB-R/dev
AMAREX Deliverable: kwb.rabimo v2.1.0
2 parents 5104cdb + 72bc5f2 commit 260ad46

26 files changed

Lines changed: 1647 additions & 954 deletions

.github/workflows/R-CMD-check.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ jobs:
5757
key: ${{ runner.os }}-r-${{ matrix.config.r }}-3-${{ hashFiles('depends.Rds') }}
5858
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3-
5959

60+
- name: Install system dependencies on Linux
61+
if: runner.os == 'Linux'
62+
run: |
63+
sudo apt-get -y install cmake libssl-dev libgdal-dev gdal-bin libgeos-dev libproj-dev libsqlite3-dev libudunits2-dev
64+
6065
- name: Install system dependencies
61-
if: runner.os == 'Linux (no, skip this!)'
66+
if: runner.os == 'Linux (no, skip!)'
6267
env:
6368
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
6469
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.Ruserdata
55
docs
66
kwb.rabimo.Rproj
7+
inst/doc

DESCRIPTION

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: kwb.rabimo
22
Title: R Implementation of Water Balance Model Abimo
3-
Version: 2.0.0
3+
Version: 2.1.0.9000
44
Authors@R: c(
55
person("Hauke", "Sonnenberg", , "hauke.sonnenberg@kompetenz-wasser.de", role = c("aut", "cre"),
66
comment = c(ORCID = "0000-0001-9134-2871")),
@@ -15,22 +15,26 @@ URL: https://github.com/KWB-R/kwb.rabimo
1515
BugReports: https://github.com/KWB-R/kwb.rabimo/issues
1616
Encoding: UTF-8
1717
Roxygen: list(markdown = TRUE)
18-
RoxygenNote: 7.3.1
18+
RoxygenNote: 7.3.2
1919
Suggests:
2020
ggplot2,
2121
jsonlite,
22+
knitr,
2223
plumber,
24+
rmarkdown,
2325
testthat (>= 3.0.0)
2426
Imports:
2527
dplyr,
2628
kwb.utils (>= 0.15.0),
2729
magrittr,
2830
parallel,
29-
rlang
31+
rlang,
32+
sf
3033
Remotes:
3134
github::kwb-r/kwb.utils
3235
Config/testthat/edition: 3
3336
Depends:
3437
R (>= 3.5.0)
3538
LazyData: true
3639
LazyDataCompression: xz
40+
VignetteBuilder: knitr

NAMESPACE

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,41 @@
1-
# Generated by roxygen2: do not edit by hand
2-
3-
export("%>%")
4-
export(calculate_delta_w)
5-
export(data_to_natural)
6-
export(define_controls)
7-
export(generate_rabimo_area)
8-
export(get_measure_stats)
9-
export(get_soil_properties)
10-
export(read_column_info)
11-
export(real_evapo_transpiration)
12-
export(run_rabimo)
13-
export(run_rabimo_with_measures)
14-
export(test_plumber_api)
15-
export(triangle_of_fractions)
16-
importFrom(kwb.utils,catAndRun)
17-
importFrom(kwb.utils,createAccessor)
18-
importFrom(kwb.utils,defaultIfNULL)
19-
importFrom(kwb.utils,getAttribute)
20-
importFrom(kwb.utils,printIf)
21-
importFrom(kwb.utils,renameAndSelect)
22-
importFrom(kwb.utils,renameColumns)
23-
importFrom(kwb.utils,selectColumns)
24-
importFrom(kwb.utils,selectElements)
25-
importFrom(kwb.utils,stopFormatted)
26-
importFrom(kwb.utils,stringList)
27-
importFrom(magrittr,"%>%")
28-
importFrom(parallel,detectCores)
29-
importFrom(parallel,makeCluster)
30-
importFrom(parallel,parLapply)
31-
importFrom(parallel,stopCluster)
32-
importFrom(rlang,.data)
33-
importFrom(stats,approx)
34-
importFrom(utils,globalVariables)
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export("%>%")
4+
export(calculate_delta_w)
5+
export(crop_box)
6+
export(data_to_natural)
7+
export(define_controls)
8+
export(generate_rabimo_area)
9+
export(get_measure_stats)
10+
export(get_soil_properties)
11+
export(read_column_info)
12+
export(real_evapo_transpiration)
13+
export(run_rabimo)
14+
export(run_rabimo_with_measures)
15+
export(test_plumber_api)
16+
export(triangle_of_fractions)
17+
importFrom(kwb.utils,catAndRun)
18+
importFrom(kwb.utils,createAccessor)
19+
importFrom(kwb.utils,defaultIfNULL)
20+
importFrom(kwb.utils,getAttribute)
21+
importFrom(kwb.utils,printIf)
22+
importFrom(kwb.utils,renameAndSelect)
23+
importFrom(kwb.utils,renameColumns)
24+
importFrom(kwb.utils,selectColumns)
25+
importFrom(kwb.utils,selectElements)
26+
importFrom(kwb.utils,stopFormatted)
27+
importFrom(kwb.utils,stringList)
28+
importFrom(magrittr,"%>%")
29+
importFrom(parallel,detectCores)
30+
importFrom(parallel,makeCluster)
31+
importFrom(parallel,parLapply)
32+
importFrom(parallel,stopCluster)
33+
importFrom(rlang,.data)
34+
importFrom(sf,st_as_sf)
35+
importFrom(sf,st_as_sfc)
36+
importFrom(sf,st_bbox)
37+
importFrom(sf,st_crop)
38+
importFrom(sf,st_drop_geometry)
39+
importFrom(sf,st_sfc)
40+
importFrom(stats,approx)
41+
importFrom(utils,globalVariables)

NEWS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# kwb.rabimo 2.1.0 (2025-07-21)
2+
3+
Contains a tutorial in the form of a vignette. To view the vignette, install
4+
the package with
5+
6+
`remotes::install_github("kwb-r/kwb.rabimo@dev", build_vignettes = TRUE)`
7+
8+
and open the vignette with
9+
10+
`vignette("tutorial", package = "kwb.rabimo")`
11+
12+
You can read the tutorial also on our GitHub page:
13+
https://kwb-r.github.io/kwb.rabimo/articles/tutorial.html
14+
115
# kwb.rabimo 2.0.0 (2025-05-20)
216

317
- contains new data for Berlin in which road areas do not belong to blocks

R/calculate_delta_w.R

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ calculate_delta_w <- function(
2525
)
2626
{
2727
#kwb.utils::assignPackageObjects("kwb.rabimo")
28-
#columns_water_balance = c("runoff", "infiltr", "evapor");column_code = "code"
28+
#columns_water_balance=c("runoff","infiltr","evapor");column_code="code";digits=1L
29+
30+
urban <- remove_geo_column_if_required(urban)
2931

3032
columns <- c(column_code, columns_water_balance)
3133
data_urban <- select_columns(urban, columns)
@@ -40,9 +42,22 @@ calculate_delta_w <- function(
4042
delta_ws <- rowSums(abs(joined_urban - joined_natural)) /
4143
rowSums(joined_natural) * 100 / 2
4244

43-
data.frame(
45+
delta_w <- data.frame(
4446
code = joined[[column_code]],
4547
delta_w = unname(round(delta_ws, digits)),
4648
stringsAsFactors = FALSE
4749
)
50+
51+
if (is.null(geometry <- attr(urban, "geometry"))) {
52+
delta_w
53+
} else {
54+
restore_geo_column_if_required(
55+
delta_w,
56+
# unfortunately, the [] selection removes the attribute "sf_column"
57+
geometry = structure(
58+
geometry[match(delta_w$code, urban$code)],
59+
sf_column = attr(geometry, "sf_column")
60+
)
61+
)
62+
}
4863
}

R/data_to_natural.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ data_to_natural <- function(data, type = "undeveloped", veg_class = 50)
2525
# data <- kwb.rabimo::rabimo_inputs_2020$data; type = "undeveloped"
2626
# data <- kwb.rabimo::rabimo_inputs_2025$data; type = "undeveloped"
2727

28+
data <- remove_geo_column_if_required(data)
29+
2830
# Check whether data look as expected
2931
stop_on_invalid_data(data)
3032

@@ -45,13 +47,18 @@ data_to_natural <- function(data, type = "undeveloped", veg_class = 50)
4547
} else if (type == "horticultural") {
4648
"horticultural"
4749
} else {
48-
stop("please provide a known natural scenario type: undeveloped, horticultural or forested")
50+
clean_stop(
51+
'Please provide a known natural scenario type: "undeveloped", ',
52+
'"horticultural" or "forested"'
53+
)
4954
}
5055
}
5156

52-
check_or_convert_data_types(
57+
data <- check_or_convert_data_types(
5358
data,
5459
types = get_expected_data_type(),
5560
convert = TRUE
5661
)
62+
63+
restore_geo_column_if_required(data)
5764
}

R/generate_rabimo_area.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# generate_rabimo_area ---------------------------------------------------------
22

3-
#' Generate an area in R-ABIMO format with default values
3+
#' Generate an area in R-Abimo format with default values
44
#'
55
#' All default values can be overridden by entering new key-value pairs.
66
#'

R/rabimo_inputs_2020.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#' \item{`prec_s`}{Long-term average of annual precipitation within summer months (May to October) in mm (integer)}
1818
#' \item{`epot_yr`}{Long-term average of annual potential evapotranspiration in mm (integer)}
1919
#' \item{`epot_s`}{Long-term average of annual potential evapotranspiration within summer months (May to October) in mm (integer)}
20-
#' \item{`district`}{Number of Berlin "Bezirk" (district) in which the block area is located (character)}
20+
#' \item{`district`}{Number of Berlin "Bezirk" (district) in which the block area is located (character). This column is Berlin-specific and optional, i.e. not required by the model.}
2121
#' \item{`total_area`}{Total block area in square metres (numeric)}
2222
#' \item{`main_frac`}{Fraction of the total area that is NOT considered as "road" area (numeric value between 0.0 and 1.0). This value should be 0.0 if roads are modelled separately, i.e. as block areas on their own.}
2323
#' \item{`roof`}{Fraction of the total area that is considered as "roof" area (numeric value between 0.0 and 1.0)}
@@ -47,7 +47,7 @@
4747
#' \item{`block_type`}{Block type identifier of the form "usage-type-id_block-type-id_usage-type-description_block-type-description" (character)}
4848
#' }
4949
#'
50-
#' Note 1: The sum of surface class fractions `srf1_pvd`, `srf1_pvd`, `srf1_pvd`, `srf1_pvd`, `srf1_pvd` should be 1.0 within each block area.
50+
#' Note 1: The sum of surface class fractions `srf1_pvd`, `srf2_pvd`, `srf3_pvd`, `srf4_pvd`, `srf5_pvd` should be 1.0 within each block area.
5151
#'
5252
#' Note 2: The fields with suffix "_r" are all zero because rows are modelled as their own blocks. In an earlier version of the dataset, roads were modelled as parts of the block area.
5353
#'

R/rabimo_inputs_2025.R

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@
99
#' @format ## `rabimo_inputs_2025`
1010
#' A list containing two elements:
1111
#' \describe{
12-
#' \item{data}{a data frame with the input data in r-abimo format ...(number of vars)}
13-
#' \item{config}{a list object with configuration data}
12+
#' \item{data}{a data frame with the input data in R-Abimo format (see below)}
13+
#' \item{config}{a list object with configuration data (see below)}
1414
#' }
1515
#' @format ## `rabimo_inputs_2025$data`
16-
#' A data.frame with 58531 observations of 25 variables:
16+
#' A data.frame with 58531 observations of 26 variables:
1717
#' \describe{
1818
#' \item{`code`}{Unique block area identifier (character)}
1919
#' \item{`prec_yr`}{Long-term average of annual precipitation in mm (integer)}
2020
#' \item{`prec_s`}{Long-term average of annual precipitation within summer months (May to October) in mm (integer)}
2121
#' \item{`epot_yr`}{Long-term average of annual potential evapotranspiration in mm (integer)}
2222
#' \item{`epot_s`}{Long-term average of annual potential evapotranspiration within summer months (May to October) in mm (integer)}
23-
#' \item{`district`}{Number of Berlin "Bezirk" (district) in which the block area is located (character)}
23+
#' \item{`district`}{Number of Berlin "Bezirk" (district) in which the block area is located (character). This column is Berlin-specific and optional, i.e. not required by the model.}
2424
#' \item{`total_area`}{Total block area in square metres (numeric)}
2525
#' \item{`roof`}{Fraction of the total area that is considered as "roof" area (numeric value between 0.0 and 1.0)}
2626
#' \item{`green_roof`}{Fraction of the roof area that belongs to green roofs (numeric value between 0.0 and 1.0). A value of 1.0 means that all roofs in the block area are green roofs.}
@@ -32,21 +32,40 @@
3232
#' \item{`srf3_pvd`}{Fraction of the paved area that belongs to surface class 3 (numeric value between 0.0 and 1.0, see note 1 below)}
3333
#' \item{`srf4_pvd`}{Fraction of the paved area that belongs to surface class 4 (numeric value between 0.0 and 1.0, see note 1 below)}
3434
#' \item{`srf5_pvd`}{Fraction of the paved area that belongs to surface class 5 (numeric value between 0.0 and 1.0, see note 1 below)}
35-
#' \item{`to_swale`}{Fraction of sealed area (roof area + paved area) that is connected to an infiltration swale (numeric)}
35+
#' \item{`to_swale`}{Fraction of sealed area (roof area + paved area) that is connected to an infiltration swale (numeric value between 0.0 and 1.0)}
3636
#' \item{`gw_dist`}{Distance between groundwater table and surface in metres (numeric)}
3737
#' \item{`ufc30`}{field capacity in 30 cm depth (numeric)}
3838
#' \item{`ufc150`}{field capacity in 150 cm depth (numeric)}
3939
#' \item{`land_type`}{land type, one of `forested`, `horticultural`, `urban`, `vegetationless`, `waterbody` (character)}
40-
#' \item{`veg_class`}{vegetation class index (numeric), derived from an analysis tree volumes}
40+
#' \item{`veg_class`}{vegetation class index (numeric), derived from an analysis of tree volumes}
4141
#' \item{`irrigation`}{irrigation in mm per year (integer)}
42-
#' \item{`block_type`}{Block type identifier of the form "usage-type-id_block-type-id_usage-type-description_block-type-description" (character)}
42+
#' \item{`block_type`}{Block type identifier of the form "usage-type-id_block-type-id_usage-type-description_block-type-description" (character). This column is Berlin-specific and optional, i.e. not required by the model.}
43+
#' \item{`Shape`}{List structure containing geometry information on the different block areas. This column is optional. If provided, it will be appended to the model output so that model results can be plotted in the form of maps.}
4344
#' }
45+
#'
46+
#' Note 1: The sum of surface class fractions `srf1_pvd`, `srf2_pvd`, `srf3_pvd`, `srf4_pvd`, `srf5_pvd` should be 1.0 within each block area.
47+
#'
4448
#' @format ## `rabimo_inputs_2025$config`
4549
#' A list with 3 named elements:
4650
#' \describe{
47-
#' \item{runoff_factors}{Runoff factors, vector of numeric with names `roof`, `surface1`, `surface2`, `surface3`, `surface4`, `surface5`}
48-
#' \item{bagrov_values}{Bagrov values for sealed surfaces, vector of numeric with names `roof`, `green_roof`, `surface1`, `surface2`, `surface3`, `surface4`, `surface5`}
49-
#' \item{swale}{Model parameter(s) related to the 'swale' measure, vector of numeric with currently one value, named `swale_evaporation_factor`}
51+
#' \item{runoff_factors}{Runoff factors for roofs and five different surface
52+
#' types, given as a vector of numeric with element names `roof`, `surface1`,
53+
#' `surface2`, `surface3`, `surface4`, `surface5`. A runoff factor determines
54+
#' the proportion of precipitation that, after subtraction of
55+
#' evapotranspiration, becomes surface runoff from a paved area. The higher
56+
#' the factor, the less permeable is the surface.}
57+
#' \item{bagrov_values}{Bagrov values to calculate evapotranspiration from
58+
#' paved surfaces, given as a vector of numeric with element names `roof`,
59+
#' `green_roof`, `surface1`, `surface2`, `surface3`, `surface4`, `surface5`.
60+
#' The higher the Bagrov value, the more evapotranspiration is generated by
61+
#' the model. For a description of the evapotranspiration model and for a
62+
#' figure that shows the influence of the Bagrov values (n) on the
63+
#' evapotranspiration (in German), see \url{https://www.berlin.de/umweltatlas/wasser/wasserhaushalt/2001/methode/}}
64+
#' \item{swale}{Model parameter(s) related to the 'swale' measure, given as a
65+
#' vector of numeric with currently one value, named
66+
#' `swale_evaporation_factor`. The swale evaporation factor determines which
67+
#' fraction of the water going into a swale becomes evapotranspiration (the
68+
#' rest becomes infiltration).}
5069
#' }
5170
#' @source <https://www.berlin.de/umweltatlas/en/general/contact/>
5271
#' @source <https://gdi.berlin.de/services/wfs/ua_gruendaecher_2020?REQUEST=GetCapabilities&SERVICE=wfs>

0 commit comments

Comments
 (0)