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/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1.8.0]
julia-version: ["lts"]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/RunTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: ["1.8"]
julia-version: ["1", "1.9", "lts"]
julia-arch: [x64]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
Expand Down
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
name = "SpatialBoundaries"
uuid = "8d2ba62a-3d23-4a2b-b692-6b63e9267be2"
authors = ["Tanya Strydom <tanya.strydom@umontreal.ca>", "Timothée Poisot <timothee.poisot@umontreal.ca>"]
version = "0.1.0"
version = "0.2.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SpeciesDistributionToolkit = "72b53823-5c0b-4575-ad0e-8e97227ad13b"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
VoronoiDelaunay = "72f80fcb-8c52-57d9-aff0-40c1a3526986"

[compat]
SpeciesDistributionToolkit = "0.0.1, 0.0.2, 0.0.3"
StatsBase = "0.33"
StatsBase = "0.34"
VoronoiDelaunay = "0.4"
julia = "1.8"
julia = "1.9"
9 changes: 2 additions & 7 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
NeutralLandscapes = "71847384-8354-4223-ac08-659a5128069f"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
SpeciesDistributionToolkit = "72b53823-5c0b-4575-ad0e-8e97227ad13b"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"

[compat]
SpeciesDistributionToolkit = "0.0"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
7 changes: 1 addition & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ makedocs(;
sitename = "SpatialBoundaries",
format = Documenter.HTML(),
modules = [SpatialBoundaries],
warnonly = true,
pages = [
"Home" => [
"Introduction" => "vignettes/introduction.md",
Expand All @@ -23,18 +24,12 @@ makedocs(;
"Vignettes" => [
"Finding boundaries" => "vignettes/boundaries.md",
"Triangulation wombling" => "vignettes/triangulation.md",
"SDM Layers" => "vignettes/simplesdmlayers.md",
],
],
)

@info "Prepare to remove"
run(`find . -type f -name ".tif" -delete`)
run(`find . -type f -name ".tif"`)

@info "Prepare to deploy"
deploydocs(;
deps = Deps.pip("pygments", "python-markdown-math"),
repo = "github.com/PoisotLab/SpatialBoundaries.jl.git",
push_preview = true,
devbranch = "main",
Expand Down
22 changes: 12 additions & 10 deletions docs/src/vignettes/boundaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
# three-patch landscape.

using SpatialBoundaries
using StatsPlots
default(; dpi=500, size=(600, 600), aspectratio=1, c=:batlow, frame=:box)
using CairoMakie

# Let's create a landscape with two values:

Expand All @@ -26,7 +25,7 @@ W = wombling(A);

# Let's look at the rate of change:

heatmap(W.m; c=:nuuk)
heatmap(W.m; colormap = :Greys)

# Picking the boundaries is done by passing the wombling output to the
# `boundaries` function, with a specific threshold giving the proportion of
Expand All @@ -36,9 +35,11 @@ heatmap(W.m; c=:nuuk)
thresholds = LinRange(0.0, 0.2, 200)
patches = [length(boundaries(W, t)) for t in thresholds]

plot(thresholds, log1p.(patches), aspectratio=:none)
xaxis!("Threshold", (0., 0.2))
yaxis!("log(boundary patches + 1)", (0., 9.))
f, ax, plt = lines(thresholds, log1p.(patches), color=:black, linewidth=2)
tightlimits!(ax)
ax.xlabel = "Threshold"
ax.ylabel = "log(boundary patches + 1)"
f

# Let's eyeball this as 0.01, and see how the patches are distributed.

Expand All @@ -49,11 +50,11 @@ yaxis!("log(boundary patches + 1)", (0., 9.))

b = similar(W.m)

for t in reverse(LinRange(0.0, 1.0, 200))
for t in reverse(LinRange(0.0, 1.0, 300))
b[boundaries(W, t)] .= t
end

heatmap(b, c=:tofino, clim=(0,1))
heatmap(b, colormap=:tofino, colorrange=(0,1))

# This also suggests that we will get well delineated patches for low values of
# the threshold.
Expand All @@ -63,7 +64,8 @@ B = boundaries(W, 0.01);
# In the following figure, cells identified as candidate boundaries are marked
# in white:

heatmap(A)
scatter!([(reverse(x.I)) for x in B], leg=false, msw=0, c=:white)
f, ax, hm = heatmap(A)
scatter!(ax, [b.I for b in B], color=:white)
f

# We can see that the boundaries of the patches have been well identified!
10 changes: 3 additions & 7 deletions docs/src/vignettes/introduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,7 @@

using SpatialBoundaries
using NeutralLandscapes
using StatsPlots

# We will set a few options for the default plots:

default(; dpi=500, size=(600, 600), aspectratio=1, c=:davos, frame=:box)
using CairoMakie

# The landscape generation is done using the `NeutralLandscapes` package, and we
# will pick a 500x500 grid:
Expand Down Expand Up @@ -76,7 +72,7 @@ W = wombling(landscape);

# Let's have a look at the rate of change:

heatmap(W.m, c=:tokyo, clim=(0, maximum(W.m)))
heatmap(W.m, colormap=:navia, colorrange=(0, maximum(W.m)))

# The rate of change informs us on the potential for there to be a boundary
# (zone of change) within a window. Cells with a high rate of change are
Expand All @@ -87,7 +83,7 @@ heatmap(W.m, c=:tokyo, clim=(0, maximum(W.m)))
# for instance, an angle of 180° means that the value is smaller in the South,
# and larger in the North:

heatmap(W.θ, c=:romaO, clim=(0., 360.))
heatmap(W.θ, colormap=:romaO, colorrange=(0., 360.))

# The direction of change is *not* the direction the boundary would be if you
# were to draw it on the landscape but rather the direction the rate of change
Expand Down
143 changes: 0 additions & 143 deletions docs/src/vignettes/simplesdmlayers.jl

This file was deleted.

33 changes: 14 additions & 19 deletions docs/src/vignettes/triangulation.jl
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
# # Triangulation wombling

using SpatialBoundaries
using StatsPlots

# Plot defaults

default(; dpi=500, size=(600, 600), aspectratio=1, c=:davos, frame=:box)
using CairoMakie
using StatsBase

# Get some points at random

n = 500
x = rand(n)
x = 2rand(n)
y = rand(n)
z = [(x[i]<=0.5)&(y[i]<=0.5) ? rand() : rand().+1.2 for i in eachindex(x)]
z = [(x[i] <= 0.5) & (y[i] <= 0.5) ? rand() : rand() .+ 1.2 for i in eachindex(x)]

scatter(x, y, marker_z = z, lab="")
scatter(x, y; color = z)

# Womble

W = wombling(x, y, z)

# Get the rate of change

scatter(x, y, c=:lightgrey, msw=0.0, lab="", m=:square, ms=3)
scatter!(W.x, W.y, marker_z = log1p.(W.m), lab="")
scatter(x, y; color = :lightgrey)
scatter!(W.x, W.y; color = log1p.(W.m))
current_figure()

# Angle histogram

stephist(
deg2rad.(sort(vec(W.θ)));
proj=:polar,
lab="",
c=:teal,
fill=(0, 0.2, :teal),
nbins=100,
)
f = Figure()
ax = PolarAxis(f[1, 1])
h = fit(Histogram, deg2rad.(values(W.θ)); nbins = 100)
stairs!(ax, h.edges[1], h.weights[[axes(h.weights, 1)..., 1]]; color = :teal, linewidth = 2)
current_figure()

# Show the rotation with a color

scatter(W.x, W.y, marker_z = W.θ, c=:vik, clim=(0, 360))
scatter(W.x, W.y; color = W.θ, colormap = :vikO, colorrange = (0, 360))
2 changes: 0 additions & 2 deletions src/SpatialBoundaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ using VoronoiDelaunay
using LinearAlgebra
using Statistics
using StatsBase
using SpeciesDistributionToolkit

include(joinpath("types", "Womble.jl"))
export Womble, TriangulationWomble, LatticeWomble

include(joinpath("lib", "rateofchange.jl"))

include(joinpath("lib", "wombling.jl"))
include(joinpath("extensions", "SpeciesDistributionToolkit.jl"))
export wombling

include(joinpath("lib", "boundaries.jl"))
Expand Down
Loading