Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare next release #13

Open
wants to merge 363 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
363 commits
Select commit Hold shift + click to select a range
a15caf1
Change interface to columns_with()
hsonne Feb 26, 2024
5b60aaf
Consider new column "block_type" in unit test
hsonne Feb 26, 2024
c881366
Extract get_block_type()
hsonne Feb 26, 2024
52253db
Fix warning, shorten the code by pasting ".csv"
hsonne Feb 26, 2024
7f99ec9
Merge pull request #18 from KWB-R/continue-restructuring
hsonne Feb 26, 2024
462b499
Rewrite in_range() to accept a tolerance
hsonne Mar 4, 2024
1a8411f
Remove extra small summand
hsonne Mar 4, 2024
d09e1a9
Add rescale_to_row_sum()
hsonne Mar 4, 2024
6a36a30
Make R-Abimo run with 2019 and 2020 data
hsonne Mar 4, 2024
397234f
Prepare Excel file for Dominik
hsonne Mar 5, 2024
561abd2
Rename main argument of run_rabimo() to "data"
hsonne Mar 7, 2024
3779a5e
Rename argument "input_data" to "data"
hsonne Mar 7, 2024
3a69aea
Rename usage_is_*() to land_type_is_*()
hsonne Mar 7, 2024
df24cce
Rename "usage.R" to "land_type_is.R"
hsonne Mar 7, 2024
613e28c
Add dummy test functions
hsonne Mar 7, 2024
1c90ebf
Finish renaming of "usage.R" to "land_type_is.R"
hsonne Mar 7, 2024
7ab2c4f
Remove suffix letter from land type keywords
hsonne Mar 7, 2024
aa1e50e
Rename _is_agricultural() to _is_urban()
hsonne Mar 7, 2024
e605a89
Rename "is_agri" to "is_urban"
hsonne Mar 7, 2024
20c51df
Rename "ep_year" to "epot_year"
hsonne Mar 7, 2024
ab6b990
Rename "yield" to "veg_class"
hsonne Mar 7, 2024
bd5c660
Rename BERLIN_TYPES_TO_USAGE_YIELD_IRRIGATION
hsonne Mar 7, 2024
feb5dd1
Use land_type, veg_class consistently
hsonne Mar 7, 2024
df57255
Slightly improve argument description
hsonne Mar 7, 2024
b2a1eed
Rename stop_on_invalid_input() to ..._data()
hsonne Mar 7, 2024
e5a2cba
Do not check for a specific column any more
hsonne Mar 7, 2024
dd9a0d5
Slightly improve documentation, add example
hsonne Mar 7, 2024
80e2865
Rename fetch_input() to fetch_data()
hsonne Mar 7, 2024
7b515c4
Use helper variable "rpot"
hsonne Mar 7, 2024
2ba649c
Calculate DeltaW for clickdummy
f-delpu Mar 11, 2024
926810b
Compare R-Abimo results with Abimo results
hsonne Mar 11, 2024
fd0a99b
Update Rd file
hsonne Mar 18, 2024
d77d1ad
Use accessor function, correct variable name
hsonne Mar 18, 2024
09a145a
Name/order variables according to arguments
hsonne Mar 18, 2024
221e318
Name file according to contained function
hsonne Mar 18, 2024
f2fece1
Remove "_TAS" from potential_capillary_rise_TAS
hsonne Mar 18, 2024
8be3ec5
Rename usage(s) to land_type(s)
hsonne Mar 18, 2024
bd154ea
Consistently use accessor functions
hsonne Mar 18, 2024
0062584
Rename r_pot to rpot (similar to epot)
hsonne Mar 18, 2024
e05c57b
Rename isDrySummer() to is_dry_summer()
hsonne Mar 18, 2024
ef379e0
Move call_with_data to kwb.utils
hsonne Mar 18, 2024
65a041f
Move functions to kwb.utils
hsonne Mar 18, 2024
39a3a73
Improve spacing in get_climate.R
hsonne Mar 18, 2024
b599ad8
Move get_potential_evaporation()
hsonne Mar 18, 2024
76a6cfa
Move get_climate() to run_rabimo.R
hsonne Mar 18, 2024
191f2f1
Remove get_precipitation(), not used any more
hsonne Mar 18, 2024
ddbda0c
Move get_usage_tuple() to prepare_input_data.R
hsonne Mar 18, 2024
161e8fb
Add a comment as a reminder
hsonne Mar 18, 2024
0eaaa7b
Move yearly_height_to_volume_flow()
hsonne Mar 18, 2024
d5a1af0
Move all plot-related functions to plot_block.R
hsonne Mar 18, 2024
cde7c1c
Put into one line what fits into one line
hsonne Mar 18, 2024
2f6d947
Merge pull request #20 from KWB-R/clean-restructure
hsonne Mar 19, 2024
5c2d925
Delete part for AMAREX Workshop
f-delpu Mar 20, 2024
b1dff78
Delete local path to 2020 data
f-delpu Mar 20, 2024
2d6ed70
Read 2020 data as provided by Berlin Senate
f-delpu Mar 20, 2024
927aae7
Set colnames to upper case to match 2019 format
f-delpu Mar 20, 2024
02e8267
Continue adapting code to aw 2020 Berlin data
f-delpu Mar 21, 2024
22a3cfa
Check only required columns for NA in num cols
hsonne Mar 22, 2024
5be67e8
Add identify_data_format_or_stop()
hsonne Mar 22, 2024
e0b07c5
Remove rows with NA in groundwater distance
hsonne Mar 22, 2024
04118c6
add new surface class 5 to the check
f-delpu Mar 25, 2024
3293925
add surface class 5
f-delpu Mar 25, 2024
1a68a35
Rename prepare_berlin_data to prepare_berlin_inputs
f-delpu Mar 26, 2024
2266954
Add surface class 5 to config, prepare and run func
f-delpu Mar 26, 2024
02a3d3b
Rename also Rd-File
f-delpu Mar 26, 2024
3161905
Correct surface classes in prepare_input_data()
f-delpu Mar 26, 2024
05fa83b
rename function in NAMESPACE
f-delpu Mar 26, 2024
57480dc
Add comparison with old abimo results
f-delpu Mar 26, 2024
49475a6
Make R CMD check happy
hsonne Apr 2, 2024
f66976a
Combine 2 set_columns_to_zero_where_na() calls
hsonne Apr 2, 2024
cf03846
Reorganise the pipe
hsonne Apr 2, 2024
fdf33e8
Slightly clean prepare_input_data.R
hsonne Apr 2, 2024
d87b931
Get rid of intermediate var. "pot_evaporation"
hsonne Apr 2, 2024
4c2f835
Use new pattern functions and matching_names()
hsonne Apr 2, 2024
7be08eb
Use new function fetch_climate() and add spaces
hsonne Apr 2, 2024
054e3fd
Reuse matching_names() and pattern_[no]_roads()
hsonne Apr 2, 2024
e067662
Merge pull request #21 from KWB-R/fit_for_20
hsonne Apr 2, 2024
876dc6e
Require the dev version of kwb.abimo
hsonne Apr 2, 2024
57fc0eb
Merge pull request #16 from KWB-R/restructure
hsonne Apr 2, 2024
5f11b5e
Create new test script
f-delpu Apr 3, 2024
b55bfee
Save 2020 rabimo inputs in Package
f-delpu Apr 4, 2024
4e05aac
Consider green roofs in Rabimo calculation
f-delpu Apr 4, 2024
bd97e58
Add empty green-roof column to prepare_input_data()
f-delpu Apr 4, 2024
72cdf42
Clean and comment test script
f-delpu Apr 4, 2024
95d8e4f
Add definition of parameter "sealed"
f-delpu Apr 5, 2024
096cfca
Add WSUD in config
f-delpu Apr 5, 2024
bb684cd
Add empty to_swale column to prepared berlin data
f-delpu Apr 5, 2024
4f60c19
Consider swales' effects on water balance
f-delpu Apr 5, 2024
38d7a55
Update 2020 data and column-names.csv with WSUD
f-delpu Apr 5, 2024
f9bb4bf
Test R-ABIMO considering Swales and compare results
f-delpu Apr 5, 2024
9489b57
Delete correction Config as already in prepare func.
f-delpu Apr 8, 2024
378837c
Add check switch to docu
f-delpu Apr 10, 2024
486844e
Function to generate an area with default values
f-delpu Apr 10, 2024
59dc4dc
Correct access to swale evaporation factor
f-delpu Apr 11, 2024
08bb8ff
Correct order of assignments
f-delpu Apr 11, 2024
5538d7a
Script for Storm-Water management calibration
f-delpu Apr 11, 2024
4bdadb5
Add function to get R-ABIMO results as fractions
f-delpu Apr 11, 2024
18a34e5
Reorganize script and compare different areas
f-delpu Apr 12, 2024
67d1a8f
Update NAMESPACE and DESCRIPTION
f-delpu Apr 12, 2024
0f87330
Estimate Swale Area with a function
f-delpu Apr 12, 2024
37b3bbf
Generate manuals
f-delpu May 2, 2024
973a1ab
Update manuals
f-delpu May 2, 2024
7d4135e
Add script to describe rabimo_inputs_2020
f-delpu May 2, 2024
1c6fc8f
Add documentation for read_column_info()
f-delpu May 2, 2024
75e1a8e
Update test functions
f-delpu May 2, 2024
37da149
Cache 2020 inputs and minor corrections
f-delpu May 2, 2024
12c9d36
Do minor changes for documentation
f-delpu May 2, 2024
f1f2c4a
Change output format and add intermediate switch
f-delpu May 2, 2024
3d6e03f
Correct area fraction connected to swale
f-delpu May 2, 2024
e3eebd5
Add export of read_column_info function
f-delpu May 2, 2024
60972d1
Correct access to config and remove result column
f-delpu May 2, 2024
53225c5
Add intermediat variable in the run_rabimo() call
f-delpu May 2, 2024
27b7e6d
Cache 2020 results
f-delpu May 3, 2024
34cff2b
Add script for natural scenario and DeltaW analysis
f-delpu May 3, 2024
74de6c9
Write function to make dataset "natural"
f-delpu May 6, 2024
03e6cc0
Move natural scenario file to R folder
f-delpu May 6, 2024
ce8f05f
Add manuals for new functions
f-delpu May 8, 2024
0d20661
Clean script from testing part
f-delpu May 8, 2024
2253ba1
Make surface Class 5 required for both data formats
f-delpu May 8, 2024
3b24db2
Avoid repetition
f-delpu May 8, 2024
7aea821
Add test script for natural scenario and delta-W
f-delpu May 8, 2024
af9ffba
Update Manuals
f-delpu May 8, 2024
a92374d
Add alternative version of calculate_delta_w()
f-delpu May 8, 2024
603fa36
Update Namespace
f-delpu May 8, 2024
0715093
Simplify output names deleting: "total_"
f-delpu May 8, 2024
8237225
Rename result columns
f-delpu May 15, 2024
cf0b01a
Correct syntax
f-delpu May 15, 2024
2d43b3d
Add function calculate_delta_mod
f-delpu May 15, 2024
426dfd0
Add attribute code_column_name
f-delpu May 15, 2024
0074c67
Use ".data" to get rid of R CMD check warning
hsonne May 16, 2024
fbd515c
Fix double quotes in row of column-names.csv
hsonne May 16, 2024
e4905fb
Fix merge conflict in column-names.csv
hsonne May 16, 2024
408caf0
Use the base intersect() function
hsonne May 16, 2024
7e4b9a7
Finish the merge that resulted in a conflict
hsonne May 16, 2024
0b3e65f
Add a test to detect invalid CSV rows
hsonne May 16, 2024
72ec5b3
Expect column "srf5_pvd" to be created
hsonne May 16, 2024
aba07fc
Move test code to dedicated test function
hsonne May 16, 2024
5255bc4
Remove depencency on dplyr, use create_accessor()
hsonne May 16, 2024
a157e18
Move test function the right place
hsonne May 16, 2024
5534947
Expect "mm" as integer and not as numeric
hsonne May 17, 2024
313a191
Rename argument "input" to "data"
hsonne May 17, 2024
2b90fe9
Add argument "dbg"
hsonne May 17, 2024
2401b2c
Reuse stop_on_invalid_data() to check data format
hsonne May 17, 2024
95eb3af
Use function to convert data to expected types
hsonne May 17, 2024
47bec1f
Update Rd file
hsonne May 17, 2024
e14a1b8
Add (pseudo) test functions
hsonne May 17, 2024
ae498ea
Merge get_expected_data_type(), ..._types()
hsonne May 17, 2024
231fc6d
Integrate two functions into one new function
hsonne May 17, 2024
3faa79c
Merge pull request #23 from KWB-R/review-hauke
hsonne May 17, 2024
5463e01
Omit intermediate variable "data_types"
hsonne May 17, 2024
a8285b2
Be explicit about the type
hsonne May 17, 2024
1780951
Simplify pattern composition, add spaces
hsonne May 17, 2024
433c21a
Improve readability of test
hsonne May 17, 2024
21e2e33
Improve indentation
hsonne May 17, 2024
cd4f0cc
Merge comments
hsonne May 17, 2024
ec1893a
Do not check the vector lengths
hsonne May 17, 2024
e1e12df
Update data types in "rabimo_inputs_2020"
hsonne May 17, 2024
044ae1a
Reactivate the checks and cache within the pipe
hsonne May 17, 2024
606436a
Start to clean "test-natural.R", benchmark dW
hsonne May 17, 2024
74372ed
Add a third version of calculate_delta_W()
hsonne May 17, 2024
7986b08
Let calculate_delta_W() be a wrapper
hsonne May 17, 2024
54082c3
Merge pull request #22 from KWB-R/storm
hsonne May 17, 2024
9f63564
Rename "water_balance_vars"
hsonne May 18, 2024
1aa45c7
Remove empty line
hsonne May 18, 2024
3428917
Clean calculate_delta_W_3
hsonne May 18, 2024
87c35d3
Rename all delta_W to delta_w (lower case W)
hsonne May 18, 2024
3fd366d
Try to fix GH action
hsonne May 18, 2024
dc46500
Merge pull request #24 from KWB-R/clean
hsonne May 18, 2024
d22b260
Simplify installation section of README file
hsonne May 18, 2024
9765325
Empty commit to trigger the workflows
hsonne May 18, 2024
ed8b941
Update the README file (was outdated)
hsonne May 18, 2024
7752d50
Use new argument "controls" in run_rabimo()
hsonne May 19, 2024
1dc0047
Use define_controls()
hsonne May 19, 2024
d05f1ac
Merge pull request #25 from KWB-R/update-readme
hsonne May 19, 2024
d7aac8b
Merge branch 'dev' into use-controls-argument
hsonne May 19, 2024
d81ad53
Use specific controls replacing "simulate_abimo"
hsonne May 19, 2024
9c1f866
Merge pull request #26 from KWB-R/use-controls-argument
hsonne May 19, 2024
1200023
Do not pass "controls" (use the default)
hsonne May 19, 2024
4eec2d4
Move scripts to subfolder script one level up
hsonne May 21, 2024
417ee46
Remove code for debugging within "if (FALSE)"
hsonne May 21, 2024
a2bddba
Implement a simple test
hsonne May 21, 2024
93511aa
Adapt test scripts to new argument list
hsonne May 21, 2024
8b56460
Correct README
f-delpu May 21, 2024
d25f41a
Simplify access to column and exclude waterbodies
f-delpu May 21, 2024
47e9f21
Update plumber interface to be shown to TSB
hsonne May 27, 2024
dae8c79
Move WABILA-related functions into the package
hsonne Jun 7, 2024
0654b2f
Add Philipps calibration script (wabila)
Jun 10, 2024
c45bfde
Move calculate_delta_mod() into the package
Jun 10, 2024
36a15f8
Everything inside the package
pmoevius Jun 10, 2024
9dc2576
Merge pull request #27 from pmoevius/add-functions-for-calibration
hsonne Jun 10, 2024
6fd5686
Merge pull request #28 from KWB-R/add-functions-for-calibration
hsonne Jun 10, 2024
f51f427
Replicate Validation though IW with R-ABIMO
f-delpu Jun 24, 2024
33c1e76
Add climate Data 2015-2021 for validation
f-delpu Jun 24, 2024
0a067fe
Consider new changes in data set columns
f-delpu Jun 24, 2024
284c7dd
Save corrected data from SenStadt
f-delpu Jun 24, 2024
af7e317
Start to adapt column names to 10 char max #29
hsonne Jun 24, 2024
414b65d
Change column names in rabimo_inputs_2020
hsonne Jun 24, 2024
f289b71
Merge pull request #30 from KWB-R/reduce-var-names-to-10-chars
hsonne Jun 24, 2024
1af51a2
Depend on R >=3.5.0 as suggested by R CMD check
hsonne Jul 15, 2024
8ab636f
Make plot functions run again
hsonne Jul 15, 2024
f3aa51a
Start script to distribute measures to blocks
hsonne Jul 15, 2024
f253d4d
WIP
hsonne Jul 15, 2024
a15f4e1
Provide required input variables first
hsonne Jul 15, 2024
d20c6e4
Simplify
hsonne Jul 16, 2024
8f6b212
Add distribute_measures()
hsonne Jul 19, 2024
eb2b9a4
Validate update_measures() with Excel results
hsonne Jul 19, 2024
88f211c
Simplify code by using variables
hsonne Jul 19, 2024
7c16ee5
Improve title
hsonne Jul 19, 2024
d677baa
Merge pull request #31 from KWB-R/distribute-measures
f-delpu Jul 19, 2024
e2d1912
Correct swale function and export
f-delpu Jul 19, 2024
5d356ef
Expect targets to be a named vector, not a list
hsonne Jul 23, 2024
c805207
Allow to set target values in Excel file
hsonne Jul 23, 2024
b95a238
Check 1000 combinations of target values
hsonne Jul 23, 2024
b82f4a1
Calculate "sealed" within distribute_measures()
hsonne Jul 23, 2024
30e4511
Make column names part of the error message
hsonne Jul 30, 2024
c84f573
Update tests now that no output is produced
hsonne Jul 30, 2024
fc8cf34
Add script to calculate runoff volumes by waterbody
f-delpu Aug 9, 2024
0f40a20
Add function for rescaling measures (target values)
f-delpu Aug 12, 2024
a0ab3b5
Add function to rescale, distribute and run rabimo
f-delpu Aug 12, 2024
8dcc645
Change expression to make it work if sum is zero
f-delpu Aug 12, 2024
3b3e428
Round expressions to make them work with tiny deltas
f-delpu Aug 12, 2024
3061db1
Add equation for max allowed unpaved value
f-delpu Aug 12, 2024
8ca2299
Improve comments
hsonne Aug 15, 2024
74919f3
Move get_measure_stats_new() into the package
hsonne Aug 15, 2024
433b64d
Cross check results of different calculations
hsonne Aug 15, 2024
77918c5
Add argument sheet for xls table
f-delpu Aug 15, 2024
2636c59
Add manual for run_rabimo_with_measures()
f-delpu Aug 15, 2024
078f308
Resolve merge conflict
f-delpu Sep 2, 2024
2015e74
Update DESCRIPTION and NAMESPACE
f-delpu Sep 2, 2024
ea63b35
Add new calibration script and comparison function
f-delpu Sep 2, 2024
3d8b2e6
Fix documentation or run_rabimo_with_measures()
hsonne Sep 5, 2024
ba26238
Extend API function /run_rabimo
hsonne Sep 5, 2024
222d162
Add test_api() to run swagger via plumber
hsonne Sep 5, 2024
25b8d67
Rename output columns
hsonne Sep 5, 2024
b35b2cd
Let get_measure_stats() return a list of lists
hsonne Sep 5, 2024
5c35c21
Test slightly smaller values that max values
hsonne Sep 5, 2024
331925c
Add "weighted_means" to output
hsonne Sep 5, 2024
9fb70ae
Downgrade Roxygen
hsonne Sep 5, 2024
877b01c
Use helper variables "zeros", "tot_area"
hsonne Sep 5, 2024
9154254
Fix test
hsonne Sep 5, 2024
906b15e
Merge pull request #32 from KWB-R/rescale_and_distribute
hsonne Sep 5, 2024
ac5836b
Use "safety factor" to diminish max values
hsonne Sep 8, 2024
31b2f47
Add plot_triangle_of_fractions()
hsonne Sep 24, 2024
b4cf7b4
Use axis functions, add tick marks
hsonne Sep 26, 2024
0bd3907
Add endpoint /triangle to plumber API
hsonne Sep 26, 2024
a04f1bc
Fix :bug:
hsonne Sep 26, 2024
b1b482e
Visualise 2nd water balance and diff in triangle
hsonne Sep 30, 2024
6fd7268
Extend example
hsonne Sep 30, 2024
05d83a8
Make arrows slightly transparent, update API
hsonne Oct 1, 2024
615ee31
Fix bug in extimate_water_holding_capacity()
hsonne Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
restore-keys: ${{ runner.os }}-r-${{ matrix.config.r }}-3-

- name: Install system dependencies
if: runner.os == 'Linux'
if: runner.os == 'Linux (no, skip this!)'
env:
RHUB_PLATFORM: linux-x86_64-ubuntu-gcc
run: |
Expand Down
22 changes: 16 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: kwb.rabimo
Title: R Implementation of Water Balance Model Abimo
Version: 1.0.1
Version: 1.0.1.9000
Authors@R: c(
person("Hauke", "Sonnenberg", , "hauke.sonnenberg@kompetenz-wasser.de", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-9134-2871")),
Expand All @@ -15,17 +15,27 @@ URL: https://github.com/KWB-R/kwb.rabimo
BugReports: https://github.com/KWB-R/kwb.rabimo/issues
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
covr
covr,
ggplot2,
kwb.rect,
plumber,
testthat (>= 3.0.0)
Imports:
dplyr,
foreign,
kwb.abimo,
kwb.utils,
magrittr,
methods,
parallel,
rlang,
xml2
Remotes:
github::kwb-r/kwb.abimo,
github::kwb-r/kwb.utils
github::kwb-r/kwb.abimo@dev,
github::kwb-r/kwb.rect,
github::kwb-r/kwb.utils@dev
Config/testthat/edition: 3
Depends:
R (>= 3.5.0)
LazyData: true
29 changes: 24 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(BERLIN_TYPES_TO_USAGE_YIELD_IRRIGATION)
export(BERLIN_TYPES_TO_LAND_TYPE_VEG_CLASS_IRRIGATION)
export(abimo_config_to_config)
export(actual_evaporation_waterbody_or_pervious)
export(call_with_data)
export(calculate_delta_w)
export(data_to_natural)
export(define_controls)
export(distribute_measures)
export(generate_rabimo_area)
export(get_measure_stats)
export(get_potential_evaporation)
export(get_precipitation)
export(get_soil_properties)
export(get_usage_tuple)
export(index_string_to_integers)
export(list_to_data_frame_with_keys)
export(prepare_input_data)
export(plot_block)
export(plot_block_2)
export(prepare_berlin_inputs)
export(read_column_info)
export(real_evapo_transpiration)
export(run_rabimo)
export(run_rabimo_with_measures)
export(test_api)
export(triangle_of_fractions)
export(yearly_height_to_volume_flow)
importFrom(dplyr,left_join)
importFrom(kwb.utils,catAndRun)
Expand All @@ -25,20 +35,29 @@ importFrom(kwb.utils,getAttribute)
importFrom(kwb.utils,inRange)
importFrom(kwb.utils,moveColumnsToFront)
importFrom(kwb.utils,multiColumnLookup)
importFrom(kwb.utils,multiSubstitute)
importFrom(kwb.utils,pasteColumns)
importFrom(kwb.utils,printIf)
importFrom(kwb.utils,removeColumns)
importFrom(kwb.utils,removeElements)
importFrom(kwb.utils,renameAndSelect)
importFrom(kwb.utils,renameColumns)
importFrom(kwb.utils,resetRowNames)
importFrom(kwb.utils,right)
importFrom(kwb.utils,safePath)
importFrom(kwb.utils,safeRowBindAll)
importFrom(kwb.utils,selectColumns)
importFrom(kwb.utils,selectElements)
importFrom(kwb.utils,stopFormatted)
importFrom(kwb.utils,stringList)
importFrom(kwb.utils,substSpecialChars)
importFrom(kwb.utils,toLookupList)
importFrom(magrittr,"%>%")
importFrom(methods,formalArgs)
importFrom(parallel,detectCores)
importFrom(parallel,makeCluster)
importFrom(parallel,parLapply)
importFrom(parallel,stopCluster)
importFrom(rlang,.data)
importFrom(stats,approx)
importFrom(stats,setNames)
importFrom(utils,globalVariables)
189 changes: 104 additions & 85 deletions R/abimo_config_to_config.R
Original file line number Diff line number Diff line change
@@ -1,100 +1,92 @@
#' Convert Abimo Configuration to List
#'
#' @param abimo_config as returned by \code{kwb.abimo:::read_config}
#' @return list with elements \code{"potential_evaporation"},
#' \code{"runoff_factors"}, \code{"bagrov_values"}, \code{"diverse"},
#' \code{"result_digits"}
#' @param abimo_config as returned by \code{kwb.abimo::read_config}
#' @param add_class_5 logical indicating whether or not to add fields for a
#' fifth surface class. The default is \code{FALSE}.
#' @return list with elements
#' \code{"potential_evaporation"},
#' \code{"runoff_factors"},
#' \code{"bagrov_values"},
#' \code{"result_digits"},
#' \code{"precipitation_correction_factor"},
#' \code{"irrigation_to_zero"}
#' @export
abimo_config_to_config <- function(abimo_config)
#' @examples
#' str(kwb.rabimo::abimo_config_to_config(kwb.abimo::read_config()))
abimo_config_to_config <- function(abimo_config, add_class_5 = FALSE)
{
# abimo_config <- kwb.abimo:::read_config()
#abimo_config <- kwb.abimo::read_config()
#`%>%` <- magrittr::`%>%`
#kwb.utils::assignPackageObjects("kwb.rabimo")

prefix <- "section_"
result <- abimo_config[startsWith(names(abimo_config), prefix)] %>%
set_names(remove_left(names(.), nchar(prefix))) %>%
lapply(function(x) {
filter_elements(x, "^item_") %>%
lapply(function(y) {
do.call(data.frame, as.list(xml2::xml_attrs(y)))
}) %>%
list_to_data_frame_with_keys("item", "item_(.*)")
})

epot_water <- "Gewaesserverdunstung"
epot_else <- "PotentielleVerdunstung"

extract_epot <- function(element, is_waterbody, renamings = NULL, ...) {
result %>%
select_elements(element) %>%
expand_district_ranges() %>%
lapply(as.integer) %>%
as.data.frame() %>%
rename_columns(renamings) %>%
{cbind.data.frame(is_waterbody = is_waterbody, ., ...)}
}

section_pattern <- "^section_"

result <- abimo_config %>%
filter_elements(section_pattern) %>%
lapply(get_all_item_data)

names(result) <- gsub(section_pattern, "", names(result))

element_water <- "Gewaesserverdunstung"
element_else <- "PotentielleVerdunstung"

all_columns_to_int <- function(x) as.data.frame(lapply(x, as.integer))

evap_water <- result %>%
select_elements(element_water) %>%
expand_district_ranges() %>%
all_columns_to_int() %>%
rename_columns(list(eg = "etp")) %>%
cbind(etps = 0, is_waterbody = TRUE)

evap_else <- result %>%
select_elements(element_else) %>%
expand_district_ranges() %>%
all_columns_to_int() %>%
cbind(is_waterbody = FALSE)

result[["potential_evaporation"]] <- rbind(evap_water, evap_else) %>%
move_columns_to_front("is_waterbody")
result[["potential_evaporation"]] <- rbind(
extract_epot(epot_water, TRUE, list(eg = "etp"), etps = 0),
extract_epot(epot_else, FALSE)
)

convert_element <- function(config, from, to, convert = identity) {
x <- select_elements(config, from)
config[[to]] <- stats::setNames(
convert(select_columns(x, "value")),
select_columns(x, "key")
)
value <- convert(select_columns(x, "value"))
key <- select_columns(x, "key")
config[[to]] <- set_names(value, key)
remove_elements(config, from)
}

result <- result %>%
remove_elements(c(
element_water,
element_else
)) %>%
convert_element(
from = "Infiltrationsfaktoren",
to = "runoff_factors",
convert = function(x) 1 - as.numeric(x)
) %>%
convert_element(
from = "Bagrovwerte",
to = "bagrov_values",
convert = as.numeric
) %>%
convert_element(
from = "Diverse",
to = "diverse"
) %>%
convert_element(
from = "ErgebnisNachkommaStellen",
to = "result_digits",
convert = as.numeric
)

result[["precipitation_correction_factor"]] <- as.numeric(
select_elements(result, "diverse")[["NIEDKORRF"]]
)
complement <- function(x) 1 - as.numeric(x)

result
}

# get_all_item_data ------------------------------------------------------------
get_all_item_data <- function(x)
{
get_attribute_data <- function(x) {
values <- xml2::xml_attrs(x)
do.call(data.frame, as.list(values))
}

get_item_data <- function(x) {
list_to_data_frame_with_keys(x, "item", "item_(.*)")
result <- result %>%
remove_elements(c(epot_water, epot_else)) %>%
convert_element("Infiltrationsfaktoren", "runoff_factors", complement) %>%
convert_element("Bagrovwerte", "bagrov_values", as.numeric) %>%
convert_element("Diverse", "diverse") %>%
convert_element("ErgebnisNachkommaStellen", "result_digits", as.numeric)

# Convert types of "diverse" entries and shift them up to the main level
diverse <- "diverse"
x <- select_elements(result, diverse)
result[["precipitation_correction_factor"]] <- as.numeric(x[["NIEDKORRF"]])
result[["irrigation_to_zero"]] <- as.logical(x[["BERtoZero"]])
result <- remove_elements(result, diverse)

# Clean names for two sections
keys <- c("runoff_factors", "bagrov_values")
result[keys] <- lapply(result[keys], function(x) {
set_names(x, multi_substitute(names(x), list(
Dachflaechen = "roof",
Belaglsklasse = "surface"
)))
})

if (add_class_5) {
result$runoff_factors <- c(result$runoff_factors, surface5 = 0.48)
result$bagrov_values <- c(result$bagrov_values, surface5 = 0.25)
}

filter_elements(x, "^item_") %>%
lapply(get_attribute_data) %>%
get_item_data()
result
}

# expand_district_ranges -------------------------------------------------------
Expand All @@ -110,9 +102,36 @@ expand_district_ranges <- function(
remove_columns(c("item", range_column)) %>%
move_columns_to_front(district_column)

stopifnot(
!anyDuplicated(select_columns(x, district_column))
)
stopifnot(!anyDuplicated(select_columns(x, district_column)))

x
}

# expand_ranges_in_column ------------------------------------------------------
expand_ranges_in_column <- function(x, range_column, index_column)
{
# Split data frame into a list of rows
data_rows <- unname(split(x, seq_len(nrow(x))))

# Expand each row with a range string in column according to the ranges
do.call(rbind, unname(lapply(data_rows, function(data_row) {

range_string <- select_columns(data_row, range_column)

# Determine the indices that are described by the range string
indices <- if (is.na(range_string)) {
NA
} else {
index_string_to_integers(range_string)
}

# Repeat the current row for each of these indices
result <- data_row[rep.int(1L, length(indices)), ]

# Append a column with these indices
result[[index_column]] <- indices

# Return the data frame
result
})))
}
Loading
Loading