Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
richardreeve committed Apr 11, 2024
1 parent 1d95c68 commit 887fdf2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
11 changes: 7 additions & 4 deletions docs/src/africa.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ EcoSISTEM was designed to scale to much larger areas, supporting many more speci

We can also explore the behaviour of selective advantage of specialist species over generalists at these scales. When we introduce a specialist species into an African-sized landscape with an existing generalist, the specialist out-competes the generalist and spreads throughout the continent. The larger the selective advantage of the specialist, the faster it is able to invade and colonise across the landscape (Figure 1). These same dynamics can be seen when we introduce a specialist to the full complement of 50,000 species (Figure 1B-D).

#### SINGLE SPECIES ####
## SINGLE SPECIES

```julia
using EcoSISTEM
Expand Down Expand Up @@ -141,7 +141,7 @@ for i in eachindex(specialist_vars)
dest = findall(abuns[2, :, :, 1] .> 0)
inst_velocity = map(1:lensim) do t
dest = findall(abuns[2, :, :, t] .> 0)
dists = [euclidean(origin, [dest[i][1], dest[i][2]]) for i in length(dest)] .* getgridsize(eco)
dists = [euclidean(origin, [dest[i][1], dest[i][2]]) for i in eachindex(dest)] .* getgridsize(eco)
return maximum(dists)/month
end
velocity[i] = mean(inst_velocity)
Expand All @@ -151,9 +151,12 @@ plot(ustrip.(abs.(specialist_vars .- 50.0K)), ustrip.(velocity),
xlab = "Selective advantage", ylab = "Invasion speed (km/month)",
label = "", grid = false)
```

![](Invasion.svg)
*Figure 1: Invasive capacity of a specialist plant species versus a generalist. Selective advantage is the difference in niche width between the specialist and generalist, and invasion speed is calculated as the average distance travelled per month by the specialist.*
#### ONE SPECIALIST VERSUS MANY GENERALISTS ####

## ONE SPECIALIST VERSUS MANY GENERALISTS

``` julia
using EcoSISTEM
using EcoSISTEM.ClimatePref
Expand Down Expand Up @@ -231,7 +234,7 @@ eco.abundances.grid[50_000, rand_start[1], rand_start[2]] = 100
@time simulate!(eco, times, timestep, record_interval, "examples/Biodiversity", "Africa_run");
```
#### 50,000 SPECIES COEXISTING #####
## 50,000 SPECIES COEXISTING
```julia
using EcoSISTEM
Expand Down
5 changes: 4 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
```

```@autodocs
Modules = [EcoSISTEM]
Modules = [EcoSISTEM, EcoSISTEM.ClimatePref]
Private = true
```

```@index
```
6 changes: 4 additions & 2 deletions docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Here we describe several properties that the model ecosystem should be able to r
- Large numbers of species are sustained over large areas.

What follows are several examples of this operating in practice.

```julia
using EcoSISTEM
using EcoSISTEM.Units
Expand All @@ -24,10 +25,10 @@ using Diversity
plotlyjs()
```


## 1. Different niche preferences and widths

Here we compare the abundances of species with different temperature preferences and tolerances. On a small patch,we explored the abundance of species given different niche preferences, with all other parameters kept equal. We found that species with niche preference nearer to the 25°C optimum were more abundant, when all species were given the same niche widths. Additionally, when all species had a preference for the 25°C climate and a range of niche widths, those with broader niche widths (generalists) were less abundant than species with narrow (specialists). If the temperature in the ecosystem was then increased by 1°C, those with the narrowest niches went extinct, and the generalists became more abundant, with a preference for those with a niche width of around 1°C as we would expect.

``` julia
numSpecies = 100; grd = (10,10); req=(450000.0kJ/m^2, 192.0nm/m^2);
individuals = 100_000_000; area = 100.0*km^2;
Expand Down Expand Up @@ -465,10 +466,10 @@ left_margin = 20.0 *Plots.mm, ylim = (0, 1))
![](Abundance.svg)
*Model testing on island ecosystems. (A) Total abundance of 100 species, with varying resources of water and solar energy across the grid. (B) Total abundance of 100 species, with increasing area size. (C) Total abundance of 100 species, with increasing grid square resolution. (D) Percentage of species survived after 10 years of simulation.*


## 3. Dispersal

Finally, we verify that dispersal is functioning as expected. This figure shows the overall abundance of an island populated with two species at opposite extremes of the ecosystem after ten years of simulation. The species moved faster and further into the unpopulated island centre when they had higher average dispersal distances, though again with some edge effects.

```julia
times = 50years; timestep = 1month
lensim = length(0month:timestep:times)
Expand Down Expand Up @@ -536,5 +537,6 @@ for i in 1:4
clim = (0, 1.5e4), link = :both))
end
```

![](DispersalSD.svg)
*Total abundance of two species in island ecosystems after 10 years of simulation, with species populated at opposite sides of the island. Those with higher dispersal distances moved further away from their starting populations at a faster rate. (A) Mean dispersal distance of 0.5km, (B) mean dispersal distance of 1km, (C) Mean dispersal distance of 2km, Mean dispersal distance of 4km.*
18 changes: 16 additions & 2 deletions src/ClimatePref/DataCleaning.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ using Statistics
"""
convert_coords(i::Int64, width::Int64)
convert_coords(x::Int64, y::Int64, width::Int64)
Function to convert coordinates from two-dimensional (`x`,`y`) format to one dimension (`i`), or vice versa, using the `width` of the grid. This function can also be applied to arrays of coordinates.
"""
function convert_coords end

function convert_coords(i::Int64, width::Int64)
x = ((i - 1) % width) + 1
y = div((i - 1), width) + 1
Expand Down Expand Up @@ -42,10 +45,12 @@ function create_reference(gridsize::Float64)
end

"""
upresolution(data::Union{ERA, Worldclim_monthly, Worldclim_bioclim}, rescale::Int64)
upresolution(data::Union{ERA, Worldclim_monthly, Worldclim_bioclim}, rescale::Int64; fn)
Function to increase the resolution of a climate dataset, by a factor, `rescale`.
"""
function upresolution end

function upresolution(era::ERA, rescale::Int64)
array = upresolution(era.array, rescale)
return ERA(array)
Expand Down Expand Up @@ -100,10 +105,11 @@ function upresolution(aa::AxisArray{T, 2} where T, rescale::Int64)
end

"""
downresolution(data::Union{ERA, Worldclim_monthly, Worldclim_bioclim}, rescale::Int64)
downresolution(data::Union{ERA, Worldclim_monthly, Worldclim_bioclim}, rescale::Int64; fn)
Function to decrease the resolution of a climate dataset, by a factor, `rescale`, and aggregation function, `fn`. The aggregation function has a default setting of taking the mean value.
"""
function downresolution end

function downresolution(era::ERA, rescale::Int64; fn::Function = mean)
array = downresolution(era.array, rescale, fn)
Expand Down Expand Up @@ -163,6 +169,14 @@ function downresolution(aa::AxisArray{T, 2} where T, rescale::Int64, fn)
Axis{:latitude}(newlat))
end

"""
downresolution!(resized_array::Matrix{T}, array::Matrix{T}, rescale::Int64, fn)
downresolution!(resized_array::Array{T, 3}, array::Matrix{T}, dim::Int64, rescale::Int64, fn)
Function to decrease the resolution of a climate dataset in place, by a factor, `rescale`, and aggregation function, `fn`. The aggregation function has a default setting of taking the mean value.
"""
function downresolution! end

function downresolution!(resized_array::Matrix{T}, array::Matrix{T}, rescale::Int64, fn) where T
Threads.@threads for i in eachindex(resized_array)
x, y = convert_coords(i, size(resized_array, 1))
Expand Down

0 comments on commit 887fdf2

Please sign in to comment.