Skip to content
Snippets Groups Projects
Commit 5d5e801b authored by xo30xoqa's avatar xo30xoqa
Browse files

Wrote tests for weather module

parent c438f0ce
Branches testsuite
Tags
No related merge requests found
......@@ -4,21 +4,19 @@
### to the rest of the model.
###
##TODO write tests
"""
Weather
A single weather datum, combining the observations from one day.
"""
struct Weather
windspeed::Float64
precipitation::Float64
sunshine::Float64
vapourpressure::Float64
meantemp::Float64
maxtemp::Float64
mintemp::Float64
windspeed::Union{Missing,Float64}
precipitation::Union{Missing,Float64}
sunshine::Union{Missing,Float64}
vapourpressure::Union{Missing,Float64}
meantemp::Union{Missing,Float64}
maxtemp::Union{Missing,Float64}
mintemp::Union{Missing,Float64}
end
"""
......@@ -31,6 +29,7 @@ mapped to dates.
**Note:** This requires a weather file in the format produced by `data/extract_weather_data.R`.
"""
function initweather(weatherfile::String, startdate::Date, enddate::Date)
@debug "Initialising weather"
data = CSV.File(weatherfile, missingstring="NA", dateformat="yyyymmdd",
types=[Date, Float64, Float64, Float64, Float64,
Float64, Float64, Float64])
......@@ -40,8 +39,11 @@ function initweather(weatherfile::String, startdate::Date, enddate::Date)
weather[row.date] = Weather(row.mean_windspeed, row.precipitation,
row.sunshine_hours, row.mean_vapour_pressure,
row.mean_temperature, row.max_temperature,
row.min_temperature))
row.min_temperature)
end
end
if length(weather) <= Dates.value(enddate-startdate)
@warn "There are missing days in the weather input file."
end
weather
end
......
......@@ -47,6 +47,7 @@ end
@test_logs((:info, "Simulated 366 days."),
match_mode=:any,
simulate!(Ps.withtestlogger(model)))
@param(core.enddate) = Date(2022,3,31) # change back to original to prevent errors
@test !isfile(joinpath(outdir, "never.csv"))
@test isfile(joinpath(outdir, "daily.csv"))
@test countlines(joinpath(outdir, "daily.csv")) == 367
......
### Persefone - a socio-economic-ecological model of European agricultural landscapes.
###
### These are the tests for the core landscape functions.
### These are the tests for the landscape and weather functions.
###
@testset "Landscape initialisation" begin
......@@ -55,3 +55,21 @@ end
@test Ps.distancetoedge((4,4), model) == 1
@test Ps.distancetoedge((6,6), model) == 2
end
@testset "Weather initialisation" begin
# these tests are specific to the Jena weather file
model = smalltestlandscape()
@test_logs((:warn, "There are missing days in the weather input file."),
Ps.initweather(TESTSETTINGS["world.weatherfile"],
Date("2022-01-01"), Date("2023-12-31")))
@test length(keys(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.vapourpressure(model) == 7.7
end
......@@ -175,7 +175,7 @@ end
@testset "Energy submodel" begin
# DEB data for the skylark (https://bio.vu.nl/thb/deb/deblab/add_my_pet/entries_web/Alauda_arvensis/Alauda_arvensis_res.html)
skylarkparams = DEBparameters(0.0, # F_m XXX is unknown
skylarkparams = Ps.DEBparameters(0.0, # F_m XXX is unknown
0.8, # y_EX Sibly et al. (2013)
0.8075, # y_VE
0.04761, # v
......
......@@ -42,8 +42,12 @@ function smalltestlandscape()
end
landscape[6,4] = Pixel(Ps.water, 0, [])
space = GridSpace(size(landscape), periodic=false)
weather = Ps.initweather(TESTSETTINGS["world.weatherfile"],
TESTSETTINGS["core.startdate"],
TESTSETTINGS["core.enddate"])
properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core.startdate"],
:landscape=>landscape,
:weather=>weather,
:events=>Vector{FarmEvent}(),
:logger=>global_logger(),
:dataoutputs=>Vector{DataOutput}(),
......
......@@ -19,6 +19,7 @@ enddate = 2022-03-31
[world]
landcovermap = "landcover_jena.tif" # location of the landcover map
farmfieldsmap = "fields_jena.tif" # location of the field geometry map
weatherfile = "weather_jena.csv" # location of the weather data file
[farm]
farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented)
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment