Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A clear and concise description of what the bug is.
A [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) that is enough to show what the problem is

~~~ julia
using SimpleSDMLayers
using SpatialBoundaries

# Add your code here
~~~
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ A clear and concise description of what you want to happen.
Ideally, this can take the form of code you would like to write:

~~~ julia
using SimpleSDMLayers
using SpatialBoundaries

# Write your dream code here
~~~
Expand Down
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SpatialBoundaries"
uuid = "8d2ba62a-3d23-4a2b-b692-6b63e9267be2"
authors = ["Tanya Strydom <tanya.strydom@umontreal.ca>", "Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.2.0"
version = "0.2.1"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Expand All @@ -10,6 +10,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
VoronoiDelaunay = "72f80fcb-8c52-57d9-aff0-40c1a3526986"

[compat]
Statistics = "1"
StatsBase = "0.34"
VoronoiDelaunay = "0.4"
julia = "1.9"
4 changes: 2 additions & 2 deletions src/lib/overallmean.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ function Statistics.mean(w::Vector{T}) where {T <: Womble}
di = filter(!isnan, [deg2rad(womble.θ[_idx]) for womble in w])
if !isempty(ch)
m[_idx] = mean(ch)
α[_idx] = atan(mean(sin.(di)), mean(cos.(di)))
α[_idx] = atan(sum(sin.(di)), sum(cos.(di)))
end
end
average_direction = rad2deg.(α) .+ 180.0
average_direction = rad2deg.(α .- π)
if w[1] isa LatticeWomble
return LatticeWomble(m, average_direction, w[1].x, w[1].y)
end
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
global anyerrors = false

tests = [
"mock test" => "00_allgood.jl",
"Mock test" => "00_allgood.jl",
"Linear gradient" => "01_gradient.jl",
"Boundaries detection" => "02_boundaries.jl",
"Triangulation wombling" => "03_delaunay.jl",
"Direction of change" => "04_direction.jl",
"Overall mean wombling" => "05_mean.jl",
"Correct values are returned" => "06_values.jl",
"Overall mean correct values are returned" => "07_overallmean.jl"
]

for test in tests
Expand Down
21 changes: 21 additions & 0 deletions test/units/06_values.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module SBTestGradient

using SpatialBoundaries
using NeutralLandscapes
using Test

angles = rand(100) .* 360

for angle in angles
landscape = rand(PlanarGradient(angle), 20, 20)
x = collect(LinRange(0.2, 1.8, size(landscape, 1)))
y = collect(LinRange(0.2, 1.8, size(landscape, 2)))

W = wombling(x, y, landscape)

for θ in W.θ
@test deg2rad(abs(θ - angle)) ≈ π atol = 0.01
end
end

end
32 changes: 32 additions & 0 deletions test/units/07_overallmean.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module SBTestGradient

using SpatialBoundaries
using NeutralLandscapes
using Test

angles = rand(100) .* 360

for replicate in Base.OneTo(10)
θ1 = rand(angles)
θ2 = rand(angles)
L1 = rand(PlanarGradient(θ1), 20, 20)
L2 = rand(PlanarGradient(θ2), size(L1)...)
x = collect(LinRange(0.2, 1.8, size(L1, 1)))
y = collect(LinRange(0.2, 1.8, size(L1, 2)))

W = mean([wombling(x, y, L) for L in [L1, L2]])

α1 = deg2rad(θ1)
α2 = deg2rad(θ2)
target = atan(sin(α1)+sin(α2), cos(α1)+cos(α2))
observed = deg2rad(rand(W.θ))

diff = (target-observed) - 2π
if abs(diff) > 0.01
@test diff ≈ -2π atol = 0.001
else
@test diff ≈ 0.0 atol = 0.001
end
end

end
Loading