Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
landscape.jl 13.89 KiB
### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
###
### This file manages the landscape maps that underlie the model.
###

using Printf

## IMPORTANT: do not change the order of this enum, or initlandscape() will break!
"The land cover classes encoded in the Mundialis Sentinel data."
@enum LandCover nodata forest grass water builtup soil agriculture

"The soil type of a Pixel or FarmPlot"
@enum SoilType begin
    nosoildata = 0   # 0
    sand             # 1
    loamy_sand       # 2
    sandy_loam       # 3
    loam             # 4
    silt_loam        # 5
    silt             # 6
    sandy_clay_loam  # 7
    clay_loam        # 8
    silty_clay_loam  # 9
    sandy_clay       # 10
    silty_clay       # 11
    clay             # 12
    nosoil           # 13
end

# TODO: move this into a CSV file and read it from there
"""Bodenatlas soil type id, corresponding Persefone soil type, and numbers to Persefone SoilType enum and the
   original Bodenatlas description of the soil type"""
const df_soiltypes_bodenatlas = DataFrame(
    NamedTuple{(:bodenatlas_id, :bodenatlas_name, :persefone_soiltype), Tuple{Int, String, SoilType}}.([
        ( 1, "Abbauflächen",      nosoil),
        ( 2, "Gewässer",          nosoil),
        ( 3, "Lehmsande (ls)",    loamy_sand),
        ( 4, "Lehmschluffe (lu)", silt_loam),
        ( 5, "Moore",             nosoil),
        ( 6, "Normallehme (ll)",  loam),
        ( 7, "Reinsande (ss)",    sand),
        ( 8, "Sandlehme (sl)",    sandy_loam),
        ( 9, "Schluffsande (us)", sandy_loam),
        (10, "Schlufftone (ut)",  silty_clay),
        (11, "Siedlung",          nosoil),
        (12, "Tonlehme (tl)",     clay_loam),
        (13, "Tonschluffe (tu)",  silty_clay_loam),
        (14, "Watt",              nosoil),
    ])
)

"Map a Bodenatlas soil type integer to a Persefone `SoilType` enum"
const soiltype_bodenatlas_to_persefone =
    Dict{Int,SoilType}(row.bodenatlas_id => row.persefone_soiltype for row in eachrow(df_soiltypes_bodenatlas))


"The types of management event that can be simulated"
@enum Management tillage sowing fertiliser pesticide harvesting


"""
    Pixel

A pixel is a simple data structure to combine land use and ownership information
in a single object. The model landscape consists of a matrix of pixels.
(Note: further landscape information may be added here in future.)
"""
mutable struct Pixel
    landcover::LandCover          # land cover class at this position
    soiltype::SoilType            # soil type class at this position