Skip to content

Commit

Permalink
More refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 31, 2024
1 parent 90c2e00 commit 4861adb
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 22 deletions.
3 changes: 2 additions & 1 deletion ext/GeoStatsFunctionsMakieExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
module GeoStatsFunctionsMakieExt

using GeoStatsFunctions
using LinearAlgebra
using Meshes
using Unitful
using LinearAlgebra

import Makie

Expand Down
69 changes: 56 additions & 13 deletions ext/planeplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,25 @@ function planeplot(g::EmpiricalVarioplane; colormap=:viridis)
rs = g.rs

# varioplane values
hs = g.hs
zs = g.zs

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

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

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

# transpose for plotting
H = transpose(H)
Z = transpose(Z)

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

Expand All @@ -43,10 +43,10 @@ function planeplot(t::EmpiricalTransioplane; colormap=:viridis, levels=nothing)
rs = [zero(eltype(rs)); rs]

# transioplane values
hs = t.hs
zs = t.zs

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

# retrieve labels
l = isnothing(levels) ? (1:L) : levels
Expand All @@ -57,17 +57,60 @@ function planeplot(t::EmpiricalTransioplane; colormap=:viridis, levels=nothing)
ax = Makie.PolarAxis(fig[i, j], title="$lᵢ$lⱼ")

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

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

# transpose for plotting
H = transpose(H)
Z = transpose(Z)

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

fig
end

function planeplot::Variogram;
# geometric options
normal=Vec(0, 0, 1),
nlags=20, nangs=50,
maxlag=nothing,
# austhetic options
colormap=:viridis
)
# basis for varioplane
u, v = householderbasis(normal)

# maximum lag
H = if isnothing(maxlag)
_maxlag(γ)
else
_addunit(maxlag, u"m")
end

# polar angles
θs = range(0, stop=π, length=nangs)

# polar radius
rs = range(1e-6, stop=ustrip(H), length=nlags)

# direction vector as a function of polar angle
dir(θ) = cos(θ) * u + sin(θ) * v

O = Point(0, 0, 0)
G = [γ(O, O + r * dir(θ)) for θ in θs, r in rs]

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

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

fig = Makie.Figure()
ax = Makie.PolarAxis(fig[1, 1])
Makie.surface!(ax, θs, rs, G, colormap=colormap, shading=Makie.NoShading)
fig
end
8 changes: 4 additions & 4 deletions src/empirical/transioplane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ the tolerance `dtol` in length units for the direction partition, the number of
angles `nangs` in the plane, and forward the `parameters` to the underlying
[`EmpiricalTransiogram`](@ref).
"""
struct EmpiricalTransioplane{T,R,H}
struct EmpiricalTransioplane{T,R,Z}
θs::Vector{T}
rs::Vector{R}
hs::Vector{H}
zs::Vector{Z}
end

function EmpiricalTransioplane(
Expand Down Expand Up @@ -65,9 +65,9 @@ function EmpiricalTransioplane(
rs = first(ts).abscissas

# transioplane values
hs = [t.ordinates for t in ts]
zs = [t.ordinates for t in ts]

EmpiricalTransioplane(θs, rs, hs)
EmpiricalTransioplane(θs, rs, zs)
end

# -----------
Expand Down
8 changes: 4 additions & 4 deletions src/empirical/varioplane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ the tolerance `dtol` in length units for the direction partition, the number of
angles `nangs` in the plane, and forward the `parameters` to the underlying
[`EmpiricalVariogram`](@ref).
"""
struct EmpiricalVarioplane{T,R,H}
struct EmpiricalVarioplane{T,R,Z}
θs::Vector{T}
rs::Vector{R}
hs::Vector{H}
zs::Vector{Z}
end

function EmpiricalVarioplane(
Expand Down Expand Up @@ -66,9 +66,9 @@ function EmpiricalVarioplane(
rs = first(γs).abscissas

# varioplane values
hs =.ordinates for γ in γs]
zs =.ordinates for γ in γs]

EmpiricalVarioplane(θs, rs, hs)
EmpiricalVarioplane(θs, rs, zs)
end

# -----------
Expand Down

0 comments on commit 4861adb

Please sign in to comment.