Skip to content

Commit

Permalink
Enforce units in PiecewiseLinearTransiogram
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Oct 29, 2024
1 parent 8798694 commit a802c58
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/theoretical/transiogram/piecewiselinear.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function PiecewiseLinearTransiogram(ball::MetricBall, abscissas::AbstractVector,
m = size(ordinates, 1)

# abscissa vector
x = abscissas
x = float(aslen.(abscissas))

# ordinate matrices
Y = map(1:n) do k
Expand Down
4 changes: 4 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
const Len{T} = Quantity{T,u"𝐋"}
const InvLen{T} = Quantity{T,u"𝐋^-1"}

aslen(x::Number) = x * u"m"
aslen(x::Len) = x
aslen(::Quantity) = throw(ArgumentError("invalid units, please check the documentation"))

asinvlen(x::Number) = x * u"m^-1"
asinvlen(x::InvLen) = x
asinvlen(::Quantity) = throw(ArgumentError("invalid units, please check the documentation"))
Expand Down
8 changes: 7 additions & 1 deletion test/theoretical/transiogram.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@
end

@testset "PiecewiseLinearTransiogram" begin
# TODO
csv = CSV.File(joinpath(datadir, "facies5.csv"))
gtb = georef(csv, ("X", "Y", "Z"))
t = EmpiricalTransiogram(gtb, "FACIES", maxlag=20, nlags=20)
τ = PiecewiseLinearTransiogram(t.abscissas, t.ordinates)
@test τ(0.0u"m") == I(5)
@test all(x -> 0 < x < 1, τ(5.0u"m"))
@test all(allequal, eachcol(τ(100.0u"m")))
end

0 comments on commit a802c58

Please sign in to comment.