Skip to content
Snippets Groups Projects
Select Git revision
  • 479afb4532b2453bba1bdde2b0c96601cf40db23
  • 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

landscape.jl

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    weather.jl 2.87 KiB
    ### Persefone.jl - a model of agricultural landscapes and ecosystems in Europe.
    ###
    ### This file reads in weather data for the selected location and makes it available
    ### to the rest of the model.
    ###
    
    """
        Weather
    
    A single weather datum, combining the observations from one day.
    """
    struct Weather
        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
    
    """
        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)
        @debug "Initialising weather"
        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
        if length(weather) <= Dates.value(enddate-startdate)
            @warn "There are missing days in the weather input file."
        end
        weather
    end
    
    """
        windspeed(model)
    
    Return today's average windspeed in m/s.
    """
    function windspeed(model::SimulationModel)
        model.weather[model.date].windspeed
    end
    
    """
        precipitation(model)
    
    Return today's total precipitation in mm.
    """
    function precipitation(model::SimulationModel)
        model.weather[model.date].precipitation
    end
    
    """
        sunshine(model)
    
    Return today's sunshine duration in hours.
    """
    function sunshine(model::SimulationModel)
        model.weather[model.date].sunshine
    end
    
    """
        vapourpressure(model)
    
    Return today's average vapour pressure in hPa.
    """
    function vapourpressure(model::SimulationModel)
        model.weather[model.date].vapourpressure
    end
    
    """
        meantemp(model)
    
    Return today's mean temperature in °C.
    """
    function meantemp(model::SimulationModel)
        model.weather[model.date].meantemp
    end
    
    """
        maxtemp(model)
    
    Return today's maximum temperature in °C.
    """
    function maxtemp(model::SimulationModel)
        model.weather[model.date].maxtemp
    end
    
    """
        mintemp(model)
    
    Return today's minimum temperature in °C.
    """
    function mintemp(model::SimulationModel)
        model.weather[model.date].mintemp
    end