AquaCrop API
API documentation for AquaCrop.
AquaCrop.AquaCropFieldAquaCrop.NoFileRunAquaCrop.NormalFileRunAquaCrop.TomlFileRunAquaCrop.basic_runAquaCrop.biomassAquaCrop.canopycoverAquaCrop.change_climate_data!AquaCrop.check_kwargsAquaCrop.check_nofilerunAquaCrop.check_parentdirAquaCrop.check_runtypeAquaCrop.dailyupdate!AquaCrop.dryyieldAquaCrop.freshyieldAquaCrop.harvest!AquaCrop.isharvestableAquaCrop.save_cropAquaCrop.season_run!AquaCrop.start_cropfieldAquaCrop.timetoharvestAquaCrop.write_out_csv
Types
AquaCrop.AquaCropField — TypeAquaCropField
Has all the data for the simulation of a cropfield::AquaCropField variable stored in dictionaries.
Initialize an object of this type using the function start_cropfield or making a deepcopy of another cropfield.
See also start_cropfield
AquaCrop.NoFileRun — Typeruntype = NoFileRun()Indicates the configuration will be loaded manualy via julia variables
AquaCrop.NormalFileRun — Typeruntype = NormalFileRun()Indicates the configuration will be loading files like in AquaCrop fortran.
AquaCrop.TomlFileRun — Typeruntype = TomlFileRun()Indicates the configuration will be loading TOML and csv files.
Methods
AquaCrop.basic_run — Methodoutputs = basic_run(; kwargs...)Runs a basic AquaCrop simulation, the outputs variable has the final dataframes with the results of the simulation
runtype allowed for now is NormalFileRun or TomlFileRun
NormalFileRun will use the input from a files like in AquaCrop Fortran (see AquaCrop.jl/test/testcase)
TomlFileRun will use the input from TOML files (see AquaCrop.jl/test/testcase/TOML_FILES)
You can see the daily result in outputs[:dayout] the result of each harvest in outputs[:harvestsout] the result of the whole season in outputs[:seasonout] the information for the evaluation in outputs[:evaldataout] and the logger information in outputs[:logger]
AquaCrop.biomass — Methodbiomass = biomass(cropfield::AquaCropField)Returns the biomass of the cropfield with units ton/ha
AquaCrop.canopycover — Methodcanopycover(cropfield::AquaCropField; actual=true)Returns the canopy cover of the cropfield in percentage of terrain covered.
If actual=true, returns the canopy cover just before harvesting, otherwise returns the canopy cover just after harvesting
The harvesting is done at the end of the day.
AquaCrop.change_climate_data! — Methodchange_climate_data!(cropfield::AquaCropField, climate_data::DataFrame; kwargs...)Changes the climate data in the cropfield using the data in climate_data.
Note that climate_data must have a column with :Date property, other wise we do not change anything. The function assumes that :Date goes day by day.
climate_data must also have one of the following climate properties [:Tmin, :Tmax, :ETo, :Rain].
AquaCrop.dailyupdate! — Methoddailyupdate!(cropfield::AquaCropField)Updates the cropfield by one day
AquaCrop.dryyield — Methoddryyield = dryyield(cropfield::AquaCropField)Returns the dry yield of the cropfield with units ton/ha
AquaCrop.freshyield — Methodfreshyield = freshyield(cropfield::AquaCropField)Returns the fresh yield of the cropfield with units ton/ha
AquaCrop.harvest! — Methodharvest!(cropfield::AquaCropField)Indicates to make a harvest on the cropfield it also makes a daily update along with the harvest
AquaCrop.isharvestable — Methodlogi = isharvestable(cropfield::AquaCropField)If a crop is harvestable returns true
See also timetoharvest
AquaCrop.save_crop — Functionsave_crop(file, cropfield::AquaCropField, head=nothing; kwargs...)head header to describe the file. Defaults to head = "# Crop saved in "*string(today())
Writes the crop into a toml file. Useful after tunning a crop
AquaCrop.season_run! — Methodseason_run!(cropfield::AquaCropField)Updates the cropfield for all days in the current season
In case you upload the data using NormalFileRun or TomlFileRun and you indicate multiple seasons, it will only run the first season.
In case you upload the data using NoFileRun it runs the simulation from Simulation_DayNr1 up to Simulation_DayNrN.
AquaCrop.start_cropfield — Methodcropfield, all_ok = start_cropfield(; kwargs...)Starts the cropfield::AquaCropField with the proper runtype. it uses default values for runtype and parentdir if these kwargs are missing.
It returns a cropfield with default values for crop, soil, etc. After calling this function check if all_ok.logi == true
AquaCrop.timetoharvest — Methodth = timetoharvest(cropfield::AquaCropField)If a crop is not harvestable returns the minimum amount of simulation days until is harvestable.
If a crop is already harvestable returns how many simulations days until crop reaches maturity.
See also isharvestable
AquaCrop.write_out_csv — Methodwrite_out_csv(file, cropfield::AquaCropField, field::Symbol; kwargs...)Writes the dataframe of cropfield.outputs[field] on file using csv format.
This is a wraper of CSV.write that removes the units, the keywords kwargs are passed to CSV.write.
If the digits keyword argument is provided, it rounds to the specified number of digits after the decimal place, otherwise uses default of digits=4.
Additional Functions
AquaCrop.check_kwargs — Functionkwargs, all_ok = check_kwargs(outputs; kwargs...)Runs all the necessary checks on the kwargs.
After calling this function check if all_ok.logi == true
See also check_runtype, check_parentdir, check_nofilerun
Examples
julia> kwargs, all_ok = AquaCrop.check_kwargs(Dict(:logger => String[]); runtype=TomlFileRun(), parentdir=pwd());
julia> all_ok.logi == true
trueAquaCrop.check_runtype — Functionkwargs, all_ok = check_runtype(outputs; kwargs...)If we do not have a kwarg for :runtype it sets it to NormalFileRun. If we do have that kwarg, then checks if it is an AbstractRunType.
After calling this function check if all_ok.logi == true
Examples
julia> kwargs, all_ok = AquaCrop.check_runtype(Dict(:logger => String[]); runtype = TomlFileRun());
julia> all_ok.logi == true
trueAquaCrop.check_parentdir — Functionkwargs, all_ok = check_parentdir(outputs; kwargs...)If we do not have a kwarg for parentdir it sets it to pwd(). If we do have that kwarg, then checks if that directory exists.
After calling this function check if all_ok.logi == true
Examples
julia> kwargs, all_ok = AquaCrop.check_parentdir(Dict(:logger => String[]); parentdir=pwd());
julia> all_ok.logi == true
trueAquaCrop.check_nofilerun — Functionkwargs, all_ok = check_nofilerun(outputs; kwargs...)In case we select a runtype = NoFileRun() checks that we have all the necessary kwargs, these are:
For the project input we have the following necessary keywords: Simulation_DayNr1, Simulation_DayNrN, Crop_Day1, Crop_DayN, InitialClimDate each one of them must be a Date type.
The soil_type must be one of these strings indicating the soil type: ["sandy clay", "clay", "clay loam", "loamy sand", "loam", "sand", "silt", "silty loam", "silty clay", "sandy clay loam", "sandy loam", "silty clay loam", "paddy"]
The crop_type must be one of these strings indicating the crop type: ["maize", "wheat", "cotton", "alfalfaGDD", "barley", "barleyGDD", "cottonGDD", "drybean", "drybeanGDD", "maizeGDD", "wheatGDD", "sugarbeet", "sugarbeetGDD", "sunflower", "sunflowerGDD", "sugarcane", "tomato", "tomatoGDD", "potato", "potatoGDD", "quinoa", "tef", "soybean", "soybeanGDD", "sorghum", "sorghumGDD", "paddyrice", "paddyriceGDD", "rapeseed", "oat", "rapeseedGDD"]
We also have the optional keys: [:co2i, :crop, :perennial_period, :soil, :soil_layers, :simulparam, :Tmin, :Tmax, :ETo, :Rain, :temperature_record, :eto_record, :rain_record, :management (with this we need to change projectinput.Management_Filename too)] which give more control when configurating the cropfield::AquaCropField, similarly to using NormalFileRun or TomlFileRun.
After calling this function check if all_ok.logi == true
Examples
julia> using Dates
julia> start_date = Date(2023, 1, 1); # January 1 2023
julia> end_date = Date(2023, 6, 1); # June 1 2023
julia> kwargs = (runtype = NoFileRun(), Simulation_DayNr1 = start_date, Simulation_DayNrN = end_date, Crop_Day1 = start_date, Crop_DayN = end_date, soil_type = "clay", crop_type = "maize", InitialClimDate = start_date);
julia> kwargs, all_ok = AquaCrop.check_nofilerun(Dict(:logger => String[]); kwargs...);
julia> all_ok.logi == true
true