Skip to content

Commit

Permalink
Add planeplot
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 30, 2024
1 parent 5f9106a commit 5fd828d
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 91 deletions.
2 changes: 2 additions & 0 deletions ext/GeoStatsFunctionsMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import Makie

import GeoStatsFunctions: varioplot, varioplot!
import GeoStatsFunctions: transioplot, transioplot!
import GeoStatsFunctions: planeplot, planeplot!

include("varioplot.jl")
include("transioplot.jl")
include("planeplot.jl")
include("utils.jl")

end
80 changes: 80 additions & 0 deletions ext/planeplot.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

function planeplot(
g::EmpiricalVarioplane;
colormap=:viridis
)
# polar angle
θs = g.θs

# polar radius
rs = g.rs

# varioplane values
hs = g.hs

# values in matrix form
H = reduce(hcat, hs)

# exploit symmetry
θs = range(0, 2π, length=2 * length(θs))
H = [H H]

# hide hole at center
rs = [zero(eltype(rs)); rs]
H = [H[1:1, :]; H]

# transpose for plotting
H = transpose(H)

fig = Makie.Figure()
ax = Makie.PolarAxis(fig[1, 1])
Makie.surface!(ax, θs, rs, H, colormap=colormap, shading=Makie.NoShading)
fig
end

function planeplot(
t::EmpiricalTransioplane;
colormap=:viridis,
levels=nothing
)
# polar angle
θs = t.θs

# polar radius
rs = t.rs

# hide hole at center
rs = [zero(eltype(rs)); rs]

# transioplane values
hs = t.hs

# number of labels
L = size(first(hs), 1)

# retrieve labels
l = isnothing(levels) ? (1:L) : levels

fig = Makie.Figure()
for i in 1:L, j in 1:L
lᵢ, lⱼ = l[i], l[j]
ax = Makie.PolarAxis(fig[i, j], title="$lᵢ$lⱼ")

# values in matrix form
h = getindex.(hs, i, j)
H = reduce(hcat, h)

# hide hole at center
H = [H[1:1, :]; H]

# transpose for plotting
H = transpose(H)

Makie.surface!(ax, θs, rs, H, colormap=colormap, shading=Makie.NoShading)
end

fig
end
46 changes: 0 additions & 46 deletions ext/transioplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,52 +62,6 @@ function transioplot(
fig
end

function transioplot(
t::EmpiricalTransioplane;
# common transiogram options
levels=nothing,
# empirical transioplane options
colormap=:viridis
)
# polar angle
θs = t.θs

# polar radius
rs = t.rs

# hide hole at center
rs = [zero(eltype(rs)); rs]

# transioplane values
hs = t.hs

# number of labels
L = size(first(hs), 1)

# retrieve labels
l = isnothing(levels) ? (1:L) : levels

fig = Makie.Figure()
for i in 1:L, j in 1:L
lᵢ, lⱼ = l[i], l[j]
ax = Makie.PolarAxis(fig[i, j], title="$lᵢ$lⱼ")

# values in matrix form
h = getindex.(hs, i, j)
H = reduce(hcat, h)

# hide hole at center
H = [H[1:1, :]; H]

# transpose for plotting
H = transpose(H)

Makie.surface!(ax, θs, rs, H, colormap=colormap, shading=Makie.NoShading)
end

fig
end

# ------------
# THEORETICAL
# ------------
Expand Down
40 changes: 1 addition & 39 deletions ext/varioplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ Makie.@recipe(VarioPlot, γ) do scene
showtext=true,
textsize=12,
showhist=true,
histcolor=:slategray,

# empirical varioplane options
colormap=:viridis,
showrange=true,
rangecolor=:white,
rangemodel=SphericalVariogram
histcolor=:slategray
)
end

Expand Down Expand Up @@ -60,38 +54,6 @@ function Makie.plot!(plot::VarioPlot{<:Tuple{EmpiricalVariogram}})
end
end

Makie.plottype(::EmpiricalVarioplane) = VarioPlot{<:Tuple{EmpiricalVarioplane}}

function Makie.plot!(plot::VarioPlot{<:Tuple{EmpiricalVarioplane}})
# retrieve varioplane object
γ = plot[]

# polar angle
θs = Makie.@lift $γ.θs

# polar radius
rs = Makie.@lift $γ.rs

# varioplane values
hs = Makie.@lift $γ.hs

# values in matrix form
H = Makie.@lift reduce(hcat, $hs)

# exploit symmetry
θs = Makie.@lift range(0, 2π, length=2 * length($θs))
H = Makie.@lift [$H $H]

# hide hole at center
rs = Makie.@lift [zero(eltype($rs)); $rs]
H = Makie.@lift [$H[1:1, :]; $H]

# transpose for plotting
H = Makie.@lift transpose($H)

Makie.surface!(plot, θs, rs, H, colormap=plot[:colormap], shading=Makie.NoShading)
end

# ------------
# THEORETICAL
# ------------
Expand Down
4 changes: 3 additions & 1 deletion src/GeoStatsFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export
varioplot,
varioplot!,
transioplot,
transioplot!
transioplot!,
planeplot,
planeplot!

end
24 changes: 19 additions & 5 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"""
varioplot(γ; [options])
Plot the variogram or varioplane `γ` with given `options`.
Plot the variogram `γ` with given `options`.
## Common variogram options:
Expand All @@ -21,10 +21,6 @@ Plot the variogram or varioplane `γ` with given `options`.
* `showhist` - show histogram
* `histcolor` - color of histogram
## Empirical varioplane options:
* `colormap` - color map of varioplane
### Notes
* This function will only work in the presence of
Expand Down Expand Up @@ -54,3 +50,21 @@ Plot the transiogram `t` with given `options`.
"""
function transioplot end
function transioplot! end

"""
planeplot(f; [options])
Plot the varioplane or transioplane `f` with given `options`.
## Available options
* `colormap` - Color map of plane plot.
### Notes
* This function will only work in the presence of
a Makie.jl backend via package extensions in
Julia v1.9 or later versions of the language.
"""
function planeplot end
function planeplot! end

0 comments on commit 5fd828d

Please sign in to comment.