..

WofostR, tutorial

R implementation of Wofost crop simulation model

See De Wit et al. (2019) for details.

Python version available at ajdewit/pcse as part of the Python Crop Simulation Environment (PCSE/WOFOST).

Installation

Install with:

devtools::install_github('lucabutikofer/WofostR',
                         build_opts = c("--no-resave-data", "--no-manual"),
                         build_vignettes = T)

Testing

After installation is complete you can test the program with test().This command uses the files published by De Wit et al. downloading a copy from the WofostR_testData repository to test either a specific routine (e.g. test(component = "leafdynamics")) or all available components if none is specified. Currently only “astro”, “leafdynamics” and “potentialproduction” are implemented. Many routines are not independent funtions like in PCSE/WOFOST but are hardcoded within function Wofost(), which is run in the “potentialproduction” and “waterlimitedproduction” tests. Passing the “potentialproduction” or “waterlimitedproduction” tests means also passing “assimilation”, “astro”, “leafdynamics”, “partitioning”, “phenology”, “respiration”, “rootdynamics” and “transpiration” (although transpiration is not actually used to copute potential production). By default only three test sets are randomly chosen to perform tests on. This is done to speed up the process. To perform tests on all available sets call test(complete = TRUE).

test(component = 'phenology', complete = TRUE)
test()

Input files

Four types of input files are required to run the Wofost():

These are S4 classes containing the variables required by function Wofost(). Crop objects can be generated by calling dwn.crop() or load.crop() to download crops from the web or to load them from a local repository respectively. dwn.crop() retrieves specific crop parameters from ajwdewit/WOFOST_crop_parameters by specifying the crop and variety names. A list of corp and varieties names can be printed with cropVarList. load.crop() works in a similar way as dwn.crop() but reads .yaml files saved in the local directory crLocal.

cr <- dwn.crop(cropName = "sugarbeet",
                        variety = "Sugarbeet_601")
cr

#> 
#>  WofostR Crop Object: 
#>  >> Crop name: sugarbeet 
#>  >> Variety name: Sugarbeet_601 
#>  >> 92 crop parameters out of 92 are specified. 
#> 

str(cr, list.len = 3)

#> Formal class 'CropObject' [package "WofostR"] with 92 slots
#>   ..@ CROPNAME       : chr "sugarbeet"
#>   ..@ VARNAME        : chr "Sugarbeet_601"
#>   ..@ CO2EFFTB       : num [1:5, 1:2] 40 360 720 1000 2000 0 1 1.11 1.11 1.11
#>   .. ..- attr(*, "dimnames")=List of 2
#>   .. .. ..$ : NULL
#>   .. .. ..$ : chr [1:2] "x" "y"
#>   .. [list output truncated]

Weather objects must contain minimum and maximum temperature, radiation and latitude at daily time-steps starting from the day the model expected to start. An example weather object can be seen with randomWeather. WeatherObjects can be printed with the plot() function.

randomWeather

#> 
#>  WofostR Weather Object: 
#>  
#>  >> From date: 2010-04-16 
#>  >> To date: 2010-12-31 
#>  
#>    VARIABLES  LENGTH
#> 1  @DAY       260   
#> 2  @E0        260   
#> 3  @ELEV      260   
#> 4  @ES0       260   
#> 5  @ET0       260   
#> 6  @IRRAD     260   
#> 7  @LAT       260   
#> 8  @LON       260   
#> 9  @RAIN      260   
#> 10 @SNOWDEPTH 260   
#> 11 @TEMP      260   
#> 12 @TMAX      260   
#> 13 @TMIN      260   
#> 14 @VAP       260   
#> 15 @WIND      260

str(randomWeather, list.len = 3)

#> Formal class 'WeatherObject' [package "WofostR"] with 15 slots
#>   ..@ DAY      : Date[1:260], format: "2010-04-16" ...
#>   ..@ E0       : num [1:260] 0.292 0.307 0.303 0.345 0.332 0.295 0.288 0.333 0.369 0.439 ...
#>   ..@ ELEV     : num [1:260] 440 440 440 440 440 440 440 440 440 440 ...
#>   .. [list output truncated]

plot(randomWeather, var = c('RAIN','TMIN'))

plot of chunk unnamed-chunk-5

SoilObjects are used to compute water-limited production (Wofost(... , waterLimited = T)) and contain soil variables for a single location. An example weather object can be seen with randomSoil.

randomSoil

#> 
#>  WofostR Soil Object: 
#>  >> 14 soil parameters out of 14 are specified. 
#> 

str(randomSoil)

#> Formal class 'SoilObject' [package "WofostR"] with 14 slots
#>   ..@ SMFCF : num 0.318
#>   ..@ SM0   : num 0.415
#>   ..@ SMW   : num 0.151
#>   ..@ CRAIRC: num 0.06
#>   ..@ SOPE  : num 10
#>   ..@ KSUB  : num 10
#>   ..@ K0    : num 10
#>   ..@ RDMSOL: num 60
#>   ..@ IFUNRN: int 0
#>   ..@ SSMAX : num 0
#>   ..@ SSI   : num 0
#>   ..@ WAV   : num 10
#>   ..@ NOTINF: num 0
#>   ..@ SMLIM : num 0.318

ManagerObjects are used to run a sequence of crops simulation in succession for the same location (e.g. a crop rotation or the same crop over multiple years). An example ManagerObject can be seen with exampleManager.

mo <- ManagerObject(
        cropSequence = c(
          'barley-Spring_barley_301',
          'millet-Millet_VanHeemst_1988',
          'maize-Grain_maize_201'),
        sequenceStart = '2010/04/16',
        sequenceFinish = '2012/01/01',
        cropStartType = c('sowing', 'sowing', 'sowing'),
        cropStartDate = c(NA, '2011/04/16', NA),
        cropFinish = c('maturity','2011/05/16','maturity'),
        spacing = c(0, NA, 10 )
      )
mo

#> 
#>  WofostR Manager Object: 
#>  >> Starting sequence: 2010/04/16 
#>  >> Finishing sequence: 2012/01/01 
#>  >> Crop rotation: 
#>  
#>      Crops                        Start_types Start_dates Finish    
#> [1,] barley-Spring_barley_301     sowing      <NA>        maturity  
#> [2,] millet-Millet_VanHeemst_1988 sowing      2011/04/16  2011/05/16
#> [3,] maize-Grain_maize_201        sowing      <NA>        maturity  
#>      Spacing
#> [1,] 0      
#> [2,] <NA>   
#> [3,] 10

Running Wofost

Wofost crop simulation model is run by functions Wofost(). Potential Production and Free Draining water-limited production are called by setting variable waterLimited to FALSE or TRUE respectively.

# Run Potential Production
outPP <- Wofost(crop = dwn.crop(), w = randomWeather)
# Run Water-Limited Production
outFD <- Wofost(crop = dwn.crop(), w = randomWeather, soil = randomSoil,
                waterLimited = TRUE)
plot(outFD)

plot of chunk unnamed-chunk-8

# Run crop rotation with ManagerObject
outMN <- Wofost(w = randomWeatherLong, manager = exampleManager)
plot(outMN, var = 'tagp')

plot of chunk unnamed-chunk-9

Available Crops and Varieties

crop variety
barley Spring_barley_301
cassava Cassava_VanHeemst_1988
chickpea Chickpea_VanHeemst_1988
cotton Cotton_VanHeemst_1988
cowpea Cowpea_VanHeemst_1988
fababean Faba_bean_801
groundnut Groundnut_VanHeemst_1988
maize Maize_VanHeemst_1988
maize Grain_maize_201
maize Grain_maize_202
maize Grain_maize_203
maize Grain_maize_204
maize Grain_maize_205
millet Millet_VanHeemst_1988
mungbean Mungbean_VanHeemst_1988
pigeonpea Pigeonpea_VanHeemst_1988
potato Potato_701
potato Potato_702
potato Potato_703
potato Potato_704
rapeseed Oilseed_rape_1001
rapeseed Oilseed_rape_1002
rapeseed Oilseed_rape_1003
rapeseed Oilseed_rape_1004
rice Rice_501
rice Rice_HYV_IR8
rice Rice_IR64616H_DS
rice Rice_IR64616H_WS
rice Rice_IR64
rice Rice_IR72
rice Rice_IR72_DS
rice Rice_IR72_WS
rice Rice_IR8A
sorghum Sorghum_VanHeemst_1988
soybean Soybean_901
soybean Soybean_902
soybean Soybean_903
soybean Soybean_904
soybean Soybean_905
soybean Soybean_906
soybean Soybean_VanHeemst_1988
sugarbeet Sugarbeet_601
sugarbeet Sugarbeet_602
sugarbeet Sugarbeet_603
sugarbeet Sugarbeet_604
sugarcane Sugarcane_VanHeemst_1988
sunflower Sunflower_1101
sweetpotato Sweetpotato_VanHeemst_1988
tobacco Tobacco_VanHeemst_1988
wheat Winter_wheat_101
wheat Winter_wheat_102
wheat Winter_wheat_103
wheat Winter_wheat_104
wheat Winter_wheat_105
wheat Winter_wheat_106
wheat Winter_wheat_107