Skip to content
Snippets Groups Projects
Select Git revision
  • 2ccd53eb5786758327f0d12a91a7cbbc39bcd0a9
  • master default protected
  • beta
  • dev
  • andrewssobral-patch-1
  • update
  • thomas-fork
  • 2.0
  • v3.2.0
  • v3.1.0
  • v3.0
  • bgslib_py27_ocv3_win64
  • bgslib_java_2.0.0
  • bgslib_console_2.0.0
  • bgslib_matlab_win64_2.0.0
  • bgslib_qtgui_2.0.0
  • 2.0.0
  • bgs_console_2.0.0
  • bgs_matlab_win64_2.0.0
  • bgs_qtgui_2.0.0
  • v1.9.2_x86_mfc_gui
  • v1.9.2_x64_java_gui
  • v1.9.2_x86_java_gui
23 results

bgslibrary.sln

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ecologicaldata.jl 1.95 KiB
    ### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
    ###
    ### This file includes the functions for collecting and saving ecological output data.
    ###
    
    """
        initecologicaldata()
    
    Create output files for each data group collected by the nature model.
    """
    function initecologicaldata(model::AgentBasedModel)
        # newdataoutput!(model, "populations", ["Date", "Species", "Abundance"],
        #                savepopulationdata, @param(nature.popoutfreq), populationtrends)
        # newdataoutput!(model, "individuals", ["Date","ID","X","Y","Species","Sex","Age"],
        #                saveindividualdata, @param(nature.indoutfreq), visualisemap)
    end
    
    """
        savepopulationdata(model)
    
    Return a comma-separated set of lines (to be printed to `populations.csv`), giving
    the current date and population size for each animal species. May be called never,
    daily, monthly, yearly, or at the end of a simulation, depending on the parameter
    `nature.popoutfreq`.
    """
    function savepopulationdata(model::AgentBasedModel)
        pops = Dict{String,Int}(s=>0 for s = @param(nature.targetspecies))
        for a in allagents(model)
            (typeof(a) != Animal) && continue
            pops[a.name] += 1
        end
        for a in model.migrants
            pops[a.first.name] += 1
        end
        data = []
        for p in keys(pops)
            push!(data, [model.date, p, pops[p]])
        end
        data
    end
    
    """
        saveindividualdata(model)
    
    Return a comma-separated set of lines (to be printed to `individuals.csv`), listing
    all properties of all animal individuals in the model. May be called never, daily,
    monthly, yearly, or at the end of a simulation, depending on the parameter
    `nature.indoutfreq`. WARNING: Produces very big files!
    """
    function saveindividualdata(model::AgentBasedModel)
        #XXX doesn't include migrants!
        data = []
        for a in allagents(model)
            (typeof(a) != Animal) && continue
            push!(data, [model.date,a.id,a.pos[1],a.pos[2],a.traits["name"],a.sex,a.age])
        end
        data
    end