-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulation_demo.py
47 lines (37 loc) · 938 Bytes
/
simulation_demo.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
# Copyright (c) 2023 Cortext
# %%
from crop_model import CropParameters, Crop
import numpy as np
import pandas as pd
import plotly.express as px
# %%
tomato_sunnySD = CropParameters(
T_sum=2800,
HI=0.68,
I_50A=520,
I_50B=400,
T_base=6,
T_opt=26,
RUE=1.00,
I_50maxH=100,
I_50maxW=5,
T_heat=32,
T_ext=45,
S_CO2=0.07,
S_water=2.5,
)
crop = Crop(tomato_sunnySD)
def simulate(crop, days=365):
for _ in range(days):
x = {
"radiation": np.random.randint(0, 10),
"T_mean": np.random.randint(5, 20),
"CO2": np.random.randint(400, 500),
"ARID": np.random.uniform(0, 1) ** 3,
}
x["T_max"] = x["T_mean"] + np.random.randint(0, 10)
crop.next_day(**x)
yield {"day": crop.i, **x, "biomass": crop.biomass}
df = pd.DataFrame([d for d in simulate(crop)]).set_index("day")
px.line(df, y="biomass")
# %%