From b2c3c65e710ad4605089a6eecceb585e6f04b53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Tue, 15 Oct 2024 16:51:07 -0300 Subject: [PATCH] Refactor EmpiricalVariogram --- src/empirical/algorithms.jl | 6 +++--- src/empirical/variogram.jl | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/empirical/algorithms.jl b/src/empirical/algorithms.jl index 05457d0..247eecc 100644 --- a/src/empirical/algorithms.jl +++ b/src/empirical/algorithms.jl @@ -49,9 +49,9 @@ function accumulate(data, var₁, var₂, estimator::Estimator, algo::AccumAlgor # lag sums and counts ℒ = Meshes.lentype(𝒫) + ns = zeros(Int, nlags) Σx = zeros(ℒ, nlags) Σy = zeros(V, nlags) - ns = zeros(Int, nlags) # loop over points inside ball @inbounds for j in 1:nelements(𝒫) @@ -80,9 +80,9 @@ function accumulate(data, var₁, var₂, estimator::Estimator, algo::AccumAlgor lag == 0 && @warn "duplicate coordinates found, consider using `UniqueCoords`" if 0 < lag ≤ nlags && !ismissing(v) + ns[lag] += 1 Σx[lag] += h Σy[lag] += v - ns[lag] += 1 end end end @@ -101,7 +101,7 @@ function accumulate(data, var₁, var₂, estimator::Estimator, algo::AccumAlgor ys = @. ordfun(Σy, ns) ys[ns .== 0] .= zero(eltype(ys)) - xs, ys, ns + ns, xs, ys end include("algorithms/fullsearch.jl") diff --git a/src/empirical/variogram.jl b/src/empirical/variogram.jl index 3fabd55..44a58cd 100644 --- a/src/empirical/variogram.jl +++ b/src/empirical/variogram.jl @@ -47,9 +47,9 @@ See also: [`DirectionalVariogram`](@ref), [`PlanarVariogram`](@ref), (https://www.sciencedirect.com/science/article/pii/S0098300419302936) """ struct EmpiricalVariogram{ℒ<:Len,V,D,E} + counts::Vector{Int} abscissa::Vector{ℒ} ordinate::Vector{V} - counts::Vector{Int} distance::D estimator::E end @@ -75,9 +75,9 @@ function EmpiricalVariogram( estim, algo = estimalgo(𝒟, nlags, maxlag, distance, estimator, algorithm) # accumulate data with chosen algorithm - abscissa, ordinate, counts = accumulate(𝒮, var₁, var₂, estim, algo) + counts, abscissa, ordinate = accumulate(𝒮, var₁, var₂, estim, algo) - EmpiricalVariogram(abscissa, ordinate, counts, distance, estim) + EmpiricalVariogram(counts, abscissa, ordinate, distance, estim) end """ @@ -160,12 +160,12 @@ assuming that both variograms have the same number of lags, distance and estimator. """ function merge(γα::EmpiricalVariogram{V,D,E}, γβ::EmpiricalVariogram{V,D,E}) where {V,D,E} + nα = γα.counts + nβ = γβ.counts xα = γα.abscissa xβ = γβ.abscissa yα = γα.ordinate yβ = γβ.ordinate - nα = γα.counts - nβ = γβ.counts # copy distance and estimator d = γα.distance @@ -183,7 +183,7 @@ function merge(γα::EmpiricalVariogram{V,D,E}, γβ::EmpiricalVariogram{V,D,E}) x[n .== 0] .= xα[n .== 0] y[n .== 0] .= 0 - EmpiricalVariogram(x, y, n, d, e) + EmpiricalVariogram(n, x, y, d, e) end # -----------