Skip to content

Commit

Permalink
Add more tests for trend
Browse files Browse the repository at this point in the history
  • Loading branch information
juliohm committed Sep 18, 2023
1 parent 2c40874 commit 02917a3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test/detrend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,32 @@
D = Tables.matrix(values(d))
R = Tables.matrix(values(r))
@test isapprox(D, R, atol=1e-6)

rng = MersenneTwister(42)
# constant trend
d = georef((z=rand(rng, 100),), CartesianGrid(100))
= GeoStatsTransforms.trend(d, :z).z
@test all(abs.(diff(z̄)) .< 0.01)

# linear trend
μ = range(0, stop=1, length=100)
ϵ = 0.1rand(rng, 100)
d = georef((z=μ + ϵ,), CartesianGrid(100))
= GeoStatsTransforms.trend(d, :z).z
@test all([abs(z̄[i] - μ[i]) < 0.1 for i in 1:length(z̄)])

# quadratic trend
r = range(-1, stop=1, length=100)
μ = [x^2 + y^2 for x in r, y in r]
ϵ = 0.1rand(rng, 100, 100)
d = georef((z=μ + ϵ,))
= GeoStatsTransforms.trend(d, :z, degree=2)
= reshape(d̄.z, 100, 100)
@test all([abs(z̄[i] - μ[i]) < 0.1 for i in 1:length(z̄)])

d = georef((x=rand(rng, 10), y=rand(rng, 10)), rand(rng, 2, 10))
𝒯 = d |> GeoStatsTransforms.trend |> values
s = Tables.schema(𝒯)
@test s.names == (:x, :y)
@test s.types == (Float64, Float64)
end

0 comments on commit 02917a3

Please sign in to comment.