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

feat!: D-infinity and terra instead of D8 and raster #23

Merged
merged 93 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
504f102
update DEMrelatedInput()
gisler May 20, 2024
ad2ec60
small addition
gisler May 20, 2024
d9f1e2e
fix from main
gisler Jun 1, 2024
ee42851
Merge branch 'main' into dinf
gisler Jun 1, 2024
ae87c43
simplify code
gisler Jun 1, 2024
44fb547
temp
gisler Jun 1, 2024
0e01fe9
fix
gisler Jun 1, 2024
65213cf
optimisations
gisler Jun 1, 2024
27cedab
implement movingWindow
gisler Jun 1, 2024
31e1a26
save state
gisler Jun 2, 2024
1f2b70a
theoretically done
gisler Jun 2, 2024
b7f7437
3rd best option works
gisler Jun 3, 2024
67bdc51
dinf and slope of outlets missing
gisler Jun 3, 2024
39e8004
DInfSlope probably not correct
gisler Jun 4, 2024
2e390a0
0 indexing bug fixed
gisler Jun 5, 2024
7f2eb88
some polishing
gisler Jun 6, 2024
e5db65c
add template
gisler Jun 6, 2024
ab6a8ef
update classes
gisler Jun 8, 2024
e8d4087
L factor missing
gisler Jun 8, 2024
d89d871
rm transportCalcOrder
gisler Jun 8, 2024
2e96b8e
rm parameter
gisler Jun 8, 2024
2533ddd
improve docs
gisler Jul 4, 2024
cee0028
refactor
gisler Jul 4, 2024
4501127
add fD8
gisler Jul 4, 2024
0939b07
some improvements
gisler Jul 7, 2024
ac75347
alter erosionPrerequisites
gisler Jul 7, 2024
fcc2084
alter transportPrerequisites
gisler Jul 7, 2024
a1b3235
check for -1.0
gisler Jul 7, 2024
f54b746
use original dem again
gisler Jul 8, 2024
4d1c5b6
refactor
gisler Jul 9, 2024
bc8c9d3
calculate proportions
gisler Jul 10, 2024
4faf7a9
should not be necessary
gisler Jul 10, 2024
8f07c14
basics
gisler Jul 12, 2024
15e423e
function to get inflow proportions
gisler Jul 12, 2024
63a4292
rename
gisler Jul 12, 2024
301541f
start with transport
gisler Jul 12, 2024
f4f809f
number of inflowing cells
gisler Jul 12, 2024
d6473d7
transport calculation order
gisler Jul 12, 2024
e1ffefa
move variable declarations
gisler Jul 13, 2024
c92562a
refactor
gisler Jul 14, 2024
3b0b1a7
fix
gisler Jul 14, 2024
d3a3daa
rm rl_rhy
gisler Jul 15, 2024
c615f0e
fix possible race condition
gisler Jul 15, 2024
56d7166
several improvements and fixes
gisler Jul 15, 2024
58c0074
add warning (no good solution)
gisler Jul 15, 2024
403429f
small fix
gisler Jul 15, 2024
787cef6
improvements
gisler Jul 15, 2024
53b586a
pass int, double by value
gisler Jul 18, 2024
e0f336f
finished first part of transport
gisler Jul 18, 2024
4a23e8f
several improvements and fixes
gisler Jul 20, 2024
007e118
rename
gisler Jul 20, 2024
f2a16be
use list initialisation
gisler Jul 20, 2024
9da13f5
more preparations
gisler Jul 20, 2024
5e731f5
insert space before {
gisler Jul 20, 2024
1711e8e
guard for NA values
gisler Jul 20, 2024
c12b4f8
done with transport
gisler Jul 20, 2024
4d0f3cc
several improvements
gisler Jul 20, 2024
3427053
default ns_slp_min to 1.0
gisler Jul 21, 2024
91144b0
model improvements
gisler Jul 21, 2024
fb8ee47
many small improvements
gisler Jul 21, 2024
05023ed
focal apportionment missing
gisler Jul 22, 2024
bdc24d0
style
gisler Jul 22, 2024
f8bd069
fix saveState
gisler Jul 23, 2024
ee1c2fd
improved riparian as well as inlet cells
gisler Jul 23, 2024
a69911b
cld and ctf more or less finished
gisler Jul 23, 2024
f9d7c67
presumbly done
gisler Jul 24, 2024
32605a3
done
gisler Jul 24, 2024
c9df11f
whitespace
gisler Jul 24, 2024
b001121
code for debugging etc.
gisler Jul 24, 2024
0c99e30
add (weighted)
gisler Jul 25, 2024
7cdee19
Revert "add (weighted)"
gisler Jul 26, 2024
b72aacf
no (weighted)
gisler Jul 26, 2024
27e2257
whitespace change
gisler Aug 19, 2024
b27ceb1
bump version
gisler Aug 21, 2024
58c9573
i to u
gisler Sep 2, 2024
bb2a3b5
fix: rip and out are "local" emissions
gisler Sep 2, 2024
3fa9de9
correct documentation
gisler Sep 12, 2024
e31ed3c
updated description
gisler Nov 4, 2024
1e55156
conditional debugging
gisler Nov 28, 2024
7a31c4c
backward compatibility of parameters.yaml
gisler Nov 28, 2024
616f4dc
fix: transport instead of retention
gisler Nov 28, 2024
bf76a64
return invisible
gisler Nov 28, 2024
9b5b85c
keep "original" transfer coefficients
gisler Nov 28, 2024
06797b0
NSE to KGE
gisler Nov 28, 2024
f83cf9e
update test data
gisler Nov 28, 2024
491edfe
fix folder
gisler Nov 28, 2024
e454b9a
fix example
gisler Nov 28, 2024
52b2021
fix test
gisler Nov 28, 2024
162ee71
add inl (used to by rhy)
gisler Nov 30, 2024
420913c
add tests
gisler Nov 30, 2024
5b2288c
refactor: loop counting down
gisler Dec 5, 2024
9aa6da2
improve news
gisler Dec 5, 2024
01f3117
done with NEWS
gisler Dec 15, 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
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
Package: RPhosFate
Type: Package
Title: Soil and Chemical Substance Emission and Transport Model
Version: 1.0.4.9000
Version: 1.0.4.9004
Authors@R: person("Gerold", "Hepp", email = "[email protected]", role = c("aut", "cre"))
Description: An enhanced version of the semi-empirical, spatially distributed
emission and transport model PhosFate implemented in 'R' and 'C++'. It
currently supports suspended solids (SS) and particulate phosphorus (PP). A
major feature is the allocation of substance loads entering surface waters
to their sources of origin, which is a basic requirement for the
emission and transport model PhosFate implemented in 'R' and 'C++'. It is
based on the D-infinity, but also supports the D8 flow method. The currently
available substances are suspended solids (SS) and particulate phosphorus
(PP). A major feature is the allocation of substance loads entering surface
waters to their sources of origin, which is a basic requirement for the
identification of critical source areas and in consequence a cost-effective
implementation of mitigation measures. References: Hepp et al. (2022)
<doi:10.1016/j.jenvman.2022.114514>; Hepp and Zessner (2019)
Expand Down Expand Up @@ -40,7 +41,7 @@ Suggests:
LinkingTo:
Rcpp,
RcppArmadillo
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
Collate:
Expand Down
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export(setParameter)
export(snapGauges)
export(subsequentRun)
export(transport)
export(transportCalcOrder)
export(transportPrerequisites)
exportClasses(RPhosFate)
exportMethods("[")
Expand All @@ -37,7 +36,6 @@ exportMethods(setParameter)
exportMethods(snapGauges)
exportMethods(subsequentRun)
exportMethods(transport)
exportMethods(transportCalcOrder)
exportMethods(transportPrerequisites)
import(checkmate)
import(methods)
Expand Down
49 changes: 37 additions & 12 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
# RPhosFate v1.0.4.9000
# RPhosFate v1.0.4.9004

* Switched to utilising the `SpatRaster` and `SpatVector` classes from the `terra` package instead of the `RasterLayer` class from the `raster` and the `Spatial*DataFrame` classes from the `sp` packages.
* Added `ns_cha` argument to `DEMrelatedInput()` function: allows for specifying the minimum (weighted) flow accumulation determining a channel.
* Added `is_ths` argument to `RPhosFate()` and `catchment()` constructors: allows for specifying the number of threads to use for processing, where applicable.
This version introduces several breaking changes into `RPhosFate`.

## Overview

* Use of the D-infinity instead of the D8 flow method, however, the D8 flow method can still be mimicked by rounding the D-infinity flow directions to the nearest multiple of 45 degrees.
* Weighted flow accumulations are no longer supported for the time being.
* The basis for the calculation of the D-infinity slopes is the original digital elevation model and not the breached one with reversed stream burning any longer.
* The default value for the parameter holding the minimum bounding slope _(ns\_slp_min)_ is now 1 instead of 0.001%.
* The L factor is now calculated using the original equation\ (9) developed by Desmet and Govers (1996) and not the adjusted one from Kovacs (2013).
* The channel retentions of the substance outlet loads of subsurface drainages are now calculated analogous to the overland retentions of the local emissions, i.e. by using half of the flow path lengths.
* `RPhosFate` now utilises the `terra` instead of the `raster` package.
* Ceased support for _ERDAS IMAGINE_ (\*.img) raster files. `img2tif()` can be used to convert all _ERDAS IMAGINE_ raster files in a directory and its subdirectories into _GeoTIFF_ raster files.
* Dropped backward compatibility to major version zero.

## Details

* Input data changes:
* Removed the layers holding the (weighted) D8 flow accumulations (_acc_ and _acc\_wtd_) and added _acc\_inf_ holding the D-infinity flow accumulations.
* Removed the layer holding the D8 flow directions _(dir)_ and added _dir\_inf_ holding the D-infinity flow directions.
* Removed the layer holding the D8 slopes _(slp)_ and added _slp\_inf_ holding the D-infinity slopes.
* `DEMrelatedInput()` function changes:
* Adjusted it to reflect the aforementioned input data changes.
* Added `ns_cha` argument to it: allows for specifying the minimum D8 flow accumulation determining a channel.
* Added `ls_fD8` argument to it: allows for mimicking D8 flow directions by rounding the D-infinity flow directions to the nearest multiple of 45 degrees. Please note that this treatment is always applied to channel cells independently of this argument.
* Removed the `cs_wgs` and `cs_dir` arguments from it: These input data are no longer supported for the time being.
* Switched to utilising the `SpatRaster` and `SpatVector` classes from the `terra` package instead of the `RasterLayer` class from the `raster` and the `Spatial*DataFrame` classes from the `sp` packages.
* Added `is_ths` argument to the `RPhosFate()` and `catchment()` constructors: allows for specifying the number of threads to use for processing, where applicable.
* Removed the layer holding the hydraulic radii _(rhy),_ as the calculation of the hydraulic radii is now integrated into the `transport()` method. This implies that the `transportPrerequisites()` method does not save it to disk any longer.
* Removed the parameter holding the D8 outflow direction vector _(iv\_fDo)._ Existing parameter files _(parameters.yaml)_ containing it can still be used, but the parameter is removed upon saving a project's state.
* Removed the `transportCalcOrder()` method, as the determination of the cell transport calculation order is now integrated into the `transport()` method. This implies that the `firstRun()` as well as `subsequentRun()` methods do not call it any longer and the `saveState()` method does not save the transport calculation order to disk any longer.
* The `calibrationQuality()` method now returns its return value invisibly.
* Considerably revised the internal `RPhosFateHelpers` class.
* Removed `spatstat.geom` from imported packages list (utilised functionality is now also provided by `terra`).
* Bumped minimum tested R version from 4.2.3 to 4.3.2 using the corresponding _Posit_ public package manager snapshot.
* Bumped the minimum tested R version from 4.2.3 to 4.3.2 using the corresponding _Posit_ public package manager snapshot.
* Slightly improved documentation.
* Major internal code improvements.

# RPhosFate v1.0.4

* The current `raster` package does not compress _GeoTIFF_ raster files any longer by default. This is probably due to the switch from `rgdal` to `terra` and has been fixed by generally using the _LZW_ algorithm.
* Fixed warning "GDAL Message 6: driver GTiff does not support creation option COMPRESSED" curiously only occurring in the reference on GitHub Pages.
* Removed `hydroGOF` from imported packages list (`maptools` is retiring and `hydroGOF` depends on it via `hydroTSM`). Thanks to Roger Bivand for raising this issue (#17).
* Bumped minimum tested R version from 4.2.2 to 4.2.3 using the corresponding _Posit_ public package manager snapshot.
* Bumped the minimum tested R version from 4.2.2 to 4.2.3 using the corresponding _Posit_ public package manager snapshot.
* Slightly improved documentation.

# RPhosFate v1.0.3

* Removed `rgdal` from suggested packages list and set minimum required version of the `raster` package to ≥ 3.6.3 (`rgdal` is retiring and `raster` ≥ 3.6.3 does not depend on it any longer). Thanks to Roger Bivand for raising this issue (#17).
* Bumped minimum tested R version from 4.1.2 to 4.2.2 using the corresponding _MRAN_ repository snapshot.
* Bumped the minimum tested R version from 4.1.2 to 4.2.2 using the corresponding _MRAN_ repository snapshot.
* Slightly improved documentation.
* Minor internal code improvements.

Expand Down Expand Up @@ -60,10 +85,10 @@

# RPhosFate v0.10.0

* `DEMrelatedInput()` function now calculates the slopes from the breached DEM (stream burning is undone beforehand).
* The `DEMrelatedInput()` function now calculates the slopes from the breached DEM (stream burning is undone beforehand).
* Switched to utilising _GeoTIFF_ (\*.tif) instead of _ERDAS IMAGINE_ (\*.img) raster files.
* Added `cs_fex` argument to `DEMrelatedInput()` function: allows for using _ERDAS IMAGINE_ raster files for backward compatibility.
* Added `cs_dir` argument to `DEMrelatedInput()` function: allows for utilising an existing D8 flow directions raster using _ArcGIS_ codes.
* Added `cs_fex` argument to the `DEMrelatedInput()` function: allows for using _ERDAS IMAGINE_ raster files for backward compatibility.
* Added `cs_dir` argument to the `DEMrelatedInput()` function: allows for utilising an existing D8 flow directions raster using _ArcGIS_ codes.
* Added `demoProject()` function providing training data.
* Added examples to documentation.
* Fixed backward incompatibility.
Expand Down
Loading
Loading