From 53f5788f4127595faa287279e5e8e2ee7d24c11b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Tue, 15 Oct 2024 17:00:28 -0300 Subject: [PATCH] Refactor accumulate function --- src/empirical/algorithms.jl | 11 +++++------ src/empirical/estimalgo.jl | 6 +++++- src/empirical/variogram.jl | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/empirical/algorithms.jl b/src/empirical/algorithms.jl index 247eecc..b665628 100644 --- a/src/empirical/algorithms.jl +++ b/src/empirical/algorithms.jl @@ -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 @@ -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, 𝒫) diff --git a/src/empirical/estimalgo.jl b/src/empirical/estimalgo.jl index 3ffdc7c..4bf74c3 100644 --- a/src/empirical/estimalgo.jl +++ b/src/empirical/estimalgo.jl @@ -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" diff --git a/src/empirical/variogram.jl b/src/empirical/variogram.jl index 44a58cd..b8e05ef 100644 --- a/src/empirical/variogram.jl +++ b/src/empirical/variogram.jl @@ -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