-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement interpolation methods from NaturalNeighbours.jl (#46)
* Explicitly mention how to do regridding using the TopoPlots API * Bump version + add NaturalNeighbours compat * Implement NaturalNeighbours.jl interpolation as `NaturalNeighboursMethod` similar to how `ScatteredInterpolationMethod` currently exists. * Document NaturalNeighboursMethod * Fix Makie warning about `shading=false` being invalid Replaced by `NoShading` * Describe the method for scattered and nn interpolation in the docs * Associate `lift`s with the plot in the topoplot recipe This makes for cleaner GC/windups when deleting a plot - the lift observer functions are known to the plot object, and can be removed immediately instead of relying on the GC to detect that those variables are no longer in use. * Implement gridding * Add an "interpolator reference image" page to the docs * Add NaturalNeighbours.jl to the docs Project * Add a brief summary of the advantage of natural neighbour interpolation * Warn against using DelaunayMesh in CairoMakie * Fix error in doc build by sampling without replacement * Fix typos / omissions * finally * fix more doc errors * ugh * Add compat for Makie v0.21 * Address code review * Restore the option for the derivative calculation to also be parallelized
- Loading branch information
1 parent
84122ef
commit 7f81e8d
Showing
9 changed files
with
235 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Interpolator reference | ||
|
||
This file contains reference figures showing the output of each interpolator available in TopoPlots, as well as timings for them. | ||
|
||
It is a more comprehensive version of the plot in [Interpolation](@ref). | ||
|
||
### Example data | ||
|
||
```@example 1 | ||
using TopoPlots, CairoMakie, ScatteredInterpolation, NaturalNeighbours | ||
data, positions = TopoPlots.example_data() | ||
f = Figure(size=(1000, 1500)) | ||
interpolators = [ | ||
SplineInterpolator() NullInterpolator() DelaunayMesh(); | ||
CloughTocher() ScatteredInterpolationMethod(ThinPlate()) ScatteredInterpolationMethod(Shepard(3)); | ||
ScatteredInterpolationMethod(Multiquadratic()) ScatteredInterpolationMethod(InverseMultiquadratic()) ScatteredInterpolationMethod(Gaussian()); | ||
NaturalNeighboursMethod(Hiyoshi(2)) NaturalNeighboursMethod(Sibson()) NaturalNeighboursMethod(Laplace()); | ||
NaturalNeighboursMethod(Farin()) NaturalNeighboursMethod(Sibson(1)) NaturalNeighboursMethod(Nearest()); | ||
] | ||
data_slice = data[:, 360, 1] | ||
for idx in CartesianIndices(interpolators) | ||
interpolation = interpolators[idx] | ||
# precompile to get accurate measurements | ||
TopoPlots.topoplot( | ||
data_slice, positions; | ||
contours=true, interpolation=interpolation, | ||
labels = string.(1:length(positions)), colorrange=(-1, 1), | ||
label_scatter=(markersize=10,), | ||
axis=(type=Axis, title="...", aspect=DataAspect(),)) | ||
# measure time, to give an idea of what speed to expect from the different interpolators | ||
t = @elapsed ax, pl = TopoPlots.topoplot( | ||
f[Tuple(idx)...], data_slice, positions; | ||
contours=true, | ||
interpolation=interpolation, | ||
labels = string.(1:length(positions)), colorrange=(-1, 1), | ||
label_scatter=(markersize=10,), | ||
axis=(type=Axis, title="$(typeof(interpolation))()",aspect=DataAspect(),)) | ||
ax.title = ("$(typeof(interpolation))() - $(round(t, digits=2))s") | ||
if interpolation isa Union{NaturalNeighboursMethod, ScatteredInterpolationMethod} | ||
ax.title = "$(typeof(interpolation))() - $(round(t, digits=2))s" | ||
ax.subtitle = string(typeof(interpolation.method)) | ||
end | ||
end | ||
f | ||
``` | ||
|
||
### Randomly sampled function | ||
|
||
```@example 1 | ||
using TopoPlots, CairoMakie, ScatteredInterpolation, NaturalNeighbours | ||
using TopoPlots.Makie.Random: randsubseq | ||
data = Makie.peaks(100) | ||
sampling_points = randsubseq(CartesianIndices(data), 0.011) | ||
data_slice = data[sampling_points] | ||
positions = Point2f.(Tuple.(sampling_points)) | ||
interpolators = [ | ||
SplineInterpolator(; smoothing = 7) NullInterpolator() DelaunayMesh(); | ||
CloughTocher() ScatteredInterpolationMethod(ThinPlate()) ScatteredInterpolationMethod(Shepard(3)); | ||
ScatteredInterpolationMethod(Multiquadratic()) ScatteredInterpolationMethod(InverseMultiquadratic()) ScatteredInterpolationMethod(Gaussian()); | ||
NaturalNeighboursMethod(Hiyoshi(2)) NaturalNeighboursMethod(Sibson()) NaturalNeighboursMethod(Laplace()); | ||
NaturalNeighboursMethod(Farin()) NaturalNeighboursMethod(Sibson(1)) NaturalNeighboursMethod(Nearest()); | ||
] | ||
f = Figure(; size = (1000, 1500)) | ||
for idx in CartesianIndices(interpolators) | ||
interpolation = interpolators[idx] | ||
# precompile to get accurate measurements | ||
TopoPlots.topoplot( | ||
data_slice, positions; | ||
contours=true, interpolation=interpolation, | ||
labels = string.(1:length(positions)), colorrange=(-1, 1), | ||
label_scatter=(markersize=10,), | ||
axis=(type=Axis, title="...", aspect=DataAspect(),)) | ||
# measure time, to give an idea of what speed to expect from the different interpolators | ||
t = @elapsed ax, pl = TopoPlots.topoplot( | ||
f[Tuple(idx)...], data_slice, positions; | ||
contours=true, | ||
interpolation=interpolation, | ||
labels = string.(1:length(positions)), colorrange=(-1, 1), | ||
label_scatter=(markersize=10,), | ||
axis=(type=Axis, title="$(typeof(interpolation))()",aspect=DataAspect(),)) | ||
ax.title = ("$(typeof(interpolation))() - $(round(t, digits=2))s") | ||
if interpolation isa Union{NaturalNeighboursMethod, ScatteredInterpolationMethod} | ||
ax.title = "$(typeof(interpolation))() - $(round(t, digits=2))s" | ||
ax.subtitle = string(typeof(interpolation.method)) | ||
end | ||
end | ||
f | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.