Skip to content

Commit

Permalink
Refactor EmpiricalVariogram
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 15, 2024
1 parent 9b1107e commit b2c3c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/empirical/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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(𝒫)
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
12 changes: 6 additions & 6 deletions src/empirical/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

"""
Expand Down Expand Up @@ -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}
= γα.counts
= γβ.counts
= γα.abscissa
= γβ.abscissa
= γα.ordinate
= γβ.ordinate
= γα.counts
= γβ.counts

# copy distance and estimator
d = γα.distance
Expand All @@ -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

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

0 comments on commit b2c3c65

Please sign in to comment.