Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions example/EpyMix with Septoria.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
Expand All @@ -558,7 +558,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.9.2"
}
},
"nbformat": 4,
Expand Down
306 changes: 306 additions & 0 deletions example/app_epymix.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b50cd883",
"metadata": {},
"source": [
"# Jupyter App"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "e05e4afa",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"import ipywidgets\n",
"\n",
"from epymix.rain import rain as _rain \n",
"from epymix.inoculum import inoculum \n",
"from epymix.configuration import configuration\n",
"from epymix.SEIR import SEIR \n",
"from epymix.dispersion_gradient import dispersion_kernel_rust, dispersion_kernel_septo\n",
"from epymix.growth_companion import growth_pois\n",
"from epymix.SEIR_practices_data import SEIR_practice\n",
"from epymix.app_parameter_generator import parameter_set"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "51d30dca",
"metadata": {},
"outputs": [],
"source": [
"#disease_par='septo_par'\n",
"delta_t0 = 10 # constant, the model has been parameterise such as t = 10 degree-day\n",
"delta_t = 10 # time step\n",
"n_season = 1 # number of season\n",
"season = 250*int(delta_t0/delta_t) # 2500 dd %% length of a cropping season\n",
"delta_companion = 0 # growth start lag of the companion crop (dd), negative: companion before, positive: companion after but for i<delta Poi=0\n",
"\n",
"Lr=1 # Lr: number of seasons\n",
"Lx=1 # Lx: number of patch along the x-axis\n",
"Ly=1 # Ly: number of patch along the y-axis\n",
"scenario_rot='uniform' # scenario_rot: rotation scenario (chose: uniform, random, chessboard, alternate, alternate_rank, etc)\n",
"wheat_fraction=0.5 # wheat_fraction: wheat fraction within each patch"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "6006cef7",
"metadata": {},
"outputs": [],
"source": [
"mu_wheat = 0.03 * delta_t / delta_t0 # 0.03 %% mortality rate of S and E tissues (LAI/10dd)\n",
"nu = 0.03 * delta_t / delta_t0 # nu = mu %% mortality of I infectious tissues (LAI/10dd)\n",
"mu_companion = 0.03 * delta_t / delta_t0 # 0.03 %% mortality rate of the companion species (LAI/10dd)\n",
"beta_wheat = 0.09 * delta_t / delta_t0 # 0.09 %% wheat growth parameter (LAI/10dd)\n",
"beta_companion = 0.09 * delta_t / delta_t0 # beta_companion = beta_wheat %% growth parameter of the companion crop (LAI/10dd)\n",
"end_wheat = 140 * int(delta_t0 / delta_t) # 1400 dj %% date of wheat growth end\n",
"end_companion = 140 * int(delta_t0 / delta_t) # end_companion = end_wheat %% date of growth end for the companion crop\n",
"LAI_K = 6 # 6 %% carrying capacity (Maximum canopy LAI)\n",
"ber_wheat = 1 # 1 # wheat spore interception coefficient (the Beer-Lambert law)\n",
"ber_companion = 1 # 1 # spore interception coefficient of the companion species (the Beer-Lambert law)\n",
"h_wheat = 1 # wheat height\n",
"h_companion = 1 # companion height"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "bceb8777",
"metadata": {},
"outputs": [],
"source": [
"year=2000"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cdb4ac11",
"metadata": {},
"outputs": [],
"source": [
"scenario_ino = 'initial_inoculum' # scenario_ino: which scenario of initial inoculum (chose: central_focus, initial_inoculum, annual_cloud)\n",
"frac_inf = 1 # frac_inf: fraction of patches within the field inoculated"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "92d65c0e",
"metadata": {},
"outputs": [],
"source": [
"### PARAMETERS IN CASE OF PRACTICE DATA\n",
"data_lai_wheat = pd.read_csv('spline_coordinate_inc_wheat_10.csv', sep=';')\n",
"data_lai_comp = pd.read_csv('spline_coordinate_inc_comp_10.csv', sep=';')\n",
"data_lai_wheat_mu = pd.read_csv('spline_coordinate_coef_wheat_10.csv', sep=';')\n",
"experiment = 5"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1ae20eb4",
"metadata": {},
"outputs": [],
"source": [
"# def app(crop='pure crop', disease_par='septo_par', year='2000', wheat_fraction=0.5, delta_companion = 0, view='LAIwheat'):\n",
"def app(crop='pure crop', disease_par='septo_par', experiment=5, year=2000, wheat_fraction=0.5, delta_companion = 0):\n",
" disease, delta_ei, lambd, s0, pi_inf0, rho, psi, gamma, theta, sigma, sigma_asco, inf_begin, inoc_init_abs, ng_ext0_abs, day_length, alpha_asco, radius_asco, alpha_pycnid, radius_pycnid, alpha_ure, radius_ure = parameter_set(disease_par=disease_par, delta_t0=delta_t0, delta_t=delta_t)\n",
"\n",
" arrangement = configuration(Lr, Lx, Ly, scenario_rot, wheat_fraction)\n",
" arrangement_max = configuration(Lr, Lx, Ly, scenario_rot, wheat_fraction=1)\n",
"\n",
" rain = _rain(year, n_season, delta_t)\n",
" \n",
" inoc_init, ng_ext0 = inoculum(scenario_ino, Lx, Ly, frac_inf, inoc_init_abs, ng_ext0_abs)\n",
" \n",
" kernel_asco, C_Disp_asco, kernel_pycnid, C_Disp_pycnid = dispersion_kernel_septo(day_length, alpha_asco, radius_asco, alpha_pycnid, radius_pycnid)\n",
" kernel_ure, C_Disp_ure = dispersion_kernel_rust(day_length, alpha_ure, radius_ure)\n",
" \n",
" if crop == 'pure crop':\n",
" t = n_season*250*int(delta_t0/delta_t) # length of the experiment\n",
" \n",
" Pth_inde, Poi_inde = growth_pois(t=t, season=season, arrangement=arrangement,\n",
" mu_companion=mu_companion, beta_companion=beta_companion, end_companion=end_companion, LAI_K=LAI_K)\n",
"\n",
" Nsp, Pth, Poi, Sth, Sus, Lat, Ifc, Ifv, Rem, LAI, LAI_wheat, Poo, Eps, AUDPC, Scont = SEIR(\n",
" t=t, \n",
" delta_t0=delta_t0, delta_t=delta_t, \n",
" season=season, delta_companion=delta_companion,\n",
" disease=disease, rain=rain, arrangement=arrangement, inoc_init=inoc_init, ng_ext0=ng_ext0,\n",
" mu_wheat=mu_wheat, nu=nu, beta_wheat=beta_wheat, #beta_companion=beta_companion, end_companion=end_companion\n",
" end_wheat=end_wheat, LAI_K=LAI_K, ber_wheat=ber_wheat, ber_companion=ber_companion, Pth_inde=Pth_inde, Poi_inde=Poi_inde,\n",
" h_wheat=h_wheat, h_companion=h_companion,\n",
" lambd=lambd, delta_ei=delta_ei,\n",
" s0=s0,pi_inf0=pi_inf0, rho=rho, psi=psi, gamma=gamma, theta=theta, sigma=sigma, sigma_asco=sigma_asco, inf_begin=inf_begin,\n",
" C_Disp_ure=C_Disp_ure, kernel_ure=kernel_ure, C_Disp_asco=C_Disp_asco, kernel_asco=kernel_asco,\n",
" C_Disp_pycnid=C_Disp_pycnid, kernel_pycnid=kernel_pycnid)\n",
"\n",
" Nsp2, Pth2, Poi2, Sth2, Sus2, Lat2, Ifc2, Ifv2, Rem2, LAI2, LAI_wheat2, Poo2, Eps2, AUDPC2, Scont2 = SEIR(\n",
" t=t, \n",
" delta_t0=delta_t0, delta_t=delta_t, \n",
" season=season, delta_companion=delta_companion,\n",
" disease=disease, rain=rain, arrangement=arrangement_max, inoc_init=inoc_init, ng_ext0=ng_ext0,\n",
" mu_wheat=mu_wheat, nu=nu, beta_wheat=beta_wheat, #beta_companion=beta_companion, end_companion=end_companion\n",
" end_wheat=end_wheat, LAI_K=LAI_K, ber_wheat=ber_wheat, ber_companion=ber_companion, Pth_inde=Pth_inde, Poi_inde=Poi_inde,\n",
" h_wheat=h_wheat, h_companion=h_companion,\n",
" lambd=lambd, delta_ei=delta_ei,\n",
" s0=s0,pi_inf0=pi_inf0, rho=rho, psi=psi, gamma=gamma, theta=theta, sigma=sigma, sigma_asco=sigma_asco, inf_begin=inf_begin,\n",
" C_Disp_ure=C_Disp_ure, kernel_ure=kernel_ure, C_Disp_asco=C_Disp_asco, kernel_asco=kernel_asco,\n",
" C_Disp_pycnid=C_Disp_pycnid, kernel_pycnid=kernel_pycnid)\n",
"\n",
" elif crop == 'intercropping':\n",
" data_lai_wheat.columns.values[experiment]\n",
" lai_wheat_inc = np.array(data_lai_wheat.iloc[:, experiment])\n",
" lai_comp_inc = np.array(data_lai_comp.iloc[:, experiment])\n",
" lai_wheat_mu = np.array(data_lai_wheat_mu.iloc[:, experiment])\n",
" t = sum(~np.isnan(lai_comp_inc))\n",
" Nsp, Pth, Poi, Sth, Sus, Lat, Ifc, Ifv, Rem, LAI, LAI_wheat, Poo, Eps, AUDPC, Scont = \\\n",
" SEIR_practice(t=t , delta_t0=delta_t0, delta_t=delta_t, season=season,\n",
" disease=disease, rain=rain, arrangement=arrangement, inoc_init=inoc_init, ng_ext0=ng_ext0,\n",
" lai_wheat_inc=lai_wheat_inc, lai_comp_inc=lai_comp_inc, lai_wheat_mu=lai_wheat_mu,\n",
" nu=nu, ber_wheat=ber_wheat, ber_companion=ber_companion, h_wheat=h_wheat, h_companion=h_companion,\n",
" lambd=lambd, delta_ei=delta_ei,\n",
" s0=s0,pi_inf0=pi_inf0, rho=rho, psi=psi, gamma=gamma, theta=theta, sigma=sigma, sigma_asco=sigma_asco, inf_begin=inf_begin,\n",
" C_Disp_ure=C_Disp_ure, kernel_ure=kernel_ure, C_Disp_asco=C_Disp_asco, kernel_asco=kernel_asco,\n",
" C_Disp_pycnid=C_Disp_pycnid, kernel_pycnid=kernel_pycnid)\n",
"\n",
" lai_comp_inc = np.array(data_lai_comp.iloc[:, experiment])*0\n",
" Nsp2, Pth2, Poi2, Sth2, Sus2, Lat2, Ifc2, Ifv2, Rem2, LAI2, LAI_wheat2, Poo2, Eps2, AUDPC2, Scont2 = \\\n",
" SEIR_practice(t=t , delta_t0=delta_t0, delta_t=delta_t, season=season,\n",
" disease=disease, rain=rain, arrangement=arrangement, inoc_init=inoc_init, ng_ext0=ng_ext0,\n",
" lai_wheat_inc=lai_wheat_inc, lai_comp_inc=lai_comp_inc, lai_wheat_mu=lai_wheat_mu,\n",
" nu=nu, ber_wheat=ber_wheat, ber_companion=ber_companion, h_wheat=h_wheat, h_companion=h_companion,\n",
" lambd=lambd, delta_ei=delta_ei,\n",
" s0=s0,pi_inf0=pi_inf0, rho=rho, psi=psi, gamma=gamma, theta=theta, sigma=sigma, sigma_asco=sigma_asco, inf_begin=inf_begin,\n",
" C_Disp_ure=C_Disp_ure, kernel_ure=kernel_ure, C_Disp_asco=C_Disp_asco, kernel_asco=kernel_asco,\n",
" C_Disp_pycnid=C_Disp_pycnid, kernel_pycnid=kernel_pycnid)\n",
"\n",
" \n",
" T = [*range(0,t)]\n",
" Sth = np.mean(Sth, axis=(1,2))\n",
" Pth = np.mean(Pth, axis=(1,2))\n",
" Poi = np.mean(Poi, axis=(1,2))\n",
" Lat = np.mean(Lat, axis=(1,2))\n",
" Ifc = np.mean(Ifc, axis=(1,2))\n",
" Ifv = np.mean(Ifv, axis=(1,2))\n",
" Sus = np.mean(Sus, axis=(1,2))\n",
" Rem = np.mean(Rem, axis=(1,2))\n",
" Nsp = np.mean(Nsp, axis=(1,2))\n",
" LAI = np.mean(LAI, axis=(1,2))\n",
" LAI_wheat = np.mean(LAI_wheat, axis=(1,2))\n",
" Poo = np.mean(Poo, axis=(1,2))\n",
" AUDPC = np.mean(AUDPC, axis=(1,2))\n",
" Eps = np.mean(Eps, axis=(1,2))\n",
" Scont = np.mean(Scont, axis=(1,2))\n",
" \n",
" # if view == 'LAIwheat':\n",
" # plt.plot(T, Sth, color='black')\n",
" # plt.ylim([0, 6])\n",
" # elif view=='Desease':\n",
" # plt.plot(T, Ifc, color='red')\n",
" # plt.ylim([0, 6])\n",
" # elif view=='All':\n",
" plt.plot(T, Sth, color='black')\n",
" plt.plot(T, Sus, color='green')\n",
" plt.plot(T, Poi, color='brown')\n",
" plt.plot(T, Ifv, color='red')\n",
" plt.ylim([0, 6])\n",
" plt.xlabel(\"Degrés-jour (joursx10 par °C)\")\n",
" plt.ylabel(\"Surface foliaire (m² par m² de sol\")\n",
" plt.plot(T, Sth, \"black\", label=\"Blé sans maladie\")\n",
" plt.plot(T, Sus, \"green\", label=\"Blé avec maladie\")\n",
" plt.plot(T, Poi, \"brown\", label=\"Compagne\")\n",
" plt.plot(T, Ifv, \"red\", label=\"Maladie cumulée\")\n",
" plt.legend(loc=\"upper left\")\n",
" # plt.ylabel(\"LAI\")\n",
"\n",
" \n",
" print(f'AUDPC: {\"{:.2f}\".format(AUDPC[-1])}')\n",
" print(f'Réduction de la maladie: {\"{:.2f}\".format(float(1-AUDPC[-1]/AUDPC2[-1]))}%')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "533d9549",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5219427c73bf494ca097101a446bb8e1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(Dropdown(description='crop', options=('pure crop', 'intercropping'), value='pure crop'),…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": [
"<function __main__.app(crop='pure crop', disease_par='septo_par', experiment=5, year=2000, wheat_fraction=0.5, delta_companion=0)>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ipywidgets.interact(app, crop=['pure crop', 'intercropping'], experiment=[('fababean_N0',61),('fababean_N1',63),('pea_N0',13),('pea_N1',14)], disease_par=['septo_par', 'rust_par'], year=list(range(1993, 2016)), wheat_fraction=(0,1,0.05), \n",
"delta_companion=(-100,100,1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d0d90ec",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "epyland",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.2"
},
"vscode": {
"interpreter": {
"hash": "cc495b77a574b98b57b7f5732d92c368da0bdafbfc1ca32d8caf81cd26f9b127"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading