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

Wrote weather.jl

parent 57264494
Branches
No related tags found
No related merge requests found
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- Daniel Vedder - Daniel Vedder
- Lea Kolb - (Lea Kolb)
### Code reviewers ### Code reviewers
......
# This file is machine-generated - editing it directly is not advised # This file is machine-generated - editing it directly is not advised
julia_version = "1.9.0-alpha1" julia_version = "1.9.1"
manifest_format = "2.0" manifest_format = "2.0"
project_hash = "7ba06fde8b5defbbec66accfbf1488a9d06b6954" project_hash = "95079802d452de8f9a12096a3facc5e629c3d6d3"
[[deps.AbstractFFTs]] [[deps.AbstractFFTs]]
deps = ["ChainRulesCore", "LinearAlgebra"] deps = ["ChainRulesCore", "LinearAlgebra"]
...@@ -105,10 +105,10 @@ uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" ...@@ -105,10 +105,10 @@ uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82"
version = "0.4.2" version = "0.4.2"
[[deps.CSV]] [[deps.CSV]]
deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "SentinelArrays", "SnoopPrecompile", "Tables", "Unicode", "WeakRefStrings", "WorkerUtilities"] deps = ["CodecZlib", "Dates", "FilePathsBase", "InlineStrings", "Mmap", "Parsers", "PooledArrays", "PrecompileTools", "SentinelArrays", "Tables", "Unicode", "WeakRefStrings", "WorkerUtilities"]
git-tree-sha1 = "8c73e96bd6817c2597cfd5615b91fca5deccf1af" git-tree-sha1 = "44dbf560808d49041989b8a96cae4cffbeb7966a"
uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" uuid = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
version = "0.10.8" version = "0.10.11"
[[deps.Calculus]] [[deps.Calculus]]
deps = ["LinearAlgebra"] deps = ["LinearAlgebra"]
...@@ -184,7 +184,7 @@ version = "4.5.0" ...@@ -184,7 +184,7 @@ version = "4.5.0"
[[deps.CompilerSupportLibraries_jll]] [[deps.CompilerSupportLibraries_jll]]
deps = ["Artifacts", "Libdl"] deps = ["Artifacts", "Libdl"]
uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae"
version = "1.0.1+0" version = "1.0.2+0"
[[deps.CompositionsBase]] [[deps.CompositionsBase]]
git-tree-sha1 = "455419f7e328a1a2493cabc6428d79e951349769" git-tree-sha1 = "455419f7e328a1a2493cabc6428d79e951349769"
...@@ -683,7 +683,7 @@ version = "1.1.7" ...@@ -683,7 +683,7 @@ version = "1.1.7"
[[deps.MbedTLS_jll]] [[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"] deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.0+0" version = "2.28.2+0"
[[deps.Meshes]] [[deps.Meshes]]
deps = ["CategoricalArrays", "CircularArrays", "Distances", "IterTools", "IteratorInterfaceExtensions", "LinearAlgebra", "NearestNeighbors", "Random", "RecipesBase", "ReferenceFrameRotations", "SimpleTraits", "SparseArrays", "SpecialFunctions", "StaticArrays", "StatsBase", "TableTraits", "Tables"] deps = ["CategoricalArrays", "CircularArrays", "Distances", "IterTools", "IteratorInterfaceExtensions", "LinearAlgebra", "NearestNeighbors", "Random", "RecipesBase", "ReferenceFrameRotations", "SimpleTraits", "SparseArrays", "SpecialFunctions", "StaticArrays", "StatsBase", "TableTraits", "Tables"]
...@@ -764,7 +764,7 @@ version = "1.12.8" ...@@ -764,7 +764,7 @@ version = "1.12.8"
[[deps.OpenBLAS_jll]] [[deps.OpenBLAS_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"]
uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" uuid = "4536629a-c528-5b80-bd46-f80d51c5b363"
version = "0.3.21+0" version = "0.3.21+4"
[[deps.OpenJpeg_jll]] [[deps.OpenJpeg_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Libtiff_jll", "LittleCMS_jll", "Pkg", "libpng_jll"] deps = ["Artifacts", "JLLWrappers", "Libdl", "Libtiff_jll", "LittleCMS_jll", "Pkg", "libpng_jll"]
...@@ -839,7 +839,7 @@ version = "2.5.2" ...@@ -839,7 +839,7 @@ version = "2.5.2"
[[deps.Pkg]] [[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.8.0" version = "1.9.0"
[[deps.PooledArrays]] [[deps.PooledArrays]]
deps = ["DataAPI", "Future"] deps = ["DataAPI", "Future"]
...@@ -853,6 +853,12 @@ git-tree-sha1 = "17275485f373e6673f7e7f97051f703ed5b15b20" ...@@ -853,6 +853,12 @@ git-tree-sha1 = "17275485f373e6673f7e7f97051f703ed5b15b20"
uuid = "85a6dd25-e78a-55b7-8502-1745935b8125" uuid = "85a6dd25-e78a-55b7-8502-1745935b8125"
version = "0.2.4" version = "0.2.4"
[[deps.PrecompileTools]]
deps = ["Preferences"]
git-tree-sha1 = "9673d39decc5feece56ef3940e5dafba15ba0f81"
uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
version = "1.1.2"
[[deps.Preferences]] [[deps.Preferences]]
deps = ["TOML"] deps = ["TOML"]
git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d" git-tree-sha1 = "47e5f437cc0e7ef2ce8406ce1e7e24d44915f88d"
...@@ -1104,7 +1110,7 @@ uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" ...@@ -1104,7 +1110,7 @@ uuid = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9"
[[deps.SuiteSparse_jll]] [[deps.SuiteSparse_jll]]
deps = ["Artifacts", "Libdl", "Pkg", "libblastrampoline_jll"] deps = ["Artifacts", "Libdl", "Pkg", "libblastrampoline_jll"]
uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c" uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c"
version = "5.10.1+0" version = "5.10.1+6"
[[deps.TOML]] [[deps.TOML]]
deps = ["Dates"] deps = ["Dates"]
...@@ -1239,7 +1245,7 @@ version = "1.76.0+1" ...@@ -1239,7 +1245,7 @@ version = "1.76.0+1"
[[deps.libblastrampoline_jll]] [[deps.libblastrampoline_jll]]
deps = ["Artifacts", "Libdl"] deps = ["Artifacts", "Libdl"]
uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" uuid = "8e850b90-86db-534c-a0d3-1478176c7d93"
version = "5.2.0+0" version = "5.8.0+0"
[[deps.libgeotiff_jll]] [[deps.libgeotiff_jll]]
deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "Libtiff_jll", "PROJ_jll", "Pkg"] deps = ["Artifacts", "JLLWrappers", "LibCURL_jll", "Libdl", "Libtiff_jll", "PROJ_jll", "Pkg"]
......
name = "Persefone" name = "Persefone"
uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136" uuid = "039acd1d-2a07-4b33-b082-83a1ff0fd136"
authors = ["Daniel Vedder <daniel.vedder@idiv.de>"] authors = ["Daniel Vedder <daniel.vedder@idiv.de>"]
version = "0.2" version = "0.2.0"
[deps] [deps]
Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671" Agents = "46ada45e-f475-11e8-01d0-f70cc89e6671"
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63" ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab" GeoArrays = "2fb1d81b-e6a0-5fc5-82e6-8e06903437ab"
......
### Persefone - a socio-economic-ecological model of European agricultural landscapes. ### Persefone - a socio-economic-ecological model of European agricultural landscapes.
### ###
### Daniel Vedder <daniel.vedder@idiv.de> ### Daniel Vedder <daniel.vedder@idiv.de>
### Lea Kolb <lea-deborah.kolb@idiv.de>
### (c) 2022-2023, licensed under the terms of the MIT license ### (c) 2022-2023, licensed under the terms of the MIT license
### ###
### This file defines the module/package for the Persefone model. ### This file defines the module/package for the Persefone model.
...@@ -15,6 +14,7 @@ module Persefone ...@@ -15,6 +14,7 @@ module Persefone
using using
Agents, Agents,
ArgParse, ArgParse,
CSV,
Dates, Dates,
Distributed, Distributed,
GeoArrays, #XXX this is a big dependency - can we get rid of it? GeoArrays, #XXX this is a big dependency - can we get rid of it?
...@@ -24,7 +24,7 @@ using ...@@ -24,7 +24,7 @@ using
StableRNGs, StableRNGs,
TOML TOML
## Packages to check out: ## Packages that may be useful later on:
# MacroTools, http://fluxml.ai/MacroTools.jl/stable/utilities/ # MacroTools, http://fluxml.ai/MacroTools.jl/stable/utilities/
# Debugger, https://github.com/JuliaDebug/Debugger.jl # Debugger, https://github.com/JuliaDebug/Debugger.jl
# Makie, https://docs.makie.org/stable/ # Makie, https://docs.makie.org/stable/
...@@ -37,6 +37,7 @@ using ...@@ -37,6 +37,7 @@ using
export export
#types #types
Pixel, Pixel,
Weather,
FarmEvent, FarmEvent,
FarmPlot, FarmPlot,
Animal, Animal,
......
...@@ -142,7 +142,7 @@ Certain software parameters can be set via the commandline. ...@@ -142,7 +142,7 @@ Certain software parameters can be set via the commandline.
function parsecommandline() function parsecommandline()
versionstring = """ versionstring = """
Persefone $(pkgversion(Persefone)) Persefone $(pkgversion(Persefone))
© 2022-2023 Daniel Vedder, Lea Kolb (MIT license) © 2022-2023 Daniel Vedder (MIT license)
https://git.idiv.de/xo30xoqa/persefone https://git.idiv.de/xo30xoqa/persefone
""" """
s = ArgParseSettings(add_version=true, version=versionstring) s = ArgParseSettings(add_version=true, version=versionstring)
......
...@@ -64,12 +64,17 @@ function initmodel(settings::Dict{String, Any}) ...@@ -64,12 +64,17 @@ function initmodel(settings::Dict{String, Any})
with_logger(logger) do with_logger(logger) do
events = Vector{FarmEvent}() events = Vector{FarmEvent}()
dataoutputs = Vector{DataOutput}() dataoutputs = Vector{DataOutput}()
landscape = initlandscape(settings["world.landcovermap"], settings["world.farmfieldsmap"]) landscape = initlandscape(settings["world.landcovermap"],
settings["world.farmfieldsmap"])
weather = initweather(settings["world.weatherfile"],
settings["core.startdate"],
settings["core.enddate"])
space = GridSpace(size(landscape), periodic=false) space = GridSpace(size(landscape), periodic=false)
properties = Dict{Symbol,Any}(:settings=>settings, properties = Dict{Symbol,Any}(:settings=>settings,
:logger=>logger, :logger=>logger,
:date=>settings["core.startdate"], :date=>settings["core.startdate"],
:landscape=>landscape, :landscape=>landscape,
:weather=>weather,
:dataoutputs=>dataoutputs, :dataoutputs=>dataoutputs,
:events=>events) :events=>events)
model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties, model = AgentBasedModel(Union{Farmer,Animal,FarmPlot}, space, properties=properties,
......
...@@ -21,6 +21,7 @@ enddate = 2022-12-31 ...@@ -21,6 +21,7 @@ enddate = 2022-12-31
[world] [world]
landcovermap = "data/landcover_jena.tif" # location of the landcover map landcovermap = "data/landcover_jena.tif" # location of the landcover map
farmfieldsmap = "data/fields_jena.tif" # location of the field geometry map farmfieldsmap = "data/fields_jena.tif" # location of the field geometry map
weatherfile = "data/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)
......
...@@ -4,4 +4,107 @@ ...@@ -4,4 +4,107 @@
### to the rest of the model. ### to the rest of the model.
### ###
##TODO (issue #8) ##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
end
"""
initweather(weatherfile, startdate, enddate)
Load a weather file, extract the values that are relevant to this model run
(specified by start and end dates), and return a dictionary of Weather objects
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)
data = CSV.File(weatherfile, missingstring="NA", dateformat="yyyymmdd",
types=[Date, Float64, Float64, Float64, Float64,
Float64, Float64, Float64])
weather = Dict{Date,Weather}()
for row in data
if row.date >= startdate && row.date <= enddate
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))
end
end
weather
end
"""
windspeed(model)
Return today's average windspeed in m/s.
"""
function windspeed(model::AgentBasedModel)
model.weather[model.date].windspeed
end
"""
precipitation(model)
Return today's total precipitation in mm.
"""
function precipitation(model::AgentBasedModel)
model.weather[model.date].precipitation
end
"""
sunshine(model)
Return today's sunshine duration in hours.
"""
function sunshine(model::AgentBasedModel)
model.weather[model.date].sunshine
end
"""
vapourpressure(model)
Return today's average vapour pressure in hPa.
"""
function vapourpressure(model::AgentBasedModel)
model.weather[model.date].vapourpressure
end
"""
meantemp(model)
Return today's mean temperature in °C.
"""
function meantemp(model::AgentBasedModel)
model.weather[model.date].meantemp
end
"""
maxtemp(model)
Return today's maximum temperature in °C.
"""
function maxtemp(model::AgentBasedModel)
model.weather[model.date].maxtemp
end
"""
mintemp(model)
Return today's minimum temperature in °C.
"""
function mintemp(model::AgentBasedModel)
model.weather[model.date].mintemp
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment