Skip to content

Commit

Permalink
Refactor variogram files
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Feb 19, 2024
1 parent bb227a7 commit c67c06f
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 44 deletions.
8 changes: 4 additions & 4 deletions src/variogram/circular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ CircularVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = CircularVariogram

CircularVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) = CircularVariogram(sill, nugget, MetricBall(range))

variotype(::CircularVariogram) = CircularVariogram

isstationary(::Type{<:CircularVariogram}) = true

function::CircularVariogram)(h)
r = radius.ball)
s = γ.sill
n = γ.nugget
v = h r ? 1 - (2 / π) * acos(h / r) + (2h /* r)) * sqrt(1 - (h^2 / r^2)) : one(h)
(s - n) * v + (h > zero(h)) * n
end

variotype(::CircularVariogram) = CircularVariogram

isstationary(::Type{<:CircularVariogram}) = true
8 changes: 4 additions & 4 deletions src/variogram/cubic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ CubicVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = CubicVariogram(sill,

CubicVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) = CubicVariogram(sill, nugget, MetricBall(range))

variotype(::CubicVariogram) = CubicVariogram

isstationary(::Type{<:CubicVariogram}) = true

function::CubicVariogram)(h::T) where {T}
r = radius.ball)
s = γ.sill
Expand All @@ -33,7 +37,3 @@ function (γ::CubicVariogram)(h::T) where {T}

(h < r) * (s - n) * s1 + (h r) * (s - n) * s2 + (h > 0) * n
end

variotype(::CubicVariogram) = CubicVariogram

isstationary(::Type{<:CubicVariogram}) = true
8 changes: 4 additions & 4 deletions src/variogram/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ ExponentialVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = ExponentialVar
ExponentialVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) =
ExponentialVariogram(sill, nugget, MetricBall(range))

variotype(::ExponentialVariogram) = ExponentialVariogram

isstationary(::Type{<:ExponentialVariogram}) = true

function::ExponentialVariogram)(h)
r = radius.ball)
s = γ.sill
n = γ.nugget
(s - n) * (1 - exp(-3(h / r))) + (h > 0) * n
end

variotype(::ExponentialVariogram) = ExponentialVariogram

isstationary(::Type{<:ExponentialVariogram}) = true
8 changes: 4 additions & 4 deletions src/variogram/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ GaussianVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = GaussianVariogram

GaussianVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) = GaussianVariogram(sill, nugget, MetricBall(range))

variotype(::GaussianVariogram) = GaussianVariogram

isstationary(::Type{<:GaussianVariogram}) = true

function::GaussianVariogram)(h)
# add small eps to nugget
# for numerical stability
Expand All @@ -27,7 +31,3 @@ function (γ::GaussianVariogram)(h)
n = γ.nugget + typeof(s)(1e-6)
(s - n) * (1 - exp(-3(h / r)^2)) + (h > 0) * n
end

variotype(::GaussianVariogram) = GaussianVariogram

isstationary(::Type{<:GaussianVariogram}) = true
8 changes: 4 additions & 4 deletions src/variogram/matern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ MaternVariogram(ball; sill=1.0, nugget=zero(typeof(sill)), order=1.0) = MaternVa
MaternVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill)), order=1.0) =
MaternVariogram(sill, nugget, order, MetricBall(range))

variotype(::MaternVariogram) = MaternVariogram

isstationary(::Type{<:MaternVariogram}) = true

function::MaternVariogram)(h::T) where {T}
r = radius.ball)
s = γ.sill
Expand All @@ -38,7 +42,3 @@ function (γ::MaternVariogram)(h::T) where {T}

(s - n) * (1 - 2^(1 - ν) / Γ * δ^ν * Β) + (h > 0) * n
end

variotype(::MaternVariogram) = MaternVariogram

isstationary(::Type{<:MaternVariogram}) = true
12 changes: 6 additions & 6 deletions src/variogram/nugget.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ end

NuggetEffect(; nugget=1.0) = NuggetEffect(nugget)

::NuggetEffect)(h) = (h > 0) * γ.nugget
variotype(::NuggetEffect) = NuggetEffect

::NuggetEffect)(u::Point, v::Point) = ifelse(u == v, zero.nugget), γ.nugget)
isstationary(::Type{<:NuggetEffect}) = true

Base.range(::NuggetEffect{T}) where {T} = zero(T)
isisotropic(::NuggetEffect) = true

sill::NuggetEffect) = γ.nugget

variotype(::NuggetEffect) = NuggetEffect
Base.range(::NuggetEffect{T}) where {T} = zero(T)

isstationary(::Type{<:NuggetEffect}) = true
::NuggetEffect)(h) = (h > 0) * γ.nugget

isisotropic(::NuggetEffect) = true
::NuggetEffect)(u::Point, v::Point) = ifelse(u == v, zero.nugget), γ.nugget)
8 changes: 4 additions & 4 deletions src/variogram/pentaspherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ PentasphericalVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = Pentaspheri
PentasphericalVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) =
PentasphericalVariogram(sill, nugget, MetricBall(range))

variotype(::PentasphericalVariogram) = PentasphericalVariogram

isstationary(::Type{<:PentasphericalVariogram}) = true

function::PentasphericalVariogram)(h::T) where {T}
r = radius.ball)
s = γ.sill
Expand All @@ -34,7 +38,3 @@ function (γ::PentasphericalVariogram)(h::T) where {T}

(h < r) * (s - n) * s1 + (h r) * (s - n) * s2 + (h > 0) * n
end

variotype(::PentasphericalVariogram) = PentasphericalVariogram

isstationary(::Type{<:PentasphericalVariogram}) = true
12 changes: 6 additions & 6 deletions src/variogram/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ end

PowerVariogram(; scaling=1.0, nugget=zero(typeof(scaling)), exponent=1.0) = PowerVariogram(scaling, nugget, exponent)

variotype(::PowerVariogram) = PowerVariogram

isstationary(::Type{<:PowerVariogram}) = false

isisotropic(::PowerVariogram) = true

function::PowerVariogram)(h)
s = γ.scaling
a = γ.exponent
Expand All @@ -29,9 +35,3 @@ function (γ::PowerVariogram)(u::Point, v::Point)
h = evaluate(d, x, y)
γ(h)
end

variotype(::PowerVariogram) = PowerVariogram

isstationary(::Type{<:PowerVariogram}) = false

isisotropic(::PowerVariogram) = true
8 changes: 4 additions & 4 deletions src/variogram/sinehole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ SineHoleVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = SineHoleVariogram

SineHoleVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) = SineHoleVariogram(sill, nugget, MetricBall(range))

variotype(::SineHoleVariogram) = SineHoleVariogram

isstationary(::Type{<:SineHoleVariogram}) = true

function::SineHoleVariogram)(h::T) where {T}
r = radius.ball)
s = γ.sill
Expand All @@ -31,7 +35,3 @@ function (γ::SineHoleVariogram)(h::T) where {T}

(s - n) * (1 - sin(c * h′ / r) / (c * h′ / r)) + (h′ > 0) * n
end

variotype(::SineHoleVariogram) = SineHoleVariogram

isstationary(::Type{<:SineHoleVariogram}) = true
8 changes: 4 additions & 4 deletions src/variogram/spherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ SphericalVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = SphericalVariogr
SphericalVariogram(; range=1.0, sill=1.0, nugget=zero(typeof(sill))) =
SphericalVariogram(sill, nugget, MetricBall(range))

variotype(::SphericalVariogram) = SphericalVariogram

isstationary(::Type{<:SphericalVariogram}) = true

function::SphericalVariogram)(h::T) where {T}
r = radius.ball)
s = γ.sill
Expand All @@ -33,7 +37,3 @@ function (γ::SphericalVariogram)(h::T) where {T}

(h < r) * (s - n) * s1 + (h r) * (s - n) * s2 + (h > 0) * n
end

variotype(::SphericalVariogram) = SphericalVariogram

isstationary(::Type{<:SphericalVariogram}) = true

0 comments on commit c67c06f

Please sign in to comment.