Ecocrop¶
Introduction¶
Chapter requirements¶
We use R packages ecocrop
and geodata
. See these
installation instructions.
Ecocrop¶
Run the model¶
As in the previous chapter, we use climate data for Senegal from WorldClim data to find .
library(geodata)
rain <- geodata::worldclim_country("Senegal", var="prec", path=".")
tavg <- geodata::worldclim_country("Senegal", var="tavg", path=".")
adm <- geodata::gadm("Senegal", level=1, path=".")
rain <- mask(rain, adm)
tavg <- mask(tavg, adm)
Create an ecocrop model for maize
library(Recocrop)
## Warning: package 'Recocrop' was built under R version 4.3.1
crop <- Recocrop::ecocropPars("maize")
m <- Recocrop::ecocrop(crop)
Use the model to make predictions for Senegal
plant <- predict(m, prec=rain, tavg=tavg)
p <- classify(plant > 0, cbind(0,NA)) * 1:12
pm <- median(p, na.rm=TRUE)
hv <- pm + m$duration
hv <- ifel(hv > 12, hv - 12, hv)
plot(hv)
lines(adm)
Or like this
control(m, which_max=TRUE)
mplant <- predict(m, prec=rain, tavg=tavg)
mhv <- mplant + m$duration
mhv <- ifel(mhv > 12, mhv - 12, mhv)
plot(mhv)
lines(adm)