From 0eb4f162268f44ca02c89711b633799b262d853a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Sun, 12 Feb 2023 16:11:33 -0500 Subject: [PATCH 01/10] vignette updated? --- Project.toml | 8 +-- docs/Project.toml | 5 +- docs/src/vignettes/simplesdmlayers.jl | 51 +++++++++---------- src/SpatialBoundaries.jl | 8 +-- ...ayers.jl => SpeciesDistributionToolkit.jl} | 6 +-- 5 files changed, 36 insertions(+), 42 deletions(-) rename src/extensions/{SimpleSDMLayers.jl => SpeciesDistributionToolkit.jl} (82%) diff --git a/Project.toml b/Project.toml index 4641b0a..e75be22 100644 --- a/Project.toml +++ b/Project.toml @@ -1,17 +1,17 @@ name = "SpatialBoundaries" uuid = "8d2ba62a-3d23-4a2b-b692-6b63e9267be2" authors = ["Tanya Strydom ", "Timothée Poisot "] -version = "0.0.4" +version = "0.1.0" [deps] LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" -Requires = "ae029012-a4dd-5104-9daa-d747884805df" +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] -Requires = "1" +SpeciesDistributionToolkit = "0.0.1" StatsBase = "0.33" VoronoiDelaunay = "0.4" -julia = "1.6" +julia = "1.8" diff --git a/docs/Project.toml b/docs/Project.toml index 04dc21d..e270666 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -3,8 +3,9 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306" NeutralLandscapes = "71847384-8354-4223-ac08-659a5128069f" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" -SimpleSDMLayers = "2c645270-77db-11e9-22c3-0f302a89c64c" +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" +SpeciesDistributionToolkit = "2c645270-77db-11e9-22c3-0f302a89c64c" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" [compat] -SimpleSDMLayers = "0.8" +SimpleSDMLayers = "0.0" diff --git a/docs/src/vignettes/simplesdmlayers.jl b/docs/src/vignettes/simplesdmlayers.jl index 45cf5f5..62f307e 100644 --- a/docs/src/vignettes/simplesdmlayers.jl +++ b/docs/src/vignettes/simplesdmlayers.jl @@ -20,8 +20,9 @@ # $y$, $z$) and the output data would be typed as `TriangulationWomble` objects. using SpatialBoundaries -using SimpleSDMLayers -using Plots +using SpeciesDistributionToolkit +using CairoMakie +import Plots # Required for radial histograms # First we can start by defining the extent of the Southwestern islands of # Hawaii, which can be used to restrict the extraction of the various landcover @@ -29,15 +30,17 @@ using Plots # `SimpleSDMLayers`: hawaii = (left = -160.2, right = -154.5, bottom = 18.6, top = 22.5) -landcover = SimpleSDMPredictor(EarthEnv, LandCover, 1:12; hawaii...) +dataprovider = RasterData(EarthEnv, LandCover) +landcover_classes = SimpleSDMDatasets.layers(dataprovider) +landcover = [SimpleSDMPredictor(dataprovider; layer=class, full=true, hawaii...) for class in landcover_classes] # We can remove all the areas that contain 100% water from the landcover data as # our question of interest is restricted to the terrestrial realm. We do this by # using the "Open Water" layer to mask over each of the landcover layers # individually: -ow_index = findfirst(isequal("Open Water"), layernames(EarthEnv, LandCover)) -not_water = broadcast(!isequal(100), landcover[ow_index]) +ow_index = findfirst(isequal("Open Water"), landcover_classes) +not_water = landcover[ow_index] .!== 0x64 lc = [mask(not_water, layer) for layer in landcover] # As layers one through four of the EarthEnv data are concerned with data on @@ -45,10 +48,11 @@ lc = [mask(not_water, layer) for layer in landcover] # Broadleaf Trees", "Deciduous Broadleaf Trees", and "Mixed/Other Trees") we # will work with only these layers. For a quick idea we of what the raw # landcover data looks like we can sum these four layers and plot the total -# woody cover for the Southwestern islands. +# woody cover: -tree_lc = convert(Float32, sum(lc[1:4])) -plot(tree_lc; c = :Greens, frame = :box, leg = false) +classes_with_trees = findall(contains.(landcover_classes, "Trees")) +tree_lc = convert(Float32, reduce(+, lc[classes_with_trees])) +heatmap(tree_lc; colormap=:linear_kbgyw_5_98_c62_n256) # Although we have previously summed the four landcover layers for the actual # wombling part we will apply the wombling function to each layer before we @@ -57,7 +61,7 @@ plot(tree_lc; c = :Greens, frame = :box, leg = false) # woody cover layers. This will give as a vector containing four `LatticeWomble` # objects (since the input data was in the form of a matrix). -wombled_layers = broadcast(wombling, (lc[1:4])) +wombled_layers = wombling.(lc[classes_with_trees]); # As we are interested in overall woody cover for Southwestern islands we can # take the `wombled_layers` vector and use them with the `mean` function to get @@ -65,7 +69,7 @@ wombled_layers = broadcast(wombling, (lc[1:4])) # cover. This will 'flatten' the four wombled layers into a single # `LatticeWomble` object. -wombled_mean = mean(wombled_layers) +wombled_mean = mean(wombled_layers); # From the `wombled_mean` object we can 'extract' the layers for both the mean # rate and direction of change. For ease of plotting we will also convert these @@ -81,21 +85,14 @@ rate, direction = SimpleSDMPredictor(wombled_mean) # and this is simply for ease of plotting. b = similar(rate) +b.grid[boundaries(wombled_mean, 0.1; ignorezero = true)] .= 1.0 -for t in 0.1 - b.grid[boundaries(wombled_mean, t; ignorezero = true)] .= t -end +# We will overlay the identified boundaries (in green) over the rate of change +# (in levels of grey): -# In addition to being used to help find candidate boundary cells we can also -# use this object (`b`) as masking layer when visualising wombling outputs. In -# this case we can view the `rate` layer in a similar fashion to the original -# landcover layer but by masking it with `b` we only plot the candidate -# boundaries *i.e.* the cells with the top 10% of highest rate of change values. - -plot( - plot(rate; c = :grey85, frame = :box), - mask(b, rate); - c = :black, frame = :box, colorbar = false) +heatmap(rate, colormap=[:grey95, :grey5]) +heatmap!(b, colormap=[:transparent, :green]) +current_figure() # For this example we will plot the direction of change as radial plots to get # an idea of the prominent direction of change. Here we will plot *all* the @@ -120,8 +117,8 @@ direction_candidate = mask(b, direction) # collect the cells and convert them from degrees to radians. Then we can start # by plotting the direction of change of *all* cells. -stephist( - deg2rad.(collect(direction_all)); +Plots.stephist( + deg2rad.(values(direction_all)); proj=:polar, lab="", c=:teal, @@ -132,8 +129,8 @@ stephist( # Followed by plotting the direction of change only for cells that are # considered as candidate boundary cells. -stephist( - deg2rad.(collect(direction_candidate)); +Plots.stephist( + deg2rad.(values(direction_candidate)); proj=:polar, lab="", c=:red, diff --git a/src/SpatialBoundaries.jl b/src/SpatialBoundaries.jl index eaf5dc8..a021e8f 100644 --- a/src/SpatialBoundaries.jl +++ b/src/SpatialBoundaries.jl @@ -5,7 +5,7 @@ using VoronoiDelaunay using LinearAlgebra using Statistics using StatsBase -using Requires +using SpeciesDistributionToolkit include(joinpath("types", "Womble.jl")) export Womble, TriangulationWomble, LatticeWomble @@ -21,10 +21,6 @@ export boundaries include(joinpath("lib", "overallmean.jl")) export mean -function __init__() - @require SimpleSDMLayers = "2c645270-77db-11e9-22c3-0f302a89c64c" include( - joinpath("extensions", "SimpleSDMLayers.jl"), - ) -end +joinpath("extensions", "SpeciesDistributionToolkit.jl") end # module \ No newline at end of file diff --git a/src/extensions/SimpleSDMLayers.jl b/src/extensions/SpeciesDistributionToolkit.jl similarity index 82% rename from src/extensions/SimpleSDMLayers.jl rename to src/extensions/SpeciesDistributionToolkit.jl index 41e5a2a..fbed29a 100644 --- a/src/extensions/SimpleSDMLayers.jl +++ b/src/extensions/SpeciesDistributionToolkit.jl @@ -3,7 +3,7 @@ Performs a lattice wombling on a `SimpleSDMLayer`. """ -function wombling(layer::T; convert_to::Type = Float64) where {T <: SimpleSDMLayers.SimpleSDMLayer} +function SpatialBoundaries.wombling(layer::T; convert_to::Type = Float64) where {T <: SimpleSDMLayer} try global nan = convert(convert_to, NaN) catch @@ -24,7 +24,7 @@ end # adding this method makes the code easier to write Base.isnan(::Nothing) = false -function SimpleSDMLayers.SimpleSDMPredictor(W::T) where {T <: LatticeWomble} +function SimpleSDMPredictor(W::T) where {T <: LatticeWomble} rate = SimpleSDMLayers.SimpleSDMPredictor(W.m, extrema(W.y)..., extrema(W.x)...) direction = SimpleSDMLayers.SimpleSDMPredictor(W.θ, extrema(W.y)..., extrema(W.x)...) rate.grid[findall(isnan, rate.grid)] .= nothing @@ -32,6 +32,6 @@ function SimpleSDMLayers.SimpleSDMPredictor(W::T) where {T <: LatticeWomble} return (rate, direction) end -function SimpleSDMLayers.SimpleSDMResponse(W::T) where {T <: LatticeWomble} +function SimpleSDMResponse(W::T) where {T <: LatticeWomble} return convert.(SimpleSDMLayers.SimpleSDMResponse, SimpleSDMLayers.SimpleSDMPredictor(W)) end From 0550af3e5d032172f5c0c242b06c072d430c272a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 08:48:17 -0500 Subject: [PATCH 02/10] =?UTF-8?q?=F0=9F=A4=96=20fix=20versions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/CompatHelper.yml | 2 +- .github/workflows/RunTests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 585661c..1d3aec7 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -9,7 +9,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: [1.6.0] + julia-version: [1.8.0] julia-arch: [x86] os: [ubuntu-latest] steps: diff --git a/.github/workflows/RunTests.yml b/.github/workflows/RunTests.yml index 5a1a0d3..8f04439 100644 --- a/.github/workflows/RunTests.yml +++ b/.github/workflows/RunTests.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - julia-version: ["1.6", "1.7", "1.8"] + julia-version: ["1.8"] julia-arch: [x64] os: [ubuntu-latest] From bb31aa6e6065a7454db91662bcdd49bc7d284dce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 08:49:57 -0500 Subject: [PATCH 03/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20SpeciesDistributionT?= =?UTF-8?q?oolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Project.toml b/docs/Project.toml index e270666..ff6d434 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,4 +8,4 @@ SpeciesDistributionToolkit = "2c645270-77db-11e9-22c3-0f302a89c64c" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" [compat] -SimpleSDMLayers = "0.0" +SpeciesDistributionToolkit = "0.0" From 386f74c8f2ee144d60fc3664c4c4ac3d9af815b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 08:52:58 -0500 Subject: [PATCH 04/10] fix version --- docs/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/Project.toml b/docs/Project.toml index ff6d434..3b8052a 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -8,4 +8,4 @@ SpeciesDistributionToolkit = "2c645270-77db-11e9-22c3-0f302a89c64c" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" [compat] -SpeciesDistributionToolkit = "0.0" +SpeciesDistributionToolkit = "0.0.1" From ddf713cddce4d545814154d722d57a5ef6b679c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 08:53:56 -0500 Subject: [PATCH 05/10] =?UTF-8?q?=F0=9F=90=9B=20fix=20the=20hash=20for=20S?= =?UTF-8?q?peciesDistributionToolkit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/Project.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Project.toml b/docs/Project.toml index 3b8052a..af3b078 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -4,8 +4,8 @@ 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 = "2c645270-77db-11e9-22c3-0f302a89c64c" +SpeciesDistributionToolkit = "72b53823-5c0b-4575-ad0e-8e97227ad13b" StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd" [compat] -SpeciesDistributionToolkit = "0.0.1" +SpeciesDistributionToolkit = "0.0" From ad4734506452c5e9390a41ac0a91e8bdca2a2e5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 09:26:27 -0500 Subject: [PATCH 06/10] =?UTF-8?q?=E2=9C=85=20fix=20integration=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/units/R1_simplesdmlayers.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/test/units/R1_simplesdmlayers.jl b/test/units/R1_simplesdmlayers.jl index 2f4ef62..5b3b9c2 100644 --- a/test/units/R1_simplesdmlayers.jl +++ b/test/units/R1_simplesdmlayers.jl @@ -1,13 +1,12 @@ module SBTestSimpleSDMLayers using SpatialBoundaries -using SimpleSDMLayers +using SpeciesDistributionToolkit using Test precipitation = SimpleSDMPredictor( - WorldClim, - BioClim, - 12; + RasterData(WorldClim, BioClim), + layer=12; left = -80.0, right = -56.0, bottom = 44.0, From 0f0459833fe02bbcc52782e1a31df9ca2bc93b81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 09:34:04 -0500 Subject: [PATCH 07/10] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20switch=20to=20SDT=20?= =?UTF-8?q?in=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Project.toml b/test/Project.toml index cced248..b0487c8 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,4 +1,4 @@ [deps] NeutralLandscapes = "71847384-8354-4223-ac08-659a5128069f" -SimpleSDMLayers = "2c645270-77db-11e9-22c3-0f302a89c64c" +SpeciesDistributionToolkit = "72b53823-5c0b-4575-ad0e-8e97227ad13b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" From 1c976a52008a1b1f9ed3b8a0f120b8ca34820ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 09:41:28 -0500 Subject: [PATCH 08/10] =?UTF-8?q?=F0=9F=90=9B=20wrong=20dataset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/units/R1_simplesdmlayers.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/R1_simplesdmlayers.jl b/test/units/R1_simplesdmlayers.jl index 5b3b9c2..4debfe9 100644 --- a/test/units/R1_simplesdmlayers.jl +++ b/test/units/R1_simplesdmlayers.jl @@ -5,7 +5,7 @@ using SpeciesDistributionToolkit using Test precipitation = SimpleSDMPredictor( - RasterData(WorldClim, BioClim), + RasterData(WorldClim2, BioClim), layer=12; left = -80.0, right = -56.0, From 10fb7696e4193de7c3b9ba94e26f1e6f7f1bdb60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 09:50:56 -0500 Subject: [PATCH 09/10] =?UTF-8?q?=F0=9F=9A=B6=20actually=20include=20the?= =?UTF-8?q?=20extension=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SpatialBoundaries.jl | 3 +-- src/extensions/SpeciesDistributionToolkit.jl | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/SpatialBoundaries.jl b/src/SpatialBoundaries.jl index a021e8f..01c654f 100644 --- a/src/SpatialBoundaries.jl +++ b/src/SpatialBoundaries.jl @@ -13,6 +13,7 @@ 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")) @@ -21,6 +22,4 @@ export boundaries include(joinpath("lib", "overallmean.jl")) export mean -joinpath("extensions", "SpeciesDistributionToolkit.jl") - end # module \ No newline at end of file diff --git a/src/extensions/SpeciesDistributionToolkit.jl b/src/extensions/SpeciesDistributionToolkit.jl index fbed29a..44fb774 100644 --- a/src/extensions/SpeciesDistributionToolkit.jl +++ b/src/extensions/SpeciesDistributionToolkit.jl @@ -3,7 +3,7 @@ Performs a lattice wombling on a `SimpleSDMLayer`. """ -function SpatialBoundaries.wombling(layer::T; convert_to::Type = Float64) where {T <: SimpleSDMLayer} +function wombling(layer::T; convert_to::Type = Float64) where {T <: SimpleSDMLayer} try global nan = convert(convert_to, NaN) catch From bc018bf2b50f725b22166b16292da2764bf5c474 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Poisot?= Date: Mon, 13 Feb 2023 09:57:42 -0500 Subject: [PATCH 10/10] =?UTF-8?q?=F0=9F=A6=86=20correct=20overloading?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/extensions/SpeciesDistributionToolkit.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extensions/SpeciesDistributionToolkit.jl b/src/extensions/SpeciesDistributionToolkit.jl index 44fb774..12c867f 100644 --- a/src/extensions/SpeciesDistributionToolkit.jl +++ b/src/extensions/SpeciesDistributionToolkit.jl @@ -24,7 +24,7 @@ end # adding this method makes the code easier to write Base.isnan(::Nothing) = false -function SimpleSDMPredictor(W::T) where {T <: LatticeWomble} +function SimpleSDMLayers.SimpleSDMPredictor(W::T) where {T <: LatticeWomble} rate = SimpleSDMLayers.SimpleSDMPredictor(W.m, extrema(W.y)..., extrema(W.x)...) direction = SimpleSDMLayers.SimpleSDMPredictor(W.θ, extrema(W.y)..., extrema(W.x)...) rate.grid[findall(isnan, rate.grid)] .= nothing @@ -32,6 +32,6 @@ function SimpleSDMPredictor(W::T) where {T <: LatticeWomble} return (rate, direction) end -function SimpleSDMResponse(W::T) where {T <: LatticeWomble} +function SimpleSDMLayers.SimpleSDMResponse(W::T) where {T <: LatticeWomble} return convert.(SimpleSDMLayers.SimpleSDMResponse, SimpleSDMLayers.SimpleSDMPredictor(W)) end