From f413f669f6d7c2fad1feeabc6b5031231bd2fdf1 Mon Sep 17 00:00:00 2001 From: Iago-lito Date: Tue, 18 Apr 2023 14:15:38 +0200 Subject: [PATCH] Define global convenience `Solution` type alias. --- Project.toml | 2 +- src/EcologicalNetworksDynamics.jl | 3 +++ src/measures/functioning.jl | 6 +++--- src/measures/stability.jl | 11 +++++------ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Project.toml b/Project.toml index edc6a65cb..2b467b9bd 100644 --- a/Project.toml +++ b/Project.toml @@ -13,6 +13,6 @@ EcologicalNetworks = "f03a62fe-f8ab-5b77-a061-bb599b765229" Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" Mangal = "b8b640a6-63d9-51e6-b784-5033db27bef2" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" - diff --git a/src/EcologicalNetworksDynamics.jl b/src/EcologicalNetworksDynamics.jl index ec87a2a89..f04073480 100644 --- a/src/EcologicalNetworksDynamics.jl +++ b/src/EcologicalNetworksDynamics.jl @@ -37,7 +37,10 @@ using OrderedCollections using SparseArrays using Statistics using Decimals +using SciMLBase +# Convenience aliases. +const Solution = SciMLBase.AbstractODESolution # Include scripts include(joinpath(".", "macros.jl")) diff --git a/src/measures/functioning.jl b/src/measures/functioning.jl index 03ef84998..96d2c4c13 100644 --- a/src/measures/functioning.jl +++ b/src/measures/functioning.jl @@ -525,7 +525,7 @@ function aggregate_trophic_level(op_name, aggregate_function) return quote @doc $docstring function $op_trophic_level( - solution::SciMLBase.ODESolution; + solution::Solution; threshold = 0, kwargs..., ) @@ -568,7 +568,7 @@ end """ - living_species(solution; threshold, kwargs...) + living_species(solution::Solution; threshold, kwargs...) Returns the vectors of alive species and their indices in the original network. Living species are the ones having, in average, a biomass above `threshold` over @@ -596,7 +596,7 @@ julia> B0 = [0, 0.5, 0.5]; ``` """ function living_species( - solution::SciMLBase.ODESolution; + solution::Solution; threshold = 0, idxs = nothing, kwargs..., diff --git a/src/measures/stability.jl b/src/measures/stability.jl index 1852060d1..25cb5f17b 100644 --- a/src/measures/stability.jl +++ b/src/measures/stability.jl @@ -3,14 +3,13 @@ Various measures of stability =# """ - species_cv(solution; threshold, kwargs...) + species_cv(solution::Solution; threshold, kwargs...) Computes the temporal coefficient of variation of species biomass and its average. See [`coefficient_of_variation`](@ref) for the details. """ -function species_cv(solution::SciMLBase.ODESolution; threshold = 0, last = "10%", kwargs...) - +function species_cv(solution::Solution; threshold = 0, last = "10%", kwargs...) measure_on = extract_last_timesteps(solution; last, kwargs...) # Fetch species that are alive, whose avg biomass is > threshold living_sp = living_species(measure_on; threshold) @@ -54,7 +53,7 @@ Neutral and Nonneutral Community Dynamics in Fluctuating Environments. The American Naturalist, 172(2), E48‑E66. https://doi.org/10.1086/589746 """ function synchrony( - solution::SciMLBase.ODESolution; + solution::Solution; threshold = 0, last = "10%", corrected = true, @@ -96,7 +95,7 @@ Compute the temporal Coefficient of Variation of community biomass. See [`coefficient_of_variation`](@ref) for the argument details. """ function community_cv( - solution::SciMLBase.ODESolution; + solution::Solution; threshold = 0, last = "10%", corrected = true, @@ -164,7 +163,7 @@ julia> B0 = [0, 0.5, 0.5]; # Two producers ``` """ function coefficient_of_variation( - solution; + solution::Solution; threshold = 0, last = "10%", corrected = true,