Skip to content

Commit

Permalink
Refactor EmpiricalVarioplane
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 29, 2024
1 parent 24497d2 commit 986846b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
30 changes: 8 additions & 22 deletions ext/varioplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,38 +66,24 @@ function Makie.plot!(plot::VarioPlot{<:Tuple{EmpiricalVarioplane}})
# retrieve varioplane object
v = plot[]

# underyling variograms
γs = Makie.@lift $v.γs

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

# polar radius
rs = Makie.@lift ustrip.($γs[1].abscissas)

# variogram ordinates for all variograms
H = Makie.@lift let
hs = map($γs) do γ
# retrieve ordinates without units
ys = ustrip.(γ.ordinates)

# handle NaN ordinates (i.e. empty bins)
isnan(ys[1]) && (ys[1] = 0)
for i in 2:length(ys)
isnan(ys[i]) && (ys[i] = ys[i - 1])
end

ys
end
reduce(hcat, hs)
end
rs = Makie.@lift $v.rs

# varioplane values
hs = Makie.@lift $v.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 [0; $rs]
rs = Makie.@lift [zero(eltype($rs)); $rs]
H = Makie.@lift [$H[1:1, :]; $H]

# transpose for plotting
Expand Down
27 changes: 22 additions & 5 deletions src/empirical/varioplane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +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,V}
struct EmpiricalVarioplane{T,R,V}
θs::Vector{T}
γs::Vector{V}
rs::Vector{R}
hs::Vector{V}
end

function EmpiricalVarioplane(
Expand Down Expand Up @@ -48,18 +49,34 @@ function EmpiricalVarioplane(
planes = collect(subset)
u, v = householderbasis(normal)
else
@error "varioplane only supported in 2D or 3D"
throw(ArgumentError("varioplane only supported in 2D or 3D"))
end

# loop over half of the plane
# polar angles for half plane (variogram is symmetric)
θs = collect(range(0, stop=π, length=nangs))

# estimate directional variograms across planes
γs = map(θs) do θ
dir = DirectionPartition(cos(θ) * u + sin(θ) * v, tol=dtol)
γ(plane) = EmpiricalVariogram(partition(rng, plane, dir), var₁, var₂; kwargs...)
tmapreduce(γ, merge, planes)
end

EmpiricalVarioplane(θs, γs)
# polar radii
rs = first(γs).abscissas

# varioplane values
hs = map(γs) do γ
h = γ.ordinates
# handle NaN ordinates (i.e. empty bins)
isnan(h[1]) && (h[1] = zero(eltype(h)))
for i in 2:length(h)
isnan(h[i]) && (h[i] = h[i - 1])
end
h
end

EmpiricalVarioplane(θs, rs, hs)
end

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

0 comments on commit 986846b

Please sign in to comment.