Skip to content

Commit 65319da

Browse files
Add KernelInterpolation.jl extension (#73)
* add KernelInterpolation.jl extension * add tests * define kernel separately to be able to overwrite with trixi_include * pass all kwargs in CubicBSpline * format * Apply suggestions from code review Co-authored-by: Andrew Winters <[email protected]> * shuffle input data in tests * actually run the tests * add KernelInterpolation to test project * add Random to test project * fix test * loosen tolerance * loosen tolerance more * add NEWS and README entries * use evaluate_two_dimensional_interpolant * fix link * fix another link * x- not y-direction * try to include extension docstrings into references * format * need to use Base.get_extension * load extensions * try listing functions of extensions explicitly * fix docstring of RBFInterpolation1D * add name to AUTHORS --------- Co-authored-by: Andrew Winters <[email protected]>
1 parent 4f54b78 commit 65319da

21 files changed

+292
-56
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ docs/src/changelog.md
1212
docs/src/code_of_conduct.md
1313
docs/src/contributing.md
1414
docs/src/index.md
15+
16+
.vscode/

AUTHORS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The following people contributed major additions or modifications to TrixiBottom
1818
are listed in alphabetical order:
1919

2020
* Maximilian D. Bertrand
21+
* Joshua Lampert
2122
* Hendrik Ranocha
2223
* Michael Schlottke-Lakemper
23-
* Andrew Winters
24+
* Andrew Winters

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ for human readability.
99

1010
#### Added
1111

12+
- Added scattered radial basis function interpolation using [KernelInterpolation.jl](https://github.com/JoshuaLampert/KernelInterpolation.jl) [#73]
1213
- Implementation of visualization routines `plot_topography` and `plot_topography_with_interpolation_knots`
1314

1415
#### Changed

Project.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1010
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1111

1212
[weakdeps]
13+
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
1314
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
1415

1516
[extensions]
16-
TrixiBottomTopographyMakieExt = "Makie"
17+
KernelInterpolationExt = "KernelInterpolation"
18+
MakieExt = "Makie"
1719

1820
[compat]
1921
Downloads = "1.6"
22+
KernelInterpolation = "0.3.5"
2023
LinearAlgebra = "1"
2124
Makie = "0.21, 0.22, 0.24"
2225
SparseArrays = "1"

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ TrixiBottomTopography.jl does this by B-spline interpolation of the underlying d
3333

3434
## Functionalities
3535

36-
This package contains the following three main functionalities:
36+
This package contains the following main functionalities:
3737
- Converting geographical data given in form of `.xyz` files, e.g., from the [DGM data set](https://www.opengeodata.nrw.de/produkte/geobasis/hm/) provided by [Geobasis NRW](https://www.bezreg-koeln.nrw.de/geobasis-nrw) to make it readable for TrixiBottomTopography.jl
3838
- Setting up a B-spline interpolation structure in one and two dimensions which contains all the relevant information to define a B-spline interpolation function with additional specifications
3939
- Using the B-spline structure to set up a B-spline interpolation function
40+
- Setting up a radial basis function interpolation based on scattered data leveraging [KernelInterpolation.jl](https://github.com/JoshuaLampert/KernelInterpolation.jl)
4041

4142
A detailed description of the functionalities can be found in the [documentation](https://trixi-framework.github.io/TrixiBottomTopography.jl/stable/) to this package.
4243

@@ -125,4 +126,4 @@ The full list of contributors can be found in [AUTHORS.md](AUTHORS.md).
125126

126127
## License and contributing
127128
TrixiBottomTopography.jl is published under the MIT license (see [LICENSE.md](LICENSE.md)).
128-
We are pleased to accept contributions from everyone, preferably in the form of a PR.
129+
We are pleased to accept contributions from everyone, preferably in the form of a PR.

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
33
Changelog = "5217a498-cd5d-4ec6-b8c2-9b85a09b6e3e"
44
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
5+
KernelInterpolation = "95686e15-3c94-4443-8f08-76d06d509f7b"
56
OrdinaryDiffEqLowStorageRK = "b0944070-b475-4768-8dec-fb6eb410534d"
67
Trixi = "a7f1ee26-1774-49b1-8366-f1abc58fbfcb"
78
TrixiBottomTopography = "86af9953-43df-404b-8eaa-d20d82623a82"
@@ -14,6 +15,7 @@ path = ".."
1415
CairoMakie = "0.13, 0.15"
1516
Changelog = "1.1"
1617
Documenter = "1.3"
18+
KernelInterpolation = "0.3.5"
1719
OrdinaryDiffEqLowStorageRK = "1.3"
1820
Trixi = "0.12, 0.13"
1921
TrixiShallowWater = "0.2"

docs/make.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ using Documenter
22
import Pkg
33
using TrixiBottomTopography
44
using Changelog: Changelog
5+
# To load the extensions
6+
import CairoMakie
7+
import KernelInterpolation
58

69
# Copy list of authors to not need to synchronize it manually.
710
# Since the authors header exists twice we create a unique identifier for the docs section.
@@ -89,7 +92,9 @@ rm(joinpath(@__DIR__, "src", "changelog_tmp.md"))
8992

9093
# Make documentation
9194
makedocs(;
92-
modules = [TrixiBottomTopography],
95+
modules = [TrixiBottomTopography,
96+
Base.get_extension(TrixiBottomTopography, :MakieExt),
97+
Base.get_extension(TrixiBottomTopography, :KernelInterpolationExt)],
9398
authors = "Andrew R. Winters <[email protected]>, Michael Schlottke-Lakemper <[email protected]>",
9499
sitename = "TrixiBottomTopography.jl",
95100
format = Documenter.HTML(;
@@ -110,12 +115,12 @@ makedocs(;
110115
"Advanced topics & developers" => ["Development" => "development.md",
111116
"Style guide" => "styleguide.md",
112117
"Testing" => "testing.md"],
118+
"Reference" => "reference.md",
113119
"Changelog" => "changelog.md",
114120
"Authors" => "authors.md",
115121
"Contributing" => "contributing.md",
116122
"Code of Conduct" => "code_of_conduct.md",
117-
"License" => "license.md",
118-
"Reference" => "reference.md"])
123+
"License" => "license.md"])
119124

120125
# Documenter can also automatically deploy documentation to gh-pages.
121126
# See "Hosting Documentation" and deploydocs() in the Documenter manual

docs/src/reference.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,19 @@ CurrentModule = TrixiBottomTopography
77
```@autodocs
88
Modules = [TrixiBottomTopography]
99
```
10+
11+
## Makie.jl extension
12+
13+
```@docs
14+
TrixiBottomTopography.evaluate_two_dimensional_interpolant
15+
TrixiBottomTopography.plot_topography
16+
TrixiBottomTopography.plot_topography_with_interpolation_knots
17+
```
18+
19+
## KernelInterpolation.jl extension
20+
21+
```@docs
22+
TrixiBottomTopography.RBFInterpolation
23+
TrixiBottomTopography.RBFInterpolation1D
24+
TrixiBottomTopography.RBFInterpolation2D
25+
```

examples/rhine_data_rbf_1d.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
###############################################################################
2+
# Script which uses the functionalities implemented in TrixiBottomTopography #
3+
# to plot a one dimensional RBF interpolated section of the Rhine river with #
4+
# data extracted along the x-direction. #
5+
###############################################################################
6+
7+
# Include packages
8+
using TrixiBottomTopography
9+
using KernelInterpolation
10+
11+
# Define data path
12+
root_dir = pkgdir(TrixiBottomTopography)
13+
data = joinpath(root_dir, "examples", "data", "rhine_data_1d_20_x.txt")
14+
15+
# Define RBF structure
16+
kernel = ThinPlateSplineKernel{1}()
17+
itp = RBFInterpolation1D(data, kernel)
18+
# Define interpolation function
19+
itp_func(x) = itp(x)
20+
21+
# Evaluate the thin plate spline on a new set of nodes and plot
22+
if isdefined(Main, :Makie)
23+
nodes = nodeset(itp)
24+
x_knots = sort(unique(nodes[:, 1]))
25+
y_knots = itp_func.(x_knots)
26+
27+
# Define interpolation points
28+
n = 200
29+
x_int_pts = Vector(LinRange(x_knots[1], x_knots[end], n))
30+
31+
# Get interpolated values
32+
y_int_pts = itp_func.(x_int_pts)
33+
34+
plot_topography_with_interpolation_knots(x_int_pts, y_int_pts, x_knots, y_knots;
35+
xlabel = "ETRS89 East",
36+
ylabel = "DHHN2016 Height",
37+
legend_position = :rb)
38+
end

examples/rhine_data_rbf_2d.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
##############################################################################
2+
# Script which uses the functionalities implemented in TrixiBottomTopography #
3+
# to plot a RBF interpolated section of the Rhine river. #
4+
##############################################################################
5+
6+
# Include packages
7+
using TrixiBottomTopography
8+
using KernelInterpolation
9+
10+
# Define data path
11+
root_dir = pkgdir(TrixiBottomTopography)
12+
data = joinpath(root_dir, "examples", "data", "rhine_data_2d_20.txt")
13+
14+
# Define RBF structure
15+
kernel = ThinPlateSplineKernel{2}()
16+
itp = RBFInterpolation2D(data, kernel)
17+
# Define interpolation function
18+
itp_func(x, y) = itp([x; y])
19+
20+
# Evaluate the thin plate spline on a new set of nodes and plot
21+
if isdefined(Main, :Makie)
22+
nodes = nodeset(itp)
23+
x_knots = sort(unique(nodes[:, 1]))
24+
y_knots = sort(unique(nodes[:, 2]))
25+
z_knots = evaluate_two_dimensional_interpolant(itp_func, x_knots, y_knots)
26+
27+
# Define interpolation points
28+
n = 100
29+
x_int_pts = Vector(LinRange(x_knots[1], x_knots[end], n))
30+
y_int_pts = Vector(LinRange(y_knots[1], y_knots[end], n))
31+
32+
# Get interpolated matrix
33+
z_int_pts = evaluate_two_dimensional_interpolant(itp_func, x_int_pts, y_int_pts)
34+
35+
plot_topography_with_interpolation_knots(x_int_pts, y_int_pts, z_int_pts,
36+
x_knots, y_knots, z_knots;
37+
xlabel = "ETRS89 East",
38+
ylabel = "DHHN2016 Height", zlabel = "H")
39+
end

0 commit comments

Comments
 (0)