Intercrop calculation#

This a simulation workflow example to calculate the surfacic density of energy absorbed Eabs (m-2) or the surfacic density of energy incoming Ei (m-2).

Workflow:

  1. Select brassica variety aviso or vigo associated with legume

  2. Read climate file, set the sowing dates, set mean temperature data for each species

  3. Read Total Leaf Area data (TLA) from file

  4. Read parameters based on option (default or specific to an experimental treatment)

  5. run simulation over the whole clim data

  6. Display 3D (openalea.widgets need to be installed)

[1]:
import sys
import pandas

from pathlib import Path

from openalea.colzette.colzette import compute_thermal_time, get_params_intercrop
from openalea.colzette.simulation import run_static_mixture_simulation
from openalea.colzette.data import data_dir

Define identifiers for simulation#

Select brassica variety aviso or vigo associated with legume

[2]:
Type_simul = 'intercrop_vigo' # 'intercrop_aviso_RRF', 'intercrop_vigo'
if Type_simul == "intercrop_aviso_RRF":
    Type_brassica = "intercrop_aviso_RRF"
    Type_legume = "intercrop_faba_aviso_RRF"
else:
    Type_brassica = "intercrop_vigo"
    Type_legume = "intercrop_faba_vigo"

species_brassica = "Rapeseed"
species_legume = "Fababean"
fname = data_dir / 'parameters' / 'type_params_fababean.csv'
df_par_legume = pandas.read_csv(fname,sep='\t')
fname = data_dir / 'parameters' / 'type_params_rapeseed.csv'
df_par_brassica = pandas.read_csv(fname,sep='\t')

Read climate file for the chosen simulation site#

set the sowing dates, set mean temperature data for each species

[3]:
meteo_fn = data_dir / 'climate' / 'IDEEV_2023_INRAE_STATION_91272001.csv'
clim= pandas.read_csv(meteo_fn,sep=";",skiprows=11)
clim['TM'] = (clim['TN'] + clim['TX'])/2

brassica = 0
Tb_legume = 0
idx_brassica = clim.index[
    (clim["AN"] == 2023) &
    (clim["MOIS"] == 9) &
    (clim["JOUR"] == 14)][0] # brassica sowing date 14/09/2023
idx_legume = clim.index[
    (clim["AN"] == 2023) &
    (clim["MOIS"] == 9) &
    (clim["JOUR"] == 20)][0] # legume sowing date 14/09/2023
clim2 = clim.iloc[idx_brassica:]
clim2['TT_brassica'] = compute_thermal_time(vec_temp=clim2['TM'], idx_begin=0, Tb=brassica)
clim2['TT_legume'] = compute_thermal_time(vec_temp=clim2['TM'], idx_begin=idx_legume-1, Tb=Tb_legume)

Read Total Leaf Area data (TLA) for the chosen simulation site#

[4]:
TLA_fn = data_dir / 'input_leaf_surface' / 'set_TLA_IDEEV.csv'
TLA_all = pandas.read_csv(TLA_fn,sep="\t")
TLA_indices_keep_brassica = TLA_all[TLA_all['Type']==Type_brassica].index
vec_TLA_brassica = TLA_all['sim'].values[TLA_indices_keep_brassica]
TLA_indices_keep_legume = TLA_all[TLA_all['Type']==Type_legume].index
vec_TLA_legume = TLA_all['sim'].values[TLA_indices_keep_legume]

Read parameters based on option (default or specific to an experimental treatment)#

[5]:
dict_params = get_params_intercrop(species_brassica, species_legume, df_par_brassica, df_par_legume, "One simulation")
density=48.0
option_plants = 'plot' # 'plot' or 'single' i.e. crop or one plant

run simulation over the whole clim data#

[6]:
dfs = []
list_scene = []
list_cs = []
list_raw = []
list_agg = []

for iday in range(0,len(clim2)):

    # just to display running activity
    sys.stdout.write('\r')
    sys.stdout.write(f'{iday/(len(clim2)-1)*100:.0f}' + '%')  # pad to overwrite leftovers
    sys.stdout.flush()

    PlantAge_brassica = clim2.iloc[iday]['TT_brassica']
    PlantAge_legume = clim2.iloc[iday]['TT_legume']
    RG_daily = clim2.iloc[iday]['PAR'] * 100.0 # in J.cm-2 must be J.m-2
    TLA_brassica = vec_TLA_brassica[iday]
    TLA_legume = vec_TLA_legume[iday]
    scene, caribu_scene, sub_dat, raw, agg = run_static_mixture_simulation(iday,
                                  RG_daily,
                                   density,
                                   dict_params,
                                   TLA_brassica,
                                   TLA_legume,
                                   PlantAge_brassica,
                                   PlantAge_legume,
                                   Type_simul=Type_simul, ustride=9, vstride=2, light_direction=(0,0,-1))
    dfs.append(sub_dat)
    list_scene.append(scene)
    list_cs.append(caribu_scene)
    list_raw.append(raw)
    list_agg.append(agg)

res = pandas.concat(dfs,ignore_index=True)
100%

Write results to a file

[7]:
res.to_csv(f'res_Eabs_{Type_simul}.csv')

Display 3D#

openalea.widgets need to be installed

In the second cell below the day after sowing can be changed to visualize the crop at different age.

[8]:
from openalea.widgets.plantgl import PlantGL
[9]:
das = len(clim2) - 1 # day after sowing to display

prop = list_agg[das]['Eabs'] # propertie to display: 'Eabs' surfacic absorbed energy or 'Ei' incident energy, list_agg aggregated value entire leaf, list_raw per triangle

scene, values = list_cs[das].plot(prop, display = False)

[10]:
PlantGL(scene)
[10]:
[ ]: