Skip to content

Commit

Permalink
Merge branch 'main' into compathelper/new_version/2022-12-15-16-33-28…
Browse files Browse the repository at this point in the history
…-105-03256689419
  • Loading branch information
claireh93 authored Sep 4, 2023
2 parents fe3df96 + 788c1d2 commit c7f7bab
Show file tree
Hide file tree
Showing 24 changed files with 1,460 additions and 849 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
version: nightly
arch: x64
- name: Build package
uses: julia-actions/julia-buildpkg@latest
uses: julia-actions/julia-buildpkg@v1
- name: Run tests
uses: julia-actions/julia-runtest@latest
uses: julia-actions/julia-runtest@v1
6 changes: 3 additions & 3 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
julia-version:
- '1.6'
- '1.8'
os:
- ubuntu-latest
- macOS-10.15
Expand All @@ -37,9 +37,9 @@ jobs:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.arch }}
- name: Build package
uses: julia-actions/julia-buildpkg@master
uses: julia-actions/julia-buildpkg@v1
- name: Running
uses: julia-actions/julia-runtest@master
uses: julia-actions/julia-runtest@v1
- name: Process coverage
uses: julia-actions/julia-processcoverage@v1
- name: Coveralls
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "EcoSISTEM"
uuid = "ed2dc23b-ada4-5fdb-a26f-56368a14ad8f"
authors = ["Claire Harris <claire.harris@bioss.ac.uk>", "Richard Reeve <Richard.Reeve@glasgow.ac.uk>"]
version = "0.1.3"
version = "0.1.4"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Expand Down Expand Up @@ -34,9 +34,9 @@ Pluto = "c3e4b0f8-55cb-11ea-2926-15256bba5781"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RasterDataSources = "3cb90ccd-e1b6-4867-9617-4276c8b2ca36"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
SimpleSDMLayers = "2c645270-77db-11e9-22c3-0f302a89c64c"
SpatialEcology = "348f2d5d-71a3-5ad4-b565-8af070f99681"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
Expand All @@ -59,18 +59,18 @@ JLD2 = "0.4.3"
MPI = "0.17.2, 0.18, 0.19, 0.20"
Measures = "0.3.1"
Missings = "0.4.5, 1.0"
NetCDF = "0.11.3"
NetCDF = "0.11"
OnlineStats = "1.5.8"
Optim = "0.18, 0.19, 0.20, 0.21, 0.22, 1"
Phylo = "0.4.18"
Plots = "0.28.4, 0.29, 1"
Pluto = "0.19"
RasterDataSources = "0.5.6"
Requires = "1"
SimpleSDMLayers = "0.7, 0.8"
SpatialEcology = "0.9"
StatsBase = "0.32.2, 0.33"
Unitful = "1.7"
julia = "1.6"
julia = "1.6, 1.8"

[extras]
MPI = "da04e1cc-30fd-572f-bb4f-1f8673147195"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ You can now run through a full introduction to EcoSISTEM with Pluto.jl! To get s
import Pluto
Pluto.run()
```
This should open a Pluto window in your browser - from there you can type `examples\Introduction.jl` in the `Open from file` box. Note that it may be slow on first launch!
This should open a Pluto window in your browser - from there you can type `notebooks\Introduction.jl` in the `Open from file` box. Note that it may be slow on first launch!

[paper-url]: https://arxiv.org/abs/1911.12257

Expand Down
111 changes: 111 additions & 0 deletions examples/LandCover_africa.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#### SINGLE SPECIES ####
# Code to run single species across Africa with WorldClim data.
using EcoSISTEM
using EcoSISTEM.ClimatePref
using EcoSISTEM.Units
using RasterDataSources
using AxisArrays
using Unitful
using Unitful.DefaultSymbols
using StatsBase
using Plots

# Download landcover data
if !isdir("assets")
mkdir("assets")
end
ENV["RASTERDATASOURCES_PATH"] = "assets"
getraster(EarthEnv{LandCover})
world = readlc("assets/EarthEnv/LandCover/without_DISCover/", -180.0°, 180.0°, -56.0°, 90.0°)
world = compressLC(world)
africa_lc = world[-25°.. 50°, -35° .. 40°]
bio_africa_lc = Landcover(africa_lc)
heatmap(africa_lc')

getraster(WorldClim{BioClim})
world = readbioclim("assets/WorldClim/BioClim/")
africa_water = world.array[-25°.. 50°, -35° .. 40°, 12]
africa_water = upresolution(africa_water, 2)
africa_water = Worldclim_bioclim(AxisArray(africa_water .* mm, AxisArrays.axes(africa_water)))
bio_africa_water = WaterBudget(africa_water)

# Find which grid cells are land
active = Array{Bool, 2}(africa_lc .!= 4)

# Set up initial parameters for ecosystem
numSpecies = 1; grid = size(active); req= 10.0mm; individuals=0; area = 64e6km^2; totalK = 1000.0kJ/km^2

# Set up how much water each species consumes
energy_vec = WaterRequirement(fill(req, numSpecies))

# Set rates for birth and death
birth = 0.6/year
death = 0.6/year
longevity = 1.0
survival = 0.2
boost = 1.0
# Collect model parameters together
param = EqualPop(birth, death, longevity, survival, boost)

# Create kernel for movement
kernel = fill(GaussianKernel(15.0km, 10e-10), numSpecies)
movement = AlwaysMovement(kernel, Torus())

# Create species list, including their temperature preferences, seed abundance and native status
opts = fill(collect(1:8), numSpecies)
traits = LCtrait(opts)
native = fill(true, numSpecies)
abun = fill(div(individuals, numSpecies), numSpecies)
sppl = SpeciesList(numSpecies, traits, abun, energy_vec,
movement, param, native)

# Create abiotic environment - with temperature and water resource
abenv = lcAE(bio_africa_lc, bio_africa_water, active)

# Set relationship between species and environment (gaussian)
rel = LCmatch{Int64}()

# Create ecosystem and fill every active grid square with an individual
eco = Ecosystem(sppl, abenv, rel)
rand_start = findall(active)
for i in rand_start
eco.abundances.grid[1, i[1], i[2]] += 1
end

# Run simulation
times = 10years; timestep = 1month; record_interval = 1month; repeats = 1
lensim = length(0years:record_interval:times)
abuns = zeros(Int64, numSpecies, prod(grid), lensim)
@time simulate_record!(abuns, eco, times, record_interval, timestep);

# Reshape abundances for plotting
abuns = reshape(abuns[1, :, :, 1], grid[1], grid[2], lensim)

# Create a gif (warning, slow!)
anim = @animate for i in 1:lensim
africa_abun = Float64.(abuns[:, :, i])
africa_abun[.!(active)] .= NaN
heatmap(africa_abun, clim = (0, maximum(abuns)),
background_color = :lightblue, background_color_outside=:white,
grid = false, color = cgrad(:algae, scale = :exp))
end
gif(anim, "examples/Africa.gif", fps = 15)

# Plot start and end abundances, next to temperature and rainfall
africa_startabun = Float64.(abuns[:, :, 1])
africa_startabun[.!(active)] .= NaN
africa_endabun = Float64.(abuns[:, :, end])
africa_endabun[.!(active)] .= NaN
heatmap(africa_startabun', clim = (0, maximum(abuns)),
background_color = :lightblue, background_color_outside=:white,
grid = false, color = cgrad(:algae, scale = :exp),
layout = (@layout [a b; c d]), title = "Start abundance")
heatmap!(africa_endabun', clim = (0, maximum(abuns)),
background_color = :lightblue, background_color_outside=:white,
grid = false, color = cgrad(:algae, scale = :exp),
subplot = 2, title = "End Abundance")
africa_lc = Float64.(africa_lc.data)
africa_lc[.!active] .= NaN
heatmap!(africa_lc', grid = false, subplot = 3, title = "Land Cover")
africa_water = world.array[-25°.. 50°, -35° .. 40°, 12]
heatmap!(africa_water', grid = false, subplot = 4, title = "Precipitation")
Loading

0 comments on commit c7f7bab

Please sign in to comment.