Skip to content
Snippets Groups Projects
Commit 60dc9894 authored by Marco Matthies's avatar Marco Matthies
Browse files

Simple linear height estimation

parent 79c11757
No related branches found
No related tags found
No related merge requests found
...@@ -5,9 +5,11 @@ module AquaCropWrapper ...@@ -5,9 +5,11 @@ module AquaCropWrapper
const CROPFILE = "crop_data.csv" const CROPFILE = "crop_data.csv"
import AquaCrop import AquaCrop
using AquaCrop: ton
import CSV import CSV
using Dates: Date using Dates: Date
using DataFrames: DataFrame using DataFrames: DataFrame
using Unitful: @u_str
using Persefone: using Persefone:
AbstractCropState, AbstractCropState,
...@@ -183,7 +185,13 @@ end ...@@ -183,7 +185,13 @@ end
croptype(cs::CropState) = cs.croptype croptype(cs::CropState) = cs.croptype
cropname(cs::CropState) = cropname(croptype(cs)) cropname(cs::CropState) = cropname(croptype(cs))
cropheight(cs::CropState) = cs.height # TODO: calculate from AquaCrop state info function cropheight(cs::CropState)
biomass = get_aquacrop_biomass(cs)
# TODO: linear model, fixed params
a = 20cm
b = 18u"cm * ha" / ton
return a + b * biomass
end
cropcover(cs::CropState) = AquaCrop.canopycover(cs.cropstate) cropcover(cs::CropState) = AquaCrop.canopycover(cs.cropstate)
cropyield(cs::CropState) = AquaCrop.dryyield(cs.cropstate) # TODO: there is also freshyield cropyield(cs::CropState) = AquaCrop.dryyield(cs.cropstate) # TODO: there is also freshyield
function isharvestable(cs::CropState) function isharvestable(cs::CropState)
...@@ -204,6 +212,11 @@ function get_aquacrop_stage(cs::CropState) ...@@ -204,6 +212,11 @@ function get_aquacrop_stage(cs::CropState)
length(stages) > 0 ? last(stages) : missing length(stages) > 0 ? last(stages) : missing
end end
function get_aquacrop_biomass(cs::CropState)
biomasses = cs.cropstate.dayout.Biomass
length(biomasses) > 0 ? last(biomasses) : missing
end
""" """
stepagent!(cropstate, model) stepagent!(cropstate, model)
......
...@@ -70,7 +70,9 @@ end ...@@ -70,7 +70,9 @@ end
@test fp.cropstate isa PsAC.CropState @test fp.cropstate isa PsAC.CropState
@test croptype(fp) isa PsAC.CropType @test croptype(fp) isa PsAC.CropType
@test cropname(fp) isa String @test cropname(fp) isa String
@test cropheight(fp) isa Length{Float64} # TODO: better testing for cropheight
ch = cropheight(fp)
@test ismissing(ch) || Unitful.dimension(ch) == Unitful.𝐋
@test cropcover(fp) isa Float64 @test cropcover(fp) isa Float64
@test Unitful.dimension(cropyield(fp)) == Unitful.𝐌 * Unitful.𝐋^-2 @test Unitful.dimension(cropyield(fp)) == Unitful.𝐌 * Unitful.𝐋^-2
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment