Developers

How to contribute

Accessing the internal Data

Simulation Data Object

To directly check the results and to do more detailed analyses directly inspect the Simulation_Data object. In julia this is done by looking at the fields with the period character .. So to see the final population size of the first species you would use:

SD.species[1].abundances[:,:,end]

Internal structures

MetaRange.DurationType
Duration

Struct for saving the length of the runtime for the entire simulation.

Fields

  • start_time::DateTime: time when simulation was started
  • end_time::DateTime: time when simulation has finished
source
MetaRange.Env_PreferencesType
Env_Preferences

Struct for saving the environmental preferences of a species.

Fields

  • upper_limit::Float64: species parameter
  • lower_limit::Float64: species parameter
  • optimum::Float64: species parameter
source
MetaRange.LandscapeType
Landscape

Struct representing the landscape/environment.

Fields

  • xlength::Int64: equivalent to size[2] of any Array in this struct
  • ylength::Int64: equivalent to size[1] of any Array in this struct
  • environment::Dict{String, Array{Float64, 3}}: contains all environment attributes,

addressable by name

  • restrictions::Array{Float64, 3}: #TODO
source
MetaRange.OutputType
Output

represents the output of a simulation run for a species.

Fields

  • abundances: amount of individuals for each species in each timestep
  • habitat: habitat suitability for each species in each timestep
  • carry: carrying capacity for each species in each timestep
  • growrate: growth rate for each species in each timestep
  • bevmort: background mortality rate for each species in each timestep
source
MetaRange.Simulation_DataType
Simulation_Data

Struct for saving all data related to the simulation

Fields

  • parameters::Simulation_Parameters: simulation parameters of the experiment
  • landscape::Landscape: landscape of the experiment
  • species::Vector{Species}: a vector of all the species in the experiment
  • duration::Duration: saves the duration the experiment took to compute
source
MetaRange.Simulation_ParametersType
Simulation_Parameters

Struct for saving simulation parameters.

Fields

  • experiment_name::String: name of the experiment
  • config_dir::String: path to the folder containing the config_file
  • config_file::String: path to the config_file
  • output_dir::String: path to the folder where the output should be saved
  • species_dir::String: path to the folder containing the species definitions
  • environment_dir::String: path to the folder or file containing the environment tables
  • input_backup::Bool: if true, the input files will be copied to the output folder
  • env_attribute_files::Dict{String, String}: #TODO
  • env_restriction_files::Dict{String, String}: #TODO
  • env_attribute_mode::String: #TODO
  • env_restriction_mode::String: #TODO
  • attribute_restriction_blending::String: #TODO
  • timesteps::Int64: number of timesteps in the simulation
  • randomseed::Int64: seed for number generator used in the simulation
  • reproduction_model::String: #TODO
  • use_metabolic_theory::Bool: #TODO

#- use_stoch_allee::Bool: if true the allee effect will be stochastic #- use_stoch_carry::Bool: if true the carrying capacity will be stochastic

  • use_stoch_num::Bool: #TODO Stochastic Survival see R code
  • initialize_cells::String: #TODO
source
MetaRange.Simulation_VariablesType
Simulation_Variables

Simulation variables used for a species during run_simulation!"

Fields

  • habitat::Array{Float64, 2}: habitability of landscape cells for a species at current

simulation timestep

  • is_habitat::BitArray{2}: if landscape cells are habitable for a species at current

simulation timestep

  • future_habitat::Array{Float64}: TODO
  • future_is_habitat::BitArray{2}: if landscape cells are habitable for a species at next

simulation timestep

  • biomass::Array{Float64, 2}: biomass of a species individual at landscape cells
  • growrate::Array{Float64, 2}: growrate of species at landscape cells
  • carry::Array{Float64, 2}: carry property of species at landscape cells
  • allee::Array{Float64, 2}: allee property of species at landscape cells
  • bevmort::Array{Float64, 2}: Beverton mortaility of species at landscape cells
  • occurrences::Vector{CartesianIndex{2}}: list of cells where species occurs at current

timestep

  • offspring::Array{Float64, 2}: offspring of species at current timestep
source
MetaRange.SpeciesType
Species

Saving all data related to a species.

Fields

  • species_name::String: name of the species
  • traits::Traits: a (Traits)[@ref] struct for the species
  • abundances::Array{Union{Int64, Missing}, 3}: amount of individuals of this species in

each timestep

  • habitat::Array{Float64, 3}: habitat suitability in each timestep
  • dispersal_kernel::Matrix{Float64}:#TODO
  • vars::Simulation_Variables:#TODO
source
MetaRange.TraitsType
Traits

Traits of a species.

#TODO: Add description in fields

Fields

  • mass::Float64:
  • sd_mass::Float64:
  • growrate::Float64:
  • sd_growrate::Float64:
  • param_const_growrate::Union{Float64, Nothing}:
  • max_dispersal_dist::Int64:
  • max_dispersal_buffer::Int64:
  • mean_dispersal_dist::Union{Int64, Float64}:
  • allee::Float64: Allee effect counteracting negative diversity loss in small populations
  • sd_allee::Float64: Allee effect standard deviation
  • param_const_allee::Union{Float64, Nothing}:
  • bevmort::Float64:
  • sd_bevmort::Float64:
  • param_const_bevmort::Union{Float64, Nothing}:
  • carry::Float64:
  • sd_carry::Float64:
  • param_const_carry::Union{Float64, Nothing}:
  • env_preferences::Dict{String, Env_Preferences}:
  • habitat_cutoff_suitability::Float64:
source
MetaRange.BVMethod
BV(N::Int64, growrate::Float64, carry::Float64, mortality::Float64)

Returns the number of individuals in the next generation according to the Beverton-Holt model. Includes stochastic mortality.

source
MetaRange.BVNoStochMethod
BVNoStoch(N::Int64, growrate::Float64, carry::Float64, mortality::Float64)

Returns the number of individuals in the next generation according to the Beverton-Holt model. Does not include stochastic mortality.

source
MetaRange.DispersalSurvivalRoundMethod
DispersalSurvivalRound(
Abundances::Array{Union{Missing, Int64},2},
Offspring::Array{Float64,2}, xy::Array{Int64,2},
max_dispersal_dist::Int64
)

TODO

source
MetaRange.DispersalSurvivalStochMethod
DispersalSurvivalStoch(
Abundances::Array{Union{Missing, Int64},2},
Offspring::Array{Float64,2},xy::Array{Int64,2},
max_dispersal_dist::Int64
)

TODO

source
MetaRange.Disperse!Method
Disperse!(
species::Vector{Species},
LS::Landscape,
groups::NTuple{4, Vector{Chunk}},
timestep::Int64,

)

Dispersal

source
MetaRange.HabitatMortalityMethod
HabitatMortality(Abundances::Matrix{Union{Missing,Int64}}, Is_habitat::BitArray{2})

Habitat based mortality.

This function kills individuals that are in non suitable Habitat.

  • Abundances: array with the number of individuals in the landscape
  • Is_habitat: array with boolean values that indicate

which cell is habitat in the next timestep

source
MetaRange.ReproductionBevertonMethod
ReproductionBeverton(N::Int64, growrate::Float64, carry::Float64, mortality::Float64)

Returns the number of offspring in the next generation according to the Beverton-Holt model.

source
MetaRange.ReproductionRickerMethod
ReproductionRicker(N::Int64, growrate::Float64, carry::Float64, unused::Union{Float64,Nothing})

Returns the number of Individuals in the next generation according to the Ricker model.

source
MetaRange.ReproductionRickerAlleeMethod
ReproductionRickerAllee(N::Int64, growrate::Float64, carry::Float64, allee::Union{Float64,Nothing})

Returns the number of Individuals in the next generation according to the Ricker model. Includes allee effects

source
MetaRange.backup_configMethod
backup_config(SD::Simulation_Data, backup_path::String)

Record the settings actually used for a simulation run and creates a config file that can be used for future replicate runs.

source
MetaRange.backup_inputMethod
backup_input(SP::Simulation_Parameters)

Initializes the output directory. This is called when input_backup in the configuration file is set to true and creates a backup of the input files in the output directory.

source
MetaRange.check_species_dirMethod
check_species_dir(config::Simulation_Parameters)

Checks if the species directory exists and throws an error if it doesn't.

source
MetaRange.df_outputMethod
df_output(SD::Simulation_Data)

Create a dataframe from the output of a simulation.

Arguments

  • SD::Simulation_Data: A Simulation_Data object containing the output data.

Returns

  • A DataFrame object with the following columns:
    • t: time
    • x: x-coordinate of the patch
    • y: y-coordinate of the patch
    • abundance: abundance of the species in the patch
    • reproduction: growth rate of the species in the patch
    • habitat: habitat suitability of the patch
    • carry: carrying capacity of the patch
    • bevmort: background mortality rate of the species in the patch

Examples

julia> df = df_output(SD)
source
MetaRange.disperse_chunk!Method
disperse_chunk!(
species::Species,
occurrences::Vector{CartesianIndex{2}},
offspring::Matrix{Float64},
chunk::Chunk,
t::Int64,

)

Parallel Dispersal in a given chunk

source
MetaRange.get_Env_PreferencesMethod
get_Env_Preferences(species::Dict, key::String)

Returns the environmental preference for the supplied trait in key with limits and optimum as an Env_Preferences object.

source
MetaRange.get_Simulation_VariablesMethod
get_Simulation_Variables()

Initializes an empty Simulation_Variables object. Each parameter is defined with an empty matrix eqivalent to the landscape's size.

source
MetaRange.get_TraitsMethod
get_Traits(species::Dict)

Extracts species traits from the configuration dictionary and returns a Trait object.

source
MetaRange.get_environment_dirMethod
get_environment_dir(config::Simulation_Parameters)

Returns full path to environment folder or returns config_dir/environment when no path to the species folder is provided.

source
MetaRange.get_habitatMethod
get_habitat(
env_pref::Dict{String, Env_Preferences},
LS::Landscape,
attribute_mode::String,
t::Int

)

Get habitat in current timestep. Return Array{Float64, 2}

source
MetaRange.get_out_dirMethod
get_out_dir(SP::Simulation_Parameters)

Names a new output directory for the simulation used in backup_input()[@ref]. This directory will only be created if backup is true or the user later saves an output into the default paths

source
MetaRange.get_pop_bevmortMethod
get_pop_bevmort(
traits::Traits,
LS::Landscape,
habitat::Array{Float64,2},
mass::Union{Float64,Array{Float64,2}},
use_metabolic_theory::Bool,
timestep::Int,
E::Float64,

)

TBW

source
MetaRange.get_pop_carryMethod
get_pop_carry(
traits::Traits,
LS::Landscape,
habitat::Array{Float64,2},
mass::Array{Float64,2},
use_metabolic_theory::Bool,
timestep::Int,
E::Float64,

)

TBW

source
MetaRange.get_pop_varMethod
get_pop_var(
trait::Float64,
sd_trait::Float64,
exp_trait::Float64,
param_const_trait::Union{Float64,Nothing},
traits::Traits,
LS::Landscape,
mass::Array{Float64,2},
use_metabolic_theory::Bool,
timestep::Int, E::Float64,

)

TBW

source
MetaRange.get_species_dirMethod
get_species_dir(config::Simulation_Parameters)

Returns full path to species folder or returns config_dir/species when no path to the species folder is provided.

source
MetaRange.gifFunction
gif(SD::Simulation_Data, arg::String, frames::Int)

Plots the specified output for timestep t.

Arguments

  • SD::Simulation_Data: Simulation_Data object
  • arg::String: argument on what shall be displayed. Must be one of restrictions, abundances, suitability, temperature, precipitation, carry, growrate, or mortality.
  • frames::Int: number of frames per second

Returns

  • The gif is saved under the name "arg.gif" in the output directory.
source
MetaRange.gif_complexMethod
gif_complex(SD::Simulation_Data; frames = 2)

Plot environment, species environmental preferences, habitat suitability, and abundances and create a GIF.

Arguments

  • SD::Simulation_Data: Simulation_Data object
  • frames::Int: framerate

Returns

  • The gif is saved under the name "all.gif" in the output directory.

Examples

julia> gif_complex(SD)

Gif of input and output plots

source
MetaRange.imgMethod
img(SD::Simulation_Data, t::Int, arg::String)

Plots the specified output for timestep t.

Arguments

  • SD::Simulation_Data: Simulation_Data object
  • t::Int: timestep
  • arg::String: argument on what shall be displayed. Must be one of restrictions, abundances, suitability, temperature, precipitation, carry, growrate, or mortality.

Returns

  • f::Figure: Figure object
source
MetaRange.img_complexMethod
img_complex(SD::Simulation_Data, t::Int)

Plot environment, species environmental preferences, habitat suitability, and abundances for a given timestep.

Arguments

  • SD::Simulation_Data: Simulation_Data object
  • t::Int: timestep

Returns

  • f::Figure: Figure object

Examples

julia> f = img_complex(SD, 19)
julia> f

All plots

source
MetaRange.initialize_outputMethod
initialize_output(
SP::Simulation_Parameters,
LS::Landscape,
abundances::Array{Int64,3},
habitat::Array{Float64,3},

)

Initializes the output struct. Calculation of the first timesteps is done outside the function.

source
MetaRange.plot_abundancesMethod
plot_abundances(SD::Simulation_Data)

Plot the total abundances of a species over time.

Arguments

  • SD::Simulation_Data: Simulation_Data object

Returns

  • f::Figure: Figure object

Examples

julia> f = plot_abundances(SD)
julia> f

Abundance plot

source
MetaRange.randomize!Method
randomize!(value,sd)

Takes a parameter or array of parameters and modifies it according to a lognormal distribution based on standard deviation sd

source
MetaRange.read_inputMethod
read_input(path::String)

Read in the configuration and associated files in the folder and return a Simulation_Data struct.

Arguments

  • path::String: Path to the configuration file.

Returns

  • SD::Simulation_Data: Returns the initialised simulation data struct with the first timestep.

Examples

julia> SD = read_input("path/to/config.csv")
precipitation
temperature
...

See also run_simulation!(), Simulation_Data

source
MetaRange.read_species_dirMethod
read_species_dir(species_dir::String, LS::Landscape, SP::Simulation_Parameters)

Read species directory, calculate properties and parameters if not provided and return as a vector of Species objects.

source
MetaRange.read_ts_configMethod
read_ts_config(env_dir::String, ls_timeseries_config::String)

Returns the timeseries generator configuration as a Dict (no struct as it's only used once)

source
MetaRange.reproduce!Method
reproduce(species, reproduction, timestep)

Reproduction function. Takes a vector of species structs, a reproduction function and a timestep and calculates the amount of species in the next timestep.

source
MetaRange.run_simulation!Method
run_simulation!(SD::Simulation_Data)

Run an ecological simulation.

Take the initialized simulation data SD and run the simulation for the specified number of timesteps.

Arguments

  • SD::MetaRange.Simulation_Data: MetaRange simulation data struct produced by

read_input()

Returns

  • SD::MetaRange.Simulation_Data: Returns the struct with later timesteps after initialisation simulated.

Examples

julia> run_simulation!(SD)

See also read_input(), Simulation_Data

source
MetaRange.save_outputMethod
save_output(SD::Simulation_Data)

Save all output variables in a .tsv file.

This function writes all output variables abundance - into a .tsv file.

Arguments

  • SD::Simulation_Data: Simulation_Data object

Returns

  • A .tsv file with the following columns in the output directory`:
    • t: time
    • x: x-coordinate of the patch
    • y: y-coordinate of the patch
    • abundance: abundance of the species in the patch
    • reproduction: growth rate of the species in the patch
    • habitat: habitat suitability of the patch
    • carry: carrying capacity of the patch
    • bevmort: background mortality rate of the species in the patch

Examples

julia> save_output(SD)
source