Skip to content

Commit

Permalink
Merge pull request #107 from EcoJulia/claireh93/landcover
Browse files Browse the repository at this point in the history
ClimatePref updates
  • Loading branch information
claireh93 committed Mar 9, 2023
2 parents 153696d + b40d903 commit db3d49c
Show file tree
Hide file tree
Showing 22 changed files with 1,336 additions and 732 deletions.
2 changes: 1 addition & 1 deletion .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 Down
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
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,17 +59,16 @@ 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"
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
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 db3d49c

Please sign in to comment.