Simulation
The core and world directories hold source files that are important for all submodels, including scheduling, landscape, weather, and input/output functions.
Persefone.jl
This file defines the module, including all exported symbols and two high-level types.
Persefone.MAPRESOLUTION — Constant
The spatial resolution of the currently used input maps.
Persefone.AnnualDate — Type
AnnualDateA type to handle recurring dates (e.g. migration, harvest). Stores a month and a day, and can be compared against normal dates. To save typing, a Tuple{Int64,Int64} or a String can be automatically converted to an AnnualDate, allowing this syntax: nestingend::AnnualDate = (August, 15), or nestingend::AnnualDate = "15 August".
Base.randn — Function
randn(vector)Return a random element from the given vector, following a (mostly) normal distribution based on index values (i.e. elements in the middle of the vector will be returned most frequently).
Persefone.bounds — Method
bounds(x; max=Inf, min=0)A utility function to make sure that a number is within a given set of bounds. Returns max/min if x is greater/less than this.
Persefone.camelcase — Method
camelcase(string)Return a CamelCaseVersion of the string (each word capitalised and joined to the next).
Persefone.cycle! — Function
cycle!(vector, n=1)Move the first element of the vector to the end, repeat n times.
Persefone.snakecase — Method
snakecase(string)Return a snakecaseversion of the string (all small letters, words joined by underscores).
Persefone.thisyear — Method
thisyear(annualdate, model)
nextyear(annualdate, model)
lastyear(annualdate, model)Convert an AnnualDate to a Date, using the current/next/previous year of the simulation run.
Persefone.uncamelcase — Method
uncamelcase(string)Reverse camelcase() (e.g. "WinterWheat" -> "Winter Wheat").
Persefone.unsnakecase — Method
unsnakecase(string)Reverse snakecase() (e.g. "winter_wheat" -> "winter wheat").
Persefone.@chance — Macro
@chance(odds)Return true if a random number is less than the odds (0.0 <= odds <= 1.0), using the model RNG. This is a utility wrapper that can only be used a context where the model object is available.
Persefone.@lastyear — Macro
@lastyear(annualdate)Construct a date object referring to the last year in the model from an AnnualDate. Only use in scopes where model is available.
Persefone.@nextyear — Macro
@nextyear(annualdate)Construct a date object referring to the next year in the model from an AnnualDate. Only use in scopes where model is available.
Persefone.@rand — Macro
@rand(args...)Return a random number or element from the sample, using the model RNG. This is a utility wrapper that can only be used a context where the model object is available.
Persefone.@randn — Macro
@randn(vector)Return a normally-distributed random number or element from the sample, using the model RNG. This is a utility wrapper that can only be used a context where the model object is available.
Persefone.@shuffle! — Macro
@shuffle!(collection)Shuffle the given collection in place, using the model RNG. This is a utility wrapper that can only be used a context where the model object is available.
Persefone.@thisyear — Macro
@thisyear(annualdate)Construct a date object referring to the current model year from an AnnualDate. Only use in scopes where model is available.
simulation.jl
This file includes the basal functions for initialising and running simulations.
Persefone.AgricultureModel — Type
AgricultureModelThis is the heart of the model - a struct that holds all data and state for one simulation run. It is created by initialise and passed as input to most model functions.
Persefone.finalise! — Method
finalise!(model)Wrap up the simulation. Finalises and visualises output, then terminates.
Persefone.initialise — Method
initialise(configfile=PARAMFILE, params=Dict())Initialise the model: read in parameters, create the output data directory, and instantiate the SimulationModel object(s). Optionally allows specifying the configuration file and overriding specific parameters. This returns a single model object, unless the config file contains multiple values for one or more parameters, in which case it creates a full-factorial simulation experiment and returns a vector of model objects.
Persefone.initmodel — Method
initmodel(settings)Initialise a model object using a ready-made settings dict. This is a helper function for initialise().
Persefone.paramscan — Method
paramscan(settings)Create a list of settings dicts, covering all possible parameter combinations given by the input settings (i.e. a full-factorial experiment). This is a helper function for initialise().
Persefone.simulate! — Method
simulate!(model)Carry out a complete simulation run using a pre-initialised model object.
Persefone.simulate — Method
simulate(configfile=PARAMFILE, params=Dict())Initialise one or more model objects and carry out a full simulation experiment, optionally specifying a configuration file and/or specific parameters.
This is the default way to run a Persefone simulation.
Persefone.stepagent! — Method
stepagent!(agent, model)All agent types must define a stepagent!() method that will be called daily.
Persefone.stepsimulation! — Method
stepsimulation!(model)Execute one update of the model.
landcover.jl
This file lists the land cover types represented on the model maps.
landscape.jl
This file manages the landscape maps that underlie the model.
Persefone.HomeRange — Type
HomeRangeContainer for home range / territory polygons.
Persefone.Landscape — Type
LandscapeA vector-based landscape representation.
Persefone.LandscapeElement — Type
LandscapeElementContainer for landscape features (landcover, soil, optional crop state).
Persefone.SoilType — Type
The soil type of a LandscapeElement
Persefone._closest_point_on_curve — Method
_closest_point_on_curve(pos, curve)Return the closest point on a curve to pos and the squared distance. The closing segment is included if the curve is not explicitly closed.
Persefone._closest_point_on_geom — Method
_closest_point_on_geom(pos, geom)Return the closest point on the polygon boundary of geom to pos and the squared distance between them. Holes are included as candidates.
Persefone._closest_point_on_segment — Method
_closest_point_on_segment(pos, a, b)Return the closest point on the segment a-b to pos and the squared distance.
Persefone._geom_to_geoms — Method
_geom_to_geoms(geom)Convert an ArchGDAL geometry into one or more polygon geometries (splitting multipolygons).
Persefone.add_homerange! — Method
add_homerange!(ls::Landscape, hr::HomeRange)Adds a HomeRange to a Landscape and update the spatial index.
Persefone.add_land! — Method
add_land!(ls::Landscape, le::LandscapeElement)Adds a LandscapeElement to a Landscape, and assigns le.id a new LandElemID (therefore modifying both arguments).
Persefone.allelements — Method
allelements(model)Return all elements in the model landscape.
Persefone.coverage_stats — Method
coverage_stats(polys, boundary; precision_eps=0.0)Compute coverage, gap area, and overlap area for a set of polygon geometries within a boundary polygon.
Persefone.coverage_stats — Method
coverage_stats(ls::Landscape; boundary=nothing, precision_eps=0.0)Compute coverage statistics for a Landscape. If no boundary is provided, the landscape extent is used as a rectangular boundary.
Persefone.createevent! — Function
createevent!(model, pixels, name, duration=1)Add a farm event to the specified pixels (a vector of position tuples) for a given duration.
Persefone.directionto — Function
directionto(pos, habitatfunction, model, maxradius=1km, stepsize::Length=100m)Calculate the direction from the given location to the closest landscape element matching the habitat descriptor function. Returns a bearing (0-359°) or nothing if no matching landscape element is found.
Persefone.distanceto — Function
distanceto(pos, habitatfunction, model, maxradius=1km, stepsize::Length=100m)Return the distance to the closest landscape element matching the habitat descriptor function. Is a thin wrapper around findnearest().
Persefone.distancetoedge — Method
distancetoedge(pos, model)Calculate the distance from the given location to the edge of the local landscape element.
Persefone.findnearest — Function
findnearest(pos, habitatfunction, model, maxradius=1km, stepsize::Length=100m)Find the closest landscape element matching the habitat function, if there is one within the maxradius. Searches in concentric circles determined by stepsize. Returns a tuple of the found landscape element (or nothing) and the distance to it.
Persefone.gap_polygons — Method
gap_polygons(polys, boundary; precision_eps=0.0)Return a vector of gap polygons (boundary minus union of polys).
Persefone.gap_polygons — Method
gap_polygons(ls::Landscape; boundary=nothing, precision_eps=0.0)Return gap polygons for a Landscape. If no boundary is provided, the landscape extent is used as a rectangular boundary.
Persefone.get_homeranges_at_coord — Method
get_homeranges_at_coord(landscape::Landscape, coord::Coord)Find any HomeRanges containing the given coordinate. Uses the spatial index for fast candidate filtering, then precise geometric test.
Returns a vector of HomeRanges found (empty if none found).
Persefone.get_homeranges_in_extent — Method
get_homeranges_in_extent(landscape::Landscape, ext::Extent2D)Find all HomeRanges whose extents intersect with the given extent using the spatial index for efficient O(log n) lookup.
Returns a lazy iterator over HomeRange objects.
Persefone.get_land_elem_at_coord — Method
get_land_elem_at_coord(landscape::Landscape, coord::Coord)Find the LandscapeElement containing the given coordinate. Uses the spatial index for fast candidate filtering, then precise geometric test.
Returns the LandscapeElement if found, or nothing otherwise.
Persefone.get_land_elems_in_extent — Method
get_land_elems_in_extent(landscape::Landscape, ext::Extent2D)Find all LandscapeElements whose extents intersect with the given extent using the spatial index for efficient O(log n) lookup.
Returns a lazy iterator over LandscapeElement objects.
Persefone.inextent — Method
inextent(pos, model)Is the given position within the extent of the model landscape?
Persefone.initlandscape — Function
initlandscape(gpkgpath="landscape.gpkg";
landcover_field=:landcover,
soil_field=:soil_type)Initialise a Landscape from a GeoPackage at gpkgpath. Each feature is converted to a LandscapeElement, keeping only the Persefone landcover value.
Arguments
landcover_field: Field name containing landcover values (default::landcover)soil_field: Field name containing soil type values (optional; default::soil_type)
Persefone.isvalid — Method
isvalid(ls::Landscape)Return true if all geometries in the landscape are topologically valid.
Persefone.landcover — Method
landcover(position, model)Return the land cover class at this position (utility wrapper).
Persefone.landelem — Method
landelem(position, model)Return the LandscapeElement at this position (Coord).
Persefone.landelem — Method
landelem(id, model)Return the LandscapeElement with this ID.
Persefone.nearby_land_elements — Function
nearby_land_elements(landscape, landscapeelement, buffer=5m)Expand the given landscape elements extent by the buffer distance, then return an iterator over all landscape elements in this extent.
Persefone.remove_homerange! — Method
remove_homerange!(ls::Landscape, hr::HomeRange)Remove the given homerange from the landscape and update the spatial index.
Persefone.safebounds — Method
safebounds(pos, model)Clamp a position to the landscape extent.
weather.jl
This file reads in weather data and makes it available to the model.
Persefone.Weather — Type
WeatherHolds the weather information for the whole simulation period.
Persefone.check_missing_weatherdata — Method
check_missing_weatherdata(dataframe)Check the weather input data for missing values in columns where input values are required.
Persefone.cloudcover — Method
cloudcover(weather, date)
cloudcover(model, date)
cloudcover(model)Return the average cloudcover in eigths on date.
Persefone.daynumber — Method
daynumber(weather, date)Returns the number of days, counting weather.firstdate as day 1.
Persefone.evapotranspiration — Method
evapotranspiration(weather, date)
evapotranspiration(model, date)
evapotranspiration(model)Return the potential evapotranspiration (ETo) on date.
Persefone.findspans — Method
findspans(predicate_fn, array) -> Vector{UnitRange{Int}}Returns spans of indices in a 1-d array where a predicate_fn returns true. The spans are returned as a Vector of UnitRange{Int}, where each range is of the form start_index:end_index.
Persefone.humidity — Method
humidity(weather, date)
humidity(model, date)
humidity(model)Return today's average vapour pressure in %.
Persefone.initweather — Method
initweather(weatherfile, startdate, enddate)Load a weather file, extract the values that are relevant to this model run (specified by start and end dates), and return a dictionary of Weather objects mapped to dates.
Note: This requires a weather file in the format produced by data/regions/auxiliary/extract_weather_data.R.
Persefone.maxtemp — Method
maxtemp(weather, date)
maxtemp(model, date)
maxtemp(model)Return the maximum temperature in °C on date.
Persefone.meantemp — Method
meantemp(weather, date)
meantemp(model, date)
meantemp(model)Return the mean temperature in °C on date.
Persefone.mintemp — Method
mintemp(weather, date)
mintemp(model, date)
mintemp(model)Return the minimum temperature in °C on date.
Persefone.precipitation — Method
precipitation(weather, date)
precipitation(model, date)
precipitation(model)Return the total precipitation in mm on date.
Persefone.sunshine — Method
sunshine(weather, date)
sunshine(model, date)
sunshine(model)Return the sunshine duration in hours on date.
Persefone.windspeed — Method
windspeed(weather, date)
windspeed(model, date)
windspeed(model)Return the average windspeed in m/s on date.
Persefone.@cloudcover — Macro
@cloudcover(date=model.date)Return the average cloudcover in eigths today/on the specified date. Can only be used in scopes where model is available.
Persefone.@evapotranspiration — Macro
@evapotranspiration(date=model.date)Return the potential evapotranspiration (ETo) today/on the specified date. Can only be used in scopes where model is available.
Persefone.@humidity — Macro
@humidity(date=model.date)Return the average vapour pressure (in %) today/on the specified date. Can only be used in scopes where model is available.
Persefone.@maxtemp — Macro
@maxtemp(date=model.date)Return the maximum temperature today/on the specified date. Can only be used in scopes where model is available.
Persefone.@meantemp — Macro
@meantemp(date=model.date)Return the mean temperature today/on the specified date. Can only be used in scopes where model is available.
Persefone.@mintemp — Macro
@mintemp(date=model.date)Return the minimum temperature today/on the specified date. Can only be used in scopes where model is available.
Persefone.@precipitation — Macro
@precipitation(date=model.date)Return the total precipitation in mm today/on the specified date. Can only be used in scopes where model is available.
Persefone.@sunshine — Macro
@sunshine(date=model.date)Return the sunshine duration in hours today/on the specified date. Can only be used in scopes where model is available.
Persefone.@windspeed — Macro
@windspeed(date=model.date)Return the average windspeed in m/s today/on the specified date. Can only be used in scopes where model is available.