Skip to content

Commit

Permalink
Refactor accumulate function
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 15, 2024
1 parent b2c3c65 commit 53f5788
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/empirical/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ estimation of geostatistical functions.
abstract type AccumAlgorithm end

"""
accumulate(data, var₁, var₂, estimator, algo)
accumulate(data, vars, estimator, algo)
Accumulate pairs of points in `data` for variables
`var₁` and `var₂` with `estimator` and accumulation
algorithm `algo`.
`vars` with `estimator` and accumulation `algo`.
"""
function accumulate(data, var₁, var₂, estimator::Estimator, algo::AccumAlgorithm)
function accumulate(data, vars, estimator::Estimator, algo::AccumAlgorithm)
# retrieve algorithm parameters
nlags = algo.nlags
maxlag = algo.maxlag
Expand All @@ -32,8 +31,8 @@ function accumulate(data, var₁, var₂, estimator::Estimator, algo::AccumAlgor

# vectors for variables
cols = Tables.columns(𝒯)
z₁ = Tables.getcolumn(cols, Symbol(var₁))
z₂ = Tables.getcolumn(cols, Symbol(var₂))
z₁ = Tables.getcolumn(cols, Symbol(vars[1]))
z₂ = Tables.getcolumn(cols, Symbol(vars[2]))

# neighbors function
neighbors = neighfun(algo, 𝒫)
Expand Down
6 changes: 5 additions & 1 deletion src/empirical/estimalgo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------

# helper function to retrieve estimator and algorithm from user input
"""
estimalgo(domain, nlags, maxlag, distance, estimator, algorithm)
Retrieve concrete estimator and algorithm from user input.
"""
function estimalgo(dom, nlags, maxlag, distance, estimator, algorithm)
# sanity checks
@assert nelements(dom) > 1 "variogram requires at least 2 elements"
Expand Down
2 changes: 1 addition & 1 deletion src/empirical/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function EmpiricalVariogram(
estim, algo = estimalgo(𝒟, nlags, maxlag, distance, estimator, algorithm)

# accumulate data with chosen algorithm
counts, abscissa, ordinate = accumulate(𝒮, var₁, var₂, estim, algo)
counts, abscissa, ordinate = accumulate(𝒮, (var₁, var₂), estim, algo)

EmpiricalVariogram(counts, abscissa, ordinate, distance, estim)
end
Expand Down

0 comments on commit 53f5788

Please sign in to comment.