Skip to content
Snippets Groups Projects
Select Git revision
  • c08aa148e49803263c292822ba57751279763fb4
  • master default protected
  • development
  • marco-development
  • fix-missing-weatherdata
  • fix-eichsfeld-weather
  • marco/dev-aquacrop
  • precompile-statements
  • precompile-tools
  • tmp-faster-loading
  • skylark
  • testsuite
  • code-review
  • v0.7.0
  • v0.6.1
  • v0.6.0
  • v0.5.5
  • v0.5.4
  • v0.5.3
  • v0.5.2
  • v0.2
  • v0.3.0
  • v0.4.1
  • v0.5
24 results

aquacrop.jl

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    aquacrop.jl 1.84 KiB
    import AquaCrop
    
    struct AquaCropType
        name::String
        group::String
        minsowdate::Union{Missing,AnnualDate}
        maxsowdate::Union{Missing,AnnualDate}
    end
    
    cropname(ct::AquaCropType) = ct.name
    
    mutable struct AquaCropState
        croptype::AquaCropType
        height::Length{Float64}  # TODO: remove height field, supply from cropstate
        cropstate::AquaCrop.AquaCropField
    
        function AquaCropState(croptype::AquaCropType, height::Length{Float64}=0.0cm)
            ac_parentdir = AquaCrop.test_toml_dir  # TODO: hardcoded croptype
            ac_runtype = :Julia
            # cropstate = AquaCrop.AquaCropField(ac_parentdir, ac_runtype)
            cropstate, allok = AquaCrop.initialize_cropfield(ac_parentdir, ac_runtype)
            if ! allok.logi
                error("AquaCrop.initialize_cropfield() failed, status = $allok")
            end
            return new(croptype, height, cropstate)
        end
    end
    
    croptype(cs::AquaCropState) = cs.croptype
    cropname(cs::AquaCropState) = cropname(croptype(cs))
    cropheight(cs::AquaCropState) = cs.height
    cropcover(cs::AquaCropState) = 0.0  # TODO: implement
    cropyield(cs::AquaCropState) = 0.0  # TODO: implement, units?
    isharvestable(cs::AquaCropState) = true  # TODO: implement this correctly
    
    """
        stepagent!(cropstate, model)
    
    Update a crop state by one day.
    """
    function stepagent!(cs::AquaCropState, model::SimulationModel)
        # TODO: call into AquaCrop.jl to simulate one day
    end
    
    """
        sow!(cropstate, model, cropname)
    
    Change the cropstate to sow the specified crop.
    """
    function sow!(cs::AquaCropState, model::SimulationModel, cropname::String)
        cs.croptype = model.crops[cropname]
        cs.height = 0.0cm
        # TODO: other things needed for AquaCrop?
    end
    
    """
        harvest!(cropstate, model)
    
    Harvest the crop of this cropstate.
    """
    function harvest!(cs::AquaCropState, model::SimulationModel)
        # TODO: implement this
        return 0.0u"g/m^2"
    end