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

Wrote tests for weather module

parent c438f0ce
No related branches found
No related tags found
No related merge requests found
...@@ -4,21 +4,19 @@ ...@@ -4,21 +4,19 @@
### to the rest of the model. ### to the rest of the model.
### ###
##TODO write tests
""" """
Weather Weather
A single weather datum, combining the observations from one day. A single weather datum, combining the observations from one day.
""" """
struct Weather struct Weather
windspeed::Float64 windspeed::Union{Missing,Float64}
precipitation::Float64 precipitation::Union{Missing,Float64}
sunshine::Float64 sunshine::Union{Missing,Float64}
vapourpressure::Float64 vapourpressure::Union{Missing,Float64}
meantemp::Float64 meantemp::Union{Missing,Float64}
maxtemp::Float64 maxtemp::Union{Missing,Float64}
mintemp::Float64 mintemp::Union{Missing,Float64}
end end
""" """
...@@ -31,6 +29,7 @@ mapped to dates. ...@@ -31,6 +29,7 @@ mapped to dates.
**Note:** This requires a weather file in the format produced by `data/extract_weather_data.R`. **Note:** This requires a weather file in the format produced by `data/extract_weather_data.R`.
""" """
function initweather(weatherfile::String, startdate::Date, enddate::Date) function initweather(weatherfile::String, startdate::Date, enddate::Date)
@debug "Initialising weather"
data = CSV.File(weatherfile, missingstring="NA", dateformat="yyyymmdd", data = CSV.File(weatherfile, missingstring="NA", dateformat="yyyymmdd",
types=[Date, Float64, Float64, Float64, Float64, types=[Date, Float64, Float64, Float64, Float64,
Float64, Float64, Float64]) Float64, Float64, Float64])
...@@ -40,9 +39,12 @@ function initweather(weatherfile::String, startdate::Date, enddate::Date) ...@@ -40,9 +39,12 @@ function initweather(weatherfile::String, startdate::Date, enddate::Date)
weather[row.date] = Weather(row.mean_windspeed, row.precipitation, weather[row.date] = Weather(row.mean_windspeed, row.precipitation,
row.sunshine_hours, row.mean_vapour_pressure, row.sunshine_hours, row.mean_vapour_pressure,
row.mean_temperature, row.max_temperature, row.mean_temperature, row.max_temperature,
row.min_temperature)) row.min_temperature)
end end
end end
if length(weather) <= Dates.value(enddate-startdate)
@warn "There are missing days in the weather input file."
end
weather weather
end end
......
...@@ -47,6 +47,7 @@ end ...@@ -47,6 +47,7 @@ end
@test_logs((:info, "Simulated 366 days."), @test_logs((:info, "Simulated 366 days."),
match_mode=:any, match_mode=:any,
simulate!(Ps.withtestlogger(model))) 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, "never.csv"))
@test isfile(joinpath(outdir, "daily.csv")) @test isfile(joinpath(outdir, "daily.csv"))
@test countlines(joinpath(outdir, "daily.csv")) == 367 @test countlines(joinpath(outdir, "daily.csv")) == 367
......
### Persefone - a socio-economic-ecological model of European agricultural landscapes. ### 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 @testset "Landscape initialisation" begin
...@@ -55,3 +55,21 @@ end ...@@ -55,3 +55,21 @@ end
@test Ps.distancetoedge((4,4), model) == 1 @test Ps.distancetoedge((4,4), model) == 1
@test Ps.distancetoedge((6,6), model) == 2 @test Ps.distancetoedge((6,6), model) == 2
end 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,18 +175,18 @@ end ...@@ -175,18 +175,18 @@ end
@testset "Energy submodel" begin @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) # 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.8, # y_EX Sibly et al. (2013)
0.8075, # y_VE 0.8075, # y_VE
0.04761, # v 0.04761, # v
0.0, # J_ET XXX is unknown 0.0, # J_ET XXX is unknown
4699,# J_EM XXX seems awfully high? 4699,# J_EM XXX seems awfully high?
0.9886, # k 0.9886, # k
0.95,# k_R 0.95,# k_R
0.0, # M_E0 XXX is unknown 0.0, # M_E0 XXX is unknown
3.4, # M_Hb 3.4, # M_Hb
25 # M_Hp XXX this seems too low? 25 # M_Hp XXX this seems too low?
) )
#TODO #TODO
end end
...@@ -42,8 +42,12 @@ function smalltestlandscape() ...@@ -42,8 +42,12 @@ function smalltestlandscape()
end end
landscape[6,4] = Pixel(Ps.water, 0, []) landscape[6,4] = Pixel(Ps.water, 0, [])
space = GridSpace(size(landscape), periodic=false) 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"], properties = Dict{Symbol,Any}(:date=>TESTSETTINGS["core.startdate"],
:landscape=>landscape, :landscape=>landscape,
:weather=>weather,
:events=>Vector{FarmEvent}(), :events=>Vector{FarmEvent}(),
:logger=>global_logger(), :logger=>global_logger(),
:dataoutputs=>Vector{DataOutput}(), :dataoutputs=>Vector{DataOutput}(),
......
...@@ -19,6 +19,7 @@ enddate = 2022-03-31 ...@@ -19,6 +19,7 @@ enddate = 2022-03-31
[world] [world]
landcovermap = "landcover_jena.tif" # location of the landcover map landcovermap = "landcover_jena.tif" # location of the landcover map
farmfieldsmap = "fields_jena.tif" # location of the field geometry map farmfieldsmap = "fields_jena.tif" # location of the field geometry map
weatherfile = "weather_jena.csv" # location of the weather data file
[farm] [farm]
farmmodel = "FieldManager" # which version of the farm model to use (not yet implemented) 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