-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_wofost.py
59 lines (52 loc) · 2.08 KB
/
run_wofost.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-
# Copyright (c) 2023 LEEP, University of Exeter (UK)
# Mattia Mancini (m.c.mancini@exeter.ac.uk), January 2024
# =======================================================
"""
run_wofost.py
=============
Run an instance of WOFOST for any location in the UK, for any
user-defined crop and agromanagement.
This will be the main script for testing WOFOST, compare
versions, build features and so on.
INPUT PARAMETERS
:param LON, LAT: coordinates of the location for which Wofost
needs to be run
:param CROP: crop of interest
:param YEAR: year of interest
Crop details and agromanagment are loaded from a file containing
default values for the specific crop. They can be overwritten
to have user-sepcified values. This can be done in the section
called "Define management", line 43 and following. The best option
is to load the default crop parameters (line 44) and change their
values before passing the crop_params dictionary when the instance
of the Crop class is instantiated (line 45). More information on
agromanagment can be found at https://tinyurl.com/bdcmj5b7
"""
from ukwofost.core.crop_manager import Crop
from ukwofost.core.defaults import defaults
from ukwofost.core.simulation_manager import WofostSimulator
from ukwofost.core.utils import lonlat2osgrid
# Define input parameters
LON, LAT = -1.670330465465696, 55.028574354445425
CROP = "wheat"
YEAR = 2019
# Build Wofost simulator
os_code = lonlat2osgrid((LON, LAT), 10)
sim = WofostSimulator(
location=os_code, weather_provider="ERA5", soil_provider="SoilGrids"
)
crop_management = defaults.get("management").get(CROP)
crop = Crop(calendar_year=YEAR, crop=CROP, **crop_management)
crop_output = sim.run(crop_or_rotation=crop, output_flag="full")
# # Define management
# rotation = []
# for item in zip(CROPS, YEARS):
# crop = item[0]
# year = item[1]
# crop_params = defaults.get("management").get(crop)
# rotation.append(Crop(calendar_year=year, crop=crop, **crop_params))
# crop_rotation = CropRotation(rotation)
# Run WOFOST to compute crop yield
# crop_yield = sim.run(crop_rotation)
# print(crop_yield)