From cccf8f2e54891f8595331e5ecc9331a13b1ac88b Mon Sep 17 00:00:00 2001 From: Anshul Singhvi Date: Mon, 22 Apr 2024 20:30:19 -0400 Subject: [PATCH] Add an "interpolator reference image" page to the docs --- docs/make.jl | 3 +- docs/src/interpolator_reference.md | 101 +++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 docs/src/interpolator_reference.md diff --git a/docs/make.jl b/docs/make.jl index c6dff1e..7f28641 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -16,7 +16,8 @@ makedocs(; "Home" => "index.md", "General TopoPlots" => "general.md", "EEG" => "eeg.md", - "Function reference" => "functions.md" + "Function reference" => "functions.md", + "Interpolator reference images" => "interpolator_reference.md" ], ) diff --git a/docs/src/interpolator_reference.md b/docs/src/interpolator_reference.md new file mode 100644 index 0000000..ed80730 --- /dev/null +++ b/docs/src/interpolator_reference.md @@ -0,0 +1,101 @@ +# 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 +data = Makie.peaks(100) +sampling_points = rand(CartesianIndices(data), 100) +data_slice = data[sampling_points] +positions = Point2f.(Tuple.(sampling_points)) + +interpolators = [ + SplineInterpolator(; smoothing = 5) 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 +```