Skip to content
Snippets Groups Projects
Select Git revision
  • 72d021284c0a7490a28da2946e6a90dd97b6e148
  • 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

run_camera.bat

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    landscape_tests.jl 3.29 KiB
    ### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
    ###
    ### These are the tests for the landscape and weather functions.
    ###
    
    @testset "Landscape initialisation" begin
        model = inittestmodel(false)
        # these tests are specific to the Jena maps
        @test_logs (:info, "Initialised 2092 farm plots.") match_mode=:any Ps.initfields!(model)
        @test size(model.landscape) == (1754, 1602)
        @test Ps.landcover((100,100), model) == Ps.forest
        @test Ps.landcover((300,1), model) == Ps.soil
        @test Ps.landcover((500,1), model) == Ps.nodata
        @test Ps.landcover((400,400), model) == Ps.grass
        @test Ps.landcover((800,800), model) == Ps.agriculture
        @test Ps.landcover((1100,1100), model) == Ps.builtup
        @test isapprox(Ps.averagefieldsize(model), 5.374u"ha"; atol=1e-3u"ha")
        @test count(f -> ismissing(f.fieldid), model.landscape) == 1685573
        @test length(Ps.farmplot((800,800), model).pixels) == 4049               
    end
    
    @testset "Utility functions" begin
        model = inittestmodel()
        iobuf = IOBuffer()
        Ps.showlandscape(iobuf, model.landscape)
        @test length(take!(iobuf)) > 0
    end
    
    @testset "Event system" begin
        model = inittestmodel()
        createevent!(model, [(1,1), (1,2), (1,3), (2,1), (2,3)], Ps.tillage)
        createevent!(model, [(1,1), (1,2), (1,3), (2,2)], Ps.sowing, 2)
        @test model.landscape[1,1].events == [Ps.tillage, Ps.sowing]
        @test model.landscape[2,1].events == [Ps.tillage]
        @test model.landscape[2,2].events == [Ps.sowing]
        @test_logs((:info, "Simulating day 2022-02-01."),
                   match_mode=:any,
                   stepsimulation!(Ps.withtestlogger(model)))
        @test model.landscape[1,1].events == [Ps.sowing]
        @test model.landscape[2,1].events == []
        @test model.landscape[2,2].events == [Ps.sowing]
        @test_logs((:info, "Simulating day 2022-02-02."),
                   match_mode=:any,
                   stepsimulation!(Ps.withtestlogger(model)))
        @test model.landscape[1,1].events == []
        @test model.landscape[2,1].events == []
        @test model.landscape[2,2].events == []
    end
    
    @testset "Landscape functions" begin
        model = inittestmodel()
        @test Ps.directionto((2,3), model, Ps.agriculture) == (0,0)
        @test Ps.directionto((2,3), model, Ps.forest) == (-1,2)
        @test Ps.directionto((2,3), model, Ps.grass) == (1,2)
        @test Ps.directionto((2,3), model, Ps.water) == (4,1)
        @test Ps.directionto((2,3), model, Ps.soil) == nothing
        @test Ps.distanceto((2,3), model, Ps.agriculture) == 0m
        @test Ps.distanceto((2,3), model, Ps.forest) == 20m
        @test Ps.distanceto((2,3), model, Ps.grass) == 20m
        @test Ps.distanceto((2,3), model, Ps.water) == 40m
        @test Ps.distanceto((2,3), model, Ps.soil) == Inf
        @test Ps.distancetoedge((1,1), model) == 40m
        @test Ps.distancetoedge((4,4), model) == 10m
        @test Ps.distancetoedge((6,6), model) == 20m
    end
    
    @testset "Weather interface" begin
        # these tests are specific to the Jena weather file
        model = inittestmodel()
        @test length(model.weather) == 59
        @test ismissing(Ps.windspeed(model))
        @test Ps.precipitation(model) == 1.3
        @test ismissing(Ps.sunshine(model))
        stepsimulation!(model)
        @test Ps.meantemp(model) == 5.1
        @test Ps.maxtemp(model) == 7.5
        @test Ps.mintemp(model) == 0.1
        stepsimulation!(model)
        @test Ps.evapotranspiration(model) == 0.6
    end