Skip to content

Commit

Permalink
Refactor plot recipes
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Feb 10, 2025
1 parent 5518b7b commit ee3566f
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 132 deletions.
72 changes: 62 additions & 10 deletions ext/GeoStatsFunctionsMakieExt/funplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

funplot(f; kwargs...) = _funplot(f; kwargs...)

function _funplot(
function funplot(
f::GeoStatsFunction;
# common options
color=:teal,
Expand Down Expand Up @@ -86,12 +84,66 @@ function _funplot(
fig
end

_istransiogram(f::GeoStatsFunction) = false
_istransiogram(t::Transiogram) = true
function funplot(
f::EmpiricalGeoStatsFunction;
# common options
color=:teal,
size=1.5,
maxlag=nothing,
labels=nothing,
# empirical options
pointsize=12,
showtext=true,
textsize=12,
showhist=true,
histcolor=:teal
)
# number of variables
n = nvariates(f)

# aesthetic options
vars = isnothing(labels) ? (1:n) : labels

fig = Makie.Figure()
for i in 1:n, j in 1:n
title = n > 1 ? "$(vars[i])$(vars[j])" : ""
ax = Makie.Axis(fig[i, j], title=title)

# retrieve coordinates and counts
hs = f.abscissas
fs = _istransiogram(f) ? f.ordinates[i, j] : f.ordinates
ns = f.counts

# retrieve maximum lag
hmax = isnothing(maxlag) ? last(hs) : _addunit(maxlag, u"m")

# discard empty bins
hs = hs[ns .> 0]
fs = fs[ns .> 0]
ns = ns[ns .> 0]

# discard above maximum lag
ns = ns[hs .≤ hmax]
fs = fs[hs .≤ hmax]
hs = hs[hs .≤ hmax]

# visualize histogram
if showhist
ms = ns * (maximum(fs) / maximum(ns)) / 10
Makie.barplot!(ax, hs, ms, color=histcolor, alpha=0.3, gap=0.0)
end

# ----------------
# SPECIALIZATIONS
# ----------------
# visualize function
Makie.scatterlines!(ax, hs, fs, color=color, markersize=pointsize, linewidth=size)

include("funplot/variogram.jl")
include("funplot/transiogram.jl")
# visualize text counts
if showtext
Makie.text!(ax, hs, fs, text=string.(ns), fontsize=textsize)
end
end
fig
end

_istransiogram(f) = false
_istransiogram(t::Transiogram) = true
_istransiogram(t::EmpiricalTransiogram) = true
66 changes: 0 additions & 66 deletions ext/GeoStatsFunctionsMakieExt/funplot/transiogram.jl

This file was deleted.

56 changes: 0 additions & 56 deletions ext/GeoStatsFunctionsMakieExt/funplot/variogram.jl

This file was deleted.

7 changes: 7 additions & 0 deletions src/empirical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ An empirical geostatistical function estimated from data.
"""
abstract type EmpiricalGeoStatsFunction end

"""
nvariates(f)
Return the number of (co)variates of the empirical geostatistical function `f`.
"""
nvariates(f::EmpiricalGeoStatsFunction) = nvariates(typeof(f))

# -----------
# IO METHODS
# -----------
Expand Down
2 changes: 2 additions & 0 deletions src/empirical/transiogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ function PlanarTransiogram(normal, data::AbstractGeoTable, var; ntol=1e-6u"m", k
EmpiricalTransiogram(Π, var; kwargs...)
end

nvariates(t::EmpiricalTransiogram) = size(t.ordinates, 1)

"""
merge(tα, tβ)
Expand Down
2 changes: 2 additions & 0 deletions src/empirical/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ function PlanarVariogram(normal, data::AbstractGeoTable, var₁, var₂=var₁;
EmpiricalVariogram(Π, var₁, var₂; kwargs...)
end

nvariates(::Type{<:EmpiricalVariogram}) = 1

"""
merge(γα, γβ)
Expand Down

0 comments on commit ee3566f

Please sign in to comment.