General utility
These file contain functions for background tasks, such as reading in model configurations, geometric functions, and printing or plotting any output.
input.jl
Persefone.AVAILABLE_CROPMODELS — Constant
The crop models that can be used in the simulation.
Persefone.PARAMFILE — Constant
The file that stores all default parameters: src/parameters.toml
Persefone.flattenTOML — Method
flattenTOML(dict)An internal utility function to convert the two-dimensional dict returned by TOML.parsefile() into a one-dimensional dict, so that instead of writing settings["domain"]["param"] one can use settings["domain.param"]. Can be reversed with prepareTOML.
Persefone.getsettings — Function
getsettings(configfile, userparams=Dict())Combines all configuration options to produce a single settings dict. Precedence: function arguments - commandline parameters - user config file - default values
Persefone.loadmodelobject — Method
loadmodelobject(fullfilename)Deserialise a model object that was previously saved with [savemodelobject](@ref).
Persefone.parsecommandline — Method
parsecommandline()Certain software parameters can be set via the commandline.
Persefone.preprocessparameters — Method
preprocessparameters(settings)Take the raw input parameters and process them where necessary (e.g. convert types or perform checks). This is a helper function for getsettings.
Persefone.resolve_input_dir — Method
resolve_input_dir(path; configdir=nothing)Return an absolute path to a directory if it exists, trying common roots (pkgdir, the directory of the config file, and the current working directory) in that order. Returns nothing if the directory cannot be found.
Persefone.@param — Macro
@param(domainparam)Return a configuration parameter from the global settings. The argument should be in the form <domain>.<parameter>, for example @param(core.outdir). Possible values for <domain> are core, animal, farm, or crop. For a full list of parameters, see src/parameters.toml.
Note: this macro only works in a context where the model object is available!
output.jl
Persefone.LOGFILE — Constant
Log output is saved to simulation.log in the output directory
Persefone.RECORDDIR — Constant
All input data are copied to the inputs folder within the output directory
Persefone.DataOutput — Type
DataOutputA struct for organising model output. This is used to collect model data in an in-memory dataframe or for CSV output. Submodels can register their own output functions using newdataoutput!.
Struct fields: - frequency: how often to call the output function. This can be any of: "daily", "monthly", "yearly", "end", "never", or a date (e.g. "15 June"). - databuffer: a vector of vectors that temporarily saves data before it is stored permanently or written to file. - datastore: a data frame that stores data until the end of the run - outputfunction: a function that takes a model object and returns data values to record (formatted as a vector of vectors). - plotfunction: a function that takes a model object and returns a Makie figure object (optional).
Persefone.createdatadir — Method
createdatadir(outdir, overwrite)Creates the output directory, dealing with possible conflicts.
Persefone.data — Method
Retrieve the data stored in a DataOutput (assumes core.storedata is true).
Persefone.modellogger — Function
modellogger(loglevel, outdir, output="both")Create a logger object that writes output to screen and/or a logfile. This object is stored as model.logger and can then be used with with_logger(). Note: requires createdatadir to be run first.
Persefone.newdataoutput! — Function
newdataoutput!(model, name, header, frequency, outputfunction, plotfunction)Create and register a new data output. This function must be called by all submodels that want to have their output functions called regularly.
Persefone.outputdata — Function
outputdata(model, force=false)Cycle through all registered data outputs and activate them according to their configured frequency. If force is true, activate all outputs regardless of their configuration.
Persefone.prepareTOML — Method
prepareTOML(dict)An internal utility function to re-convert the one-dimensional dict created by flattenTOML into the two-dimensional dict needed by TOML.print, and convert any data types into TOML-compatible types where necessary.
Persefone.record! — Method
record!(model, outputname, data)Append an observation vector to the given output.
Persefone.saveinputfiles — Method
saveinputfiles(model)Copy all input files into the output directory, including the actual parameter settings used. This allows replicating a run in future.
Persefone.savemodelobject — Method
savemodelobject(model, filename)Serialise a model object and save it to file for later reference. Includes the current model and Julia versions for compatibility checking.
WARNING: produces large files (>100 MB) and takes a while to execute.
Persefone.visualiseoutput — Method
visualiseoutput(model)Cycle through all data outputs and call their respective plot functions, saving each figure to file.
Persefone.withtestlogger — Method
withtestlogger(model)Replace the model logger with the currently active logger. This is intended to be used in the testsuite to circumvent a Julia issue, where @test_logs doesn't work with local loggers.
Persefone.@data — Macro
@data(outputname)Return the data stored in the given output (assumes core.storedata is true). Only use in scopes where model is available.
Persefone.@record — Macro
@record(outputname, data)Record an observation / data point. Only use in scopes where model is available.
types.jl
Persefone.AbstractCropState — Type
AbstractCropStateThe abstract supertype of all crop states in the model. Each crop model has to define a type CropState <: AbstractCropState.
Persefone.AbstractCropType — Type
AbstractCropTypeThe abstract supertype of all crop types in the model. Each crop model has to define a type CropType <: AbstractCropType.
Persefone.ModelAgent — Type
ModelAgentThe supertype of all agents in the model (animal species, farmer types, landscape polygons).
Persefone.SimulationModel — Type
SimulationModelThe supertype of AgricultureModel. This is needed to avoid circular dependencies (most types and functions depend on SimulationModel, but the definition of the model struct depends on these types).
geometry.jl
Persefone.Coord — Type
CoordContinuous 2D coordinate in projected map units (e.g. meters).
This is aliased to GeometryBasics.Point{2,Float64} for compatibility with GeoInterface-aware geometry types.
Persefone.Extent2D — Type
Extent2DAxis-aligned extent with X/Y bounds, backed by Extents.Extent.
Persefone.Extent2D — Method
Extent2D(geom::Geom)Compute the X/Y extent of a GDAL geometry.
Persefone.Geom — Type
GeomGeometry handle returned by GDAL/ArchGDAL. For polygons this is typically an ArchGDAL.IGeometry of type wkbPolygon or wkbMultiPolygon.
Persefone.areaof — Method
areaof(geom)Return the area of a geometry in square meters.
Persefone.bearingfrompoint — Method
bearingfrompoint(origin, destination)Get the distance and the bearing of the destination point as seen from the origin.
Persefone.circle — Function
circle(center, radius, coarseness=10)Return a quasi-circular geom with the given properties. Coarseness defines how many degrees lie between two points of the resulting polygon (i.e. if 10°, the "circle" will consist of 36 points).
Persefone.fuzzyposition — Function
fuzzyposition(pos, maxdist, rng=default_rng())Return a random position that is at most maxdist away from pos.
Persefone.geom_from_coords — Method
geom_from_coords(coords)Create a GDAL polygon geometry from a list of coordinates (outer ring only).
Persefone.point_in_polygon — Method
point_in_polygon(coord, geom)Test whether the given point lies within the given geometry.
Persefone.pointfrombearing — Method
pointfrombearing(origin, bearing, distance)Calculate the coordinates of the point at the given bearing (in °) and distance from the origin.
Persefone.randompoint — Function
randompoint(geom, rng)Return a random position that lies within the given geometry.
Persefone.rectangle — Method
rectangle(center, width, height)Return a rectangular geom with the given properties.
Persefone.square — Method
square(center, width)Return a square geom with the given properties.
Persefone.@fuzzyposition — Macro
@fuzzyposition(pos, maxdist)Return a random position that is at most maxdist away from pos. This is a utility wrapper that can only be used where model is available.
Persefone.@randompoint — Macro
@randompoint(place)Return a random point within a landscape element or a home range. This is a utility wrapper that can only be used where model is available.
utils.jl
makieplots.jl
Persefone.birdpopulation — Method
birdpopulation(speciesname, model)Plot a line graph of total population size and individual demographics of birds over time. Returns a Makie figure object.
Persefone.birdstats — Method
birdstats(speciesname, model)Plot various statistics from the bird model: nesting habitat, territory size, mortality.
Persefone.butterflyabundanceplot — Method
butterflyabundanceplot(speciesname, model)Plot a line graph of total population size and individual demographics of marbled whites over time. Returns a Makie figure object.
Persefone.butterflylifestats — Method
butterflylifestats(speciesname, model)Plot various statistics from the marbled white model: fecundity, movement, habitat use
Persefone.butterflytrendsplot — Method
butterflytrendsplot(speciesname, model)... Returns a Makie figure object.
Persefone.croptrends — Method
croptrends(model)Plot a dual line graph of cropped area and average plant height and cover per crop over time. Returns a Makie figure object.
Persefone.datetickmarks — Method
datetickmarks(dates)Given a vector of dates, construct a selection to use as tick mark locations. Helper function for [populationtrends](@ref)
Persefone.populationtrends — Method
populationtrends(model)Plot a line graph of population sizes of each species over time. Returns a Makie figure object.
Persefone.visualisemap — Function
visualisemap(model, date, landscape)Draw the model's land cover map and plot all individuals as points on it at the specified date. If no date is passed, use the last date for which data are available. Optionally, you can pass a pre-loaded Landscape object. Returns a Makie figure object.