Currently planting_date is set in two places in model.py. I played around with removing it from init but that didn't seem right. Additionally, as-is model.py has some problems:
The model seems happy when you set the planting date as 75 (example 1) but unhappy when planting date is 2 (example 2) or 200 (example 3), for example.
It looks like the model always ends on day 208, this should change depending on the planting date.
Here's the code I was playing with:
Start by importing packages and objects
# import packages and set working directory
import numpy as np
import matplotlib.pyplot as plt
import os
from math import exp
import pandas as pd
import sys
# We need to add the module path to our system path so
# so that our notebook can find our local objects and code:
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
sys.path.append(module_path)
# import objects
from farm import Climate
from farm import Soil
from farm import Crop
from farm import CropModel
from farm.make_climate_parameters import make_climate_parameters
Example 1
alpha_r, lambda_r = make_climate_parameters()
climate = Climate(alpha_r, lambda_r)
soil = Soil('loam')
crop = Crop(soil=soil)
soil.set_nZr(crop)
model = CropModel(crop=crop,soil=soil,climate=climate)
model.run(planting_date=75)
o = model.output()
o['kc'].plot()
o
Here the DOY starts on Julian day 54. This makes sense given the calculation: planting date (75) - t_before (21). The model is ending on day 208 (zero-indexed) whereas it should end on day 262 (calculated by doy_end = 75 + 180 + 7).
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-2-9a2956d9a135> in <module>
7 model = CropModel(crop=crop,soil=soil,climate=climate)
8
----> 9 model.run(planting_date=2)
10
11 o = model.output()
~/Box Sync/waves/maize-Toff/farm/model.py in run(self, s0, planting_date, t_before, t_after)
123
124 for t in range(self.n_days):
--> 125 self.R[t] = self.climate.rainfall[doy[t]-1]
126
127 self.doy = doy
IndexError: index 0 is out of bounds for axis 0 with size 0
Example 3
alpha_r, lambda_r = make_climate_parameters()
climate = Climate(alpha_r, lambda_r)
soil = Soil('loam')
crop = Crop(soil=soil)
soil.set_nZr(crop)
model = CropModel(crop=crop,soil=soil,climate=climate)
model.run(planting_date=200)
o = model.output()
o['kc'].plot()
o
Here it looks like the plant never starts to grow. dos never switches to "1" and we can see that the crop coefficient is always 0.3.
Currently
planting_date
is set in two places inmodel.py
. I played around with removing it from init but that didn't seem right. Additionally, as-ismodel.py
has some problems:Here's the code I was playing with:
Start by importing packages and objects
Example 1
Here the DOY starts on Julian day 54. This makes sense given the calculation: planting date (75) - t_before (21). The model is ending on day 208 (zero-indexed) whereas it should end on day 262 (calculated by doy_end = 75 + 180 + 7).
Example 2
Get the error:
Example 3
Here it looks like the plant never starts to grow.
dos
never switches to "1" and we can see that the crop coefficient is always 0.3.