Skip to content

Commit

Permalink
Convert Variogram parameters to float (#36)
Browse files Browse the repository at this point in the history
* Convert 'Variogram' parameters to float

* Add tests

* Update code
  • Loading branch information
eliascarv authored Oct 23, 2024
1 parent fa9be00 commit 44e2952
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/theoretical/variogram/circular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ struct CircularVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
CircularVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

CircularVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = CircularVariogram(sill, nugget, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/cubic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct CubicVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
CubicVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

CubicVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = CubicVariogram(sill, nugget, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/exponential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct ExponentialVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
ExponentialVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

ExponentialVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = ExponentialVariogram(sill, nugget, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/gaussian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct GaussianVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
GaussianVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

GaussianVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = GaussianVariogram(sill, nugget, ball)
Expand Down
2 changes: 2 additions & 0 deletions src/theoretical/variogram/matern.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ struct MaternVariogram{V,O,B} <: Variogram
nugget::V
order::O
ball::B
MaternVariogram(sill::V, nugget::V, order::O, ball::B) where {V,O,B} =
new{float(V),float(O),B}(sill, nugget, order, ball)
end

MaternVariogram(ball; sill=1.0, nugget=zero(typeof(sill)), order=1.0) = MaternVariogram(sill, nugget, order, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/nugget.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A pure nugget effect variogram with nugget `n`.
"""
struct NuggetEffect{V} <: Variogram
nugget::V
NuggetEffect(nugget::V) where {V} = new{float(V)}(nugget)
end

NuggetEffect(; nugget=1.0) = NuggetEffect(nugget)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/pentaspherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct PentasphericalVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
PentasphericalVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

PentasphericalVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = PentasphericalVariogram(sill, nugget, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct PowerVariogram{V,E} <: Variogram
scaling::V
nugget::V
exponent::E
PowerVariogram(scaling::V, nugget::V, exponent::E) where {V,E} = new{float(V),float(E)}(scaling, nugget, exponent)
end

PowerVariogram(; scaling=1.0, nugget=zero(typeof(scaling)), exponent=1.0) = PowerVariogram(scaling, nugget, exponent)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/sinehole.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SineHoleVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
SineHoleVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

SineHoleVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = SineHoleVariogram(sill, nugget, ball)
Expand Down
1 change: 1 addition & 0 deletions src/theoretical/variogram/spherical.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct SphericalVariogram{V,B} <: Variogram
sill::V
nugget::V
ball::B
SphericalVariogram(sill::V, nugget::V, ball::B) where {V,B} = new{float(V),B}(sill, nugget, ball)
end

SphericalVariogram(ball; sill=1.0, nugget=zero(typeof(sill))) = SphericalVariogram(sill, nugget, ball)
Expand Down
33 changes: 33 additions & 0 deletions test/theoretical/variogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,39 @@
g = GeoStatsFunctions.scale(γ, 2)
@test g == γ

# convert parameters to float
γ = CircularVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = CubicVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = ExponentialVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = GaussianVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = MaternVariogram(sill=1, nugget=1, order=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
@test γ.order isa Float64
γ = NuggetEffect(nugget=1)
@test nugget(γ) isa Float64
γ = PentasphericalVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = PowerVariogram(scaling=1, nugget=1, exponent=1)
@test γ.scaling isa Float64
@test nugget(γ) isa Float64
@test γ.exponent isa Float64
γ = SineHoleVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64
γ = SphericalVariogram(sill=1, nugget=1)
@test sill(γ) isa Float64
@test nugget(γ) isa Float64

# shows
γ = CircularVariogram()
@test sprint(show, γ) == "CircularVariogram(sill: 1.0, nugget: 0.0, range: 1.0 m, distance: Euclidean)"
Expand Down

0 comments on commit 44e2952

Please sign in to comment.