Appropriation of the STICS model
2024-12-19
Packages
Functions
Getting parameters values from XML files
#For one parameter and one occurrence
# Fixing files paths
sols <- file.path(workspace, "sols.xml")
par_gen <- file.path(workspace, "param_gen.xml")
station <- file.path(workspace, "climatex_sta.xml")
# A option parameter
get_param_xml(par_gen, param = "codeactimulch")
# A simple parameter
get_param_xml(station, param = "concrr")
# Using a conditional selection
get_param_xml(sols, param = "argi", select = "sol", select_value = "solcanne")
Getting variables informations
# get_var_info(var = "msrac_n")
# get_var_info(var = "masec_n")
# get_var_info(var = "totir")
# get_var_info(var = "totapN")
# get_var_info(var = c("inn", "inn1moy","inn2moy"))
# get_var_info(var = "totapN")
# get_var_info(var = "turfac")
# get_var_info(var = "inn")
# get_var_info(var = "leaching_from_lev")
# get_var_info(var = "N_volatilisation")
Simulation of the actual yields of the pea crops:
See the input Excel file : _inputs_stics_pea.xlsx.
Getting data
Genarating the usms.xml file
The usms.xml
file content
Focus of the first usm
parameters:
## <?xml version="1.0" encoding="UTF-8" standalone="no"?>
## <usms version="10.1.0">
## <usm nom="baccara_PP">
## <datedebut>61</datedebut>
## <datefin>201</datefin>
## <finit>ACBB_Mons_T5_ini.xml</finit>
## <nomsol>ACBB_Mons_T5</nomsol>
## <fstation>ACBB_Mons_sta.xml</fstation>
## <fclim1>ACBB_Mons.2010</fclim1>
## <fclim2>ACBB_Mons.2010</fclim2>
## <culturean>1</culturean>
## <nbplantes>1</nbplantes>
## <codesimul>0</codesimul>
## <plante dominance="1">
## <fplt>pea_v10_plt.xml</fplt>
## <ftec>baccara_PP_tec.xml</ftec>
## <flai>null</flai>
## <fobs>03_T5_2010_b1.obs</fobs>
## </plante>
## <plante dominance="2">
## <fplt>null</fplt>
## <ftec>null</ftec>
## <flai>null</flai>
## <fobs>null</fobs>
## ...
## </usms>
Getting data
Generating multiple initialization files (*_ini.xml)
Focus of a ini
parameters file content sub-list:
## <?xml version="1.0" encoding="UTF-8"?>
## <initialisations version="10.1.0">
## <nbplantes>1</nbplantes>
## <plante dominance="1">
## <stade0>snu</stade0>
## <lai0>0</lai0>
## <magrain0>0</magrain0>
## <zrac0>0</zrac0>
## <option choix="2" nom="Simulation of Nitrogen and Carbon reserves" nomParam="code_acti_reserve">
## <choix code="1" nom="yes">
## <maperenne0>0</maperenne0>
## <QNperenne0>0</QNperenne0>
## <masecnp0>0</masecnp0>
## <QNplantenp0>0</QNplantenp0>
## </choix>
## <choix code="2" nom="no">
## <masec0>0</masec0>
## <QNplante0>0</QNplante0>
## <restemp0>0</restemp0>
## ...
## </initialisations>
Getting data
Genarating the soils.xml file
# Verification
path_ref = "/home/ardiallo/Bureau/PhD_l/STICS/JavaSTICS-1.5.2-STICS-10.2.0/stics_mod/example_pw"
df_ref = get_param_xml(file.path(path_ref, "sols.xml"))[[1]]
df = get_param_xml(file.path(workspace, "sols.xml"))[[1]]
df_ref = data.frame(df_ref)
df = data.frame(df)
all(names(df)==names(df_ref))
The sols.xml
file content:
Focus of the first sol
parameters sub-list:
## <?xml version="1.0" encoding="UTF-8"?>
## <sols version="10.1.0">
## <sol nom="ACBB_Mons_T5">
## <param format="real" max="60.0" min="0.0" nom="argi">17</param>
## <param format="real" max="0.5" min="0.05" nom="norg">0.105</param>
## <param format="real" max="60.0" min="10.0" nom="profhum">35</param>
## <param format="real" max="100.0" min="0.0" nom="calc">0.53</param>
## <param format="real" max="9.0" min="4.0" nom="pH">8.25</param>
## <param format="real" max="0.5" min="0.0" nom="concseuil">0</param>
## <param format="real" max="0.6" min="0.05" nom="albedo">0.22</param>
## <param format="real" max="50.0" min="0.0" nom="q0">9.36</param>
## <param format="real" max="1.0" min="0.0" nom="ruisolnu">0</param>
## <param format="real" max="1000.0" min="10.0" nom="obstarac">210</param>
## <param format="real" max="100.0" min="5.0" nom="pluiebat">50</param>
## <param format="real" max="2.0" min="0.0" nom="mulchbat">1.5</param>
## <param format="real" max="150.0" min="10.0" nom="zesx">60</param>
## <param format="real" max="10.0" min="-10.0" nom="cfes">4</param>
## <param format="real" max="0.2" min="0.01" nom="z0solnu">0.01</param>
## <param format="real" max="20.0" min="8.0" nom="CsurNsol">9.46</param>
## <param nom="finert">0.65</param>
## <param format="real" max="5.0" min="0.0" nom="penterui">0.33</param>
## <option choix="2" nom="pebbles" nomParam="codecailloux">
## <choix code="1" nom="yes"/>
## <choix code="2" nom="no"/>
## </option>
## <option choix="2" nom="macroporosity" nomParam="codemacropor">
## <choix code="1" nom="yes"/>
## <choix code="2" nom="no"/>
## </option>
## <option choix="2" nom="cracks (case of swelling clay soils)" nomParam="codefente">
## ...
## </tableau>
## ...
## </sols>
Getting data
Generating the crop management files (*_tec.xml)
Focus of a tec
parameters file content sub-list:
## <?xml version="1.0" encoding="UTF-8" standalone="no"?>
## <fichiertec version="10.1.0">
## <formalisme nom="supply of organic residus">
## <ta nb_interventions="0" nom="interventions">
## <ta_entete nb_colonnes="7">
## <colonne nom="julres"/>
## <colonne nom="coderes"/>
## <colonne nom="qres"/>
## <colonne nom="Crespc"/>
## <colonne nom="CsurNres"/>
## <colonne nom="Nminres"/>
## <colonne nom="eaures"/>
## </ta_entete>
## </ta>
## </formalisme>
## <formalisme nom="soil tillage">
## <option choix="1" nom="Automatic calculation of the depth of residues incorporation in function of proftrav" nomParam="code_auto_profres">
## <choix code="1" nom="yes">
## <param format="real" max="0.0" min="1.0" nom="resk">0.14</param>
## <param format="real" max="0.0" min="10.0" nom="resz">5</param>
## </choix>
## <choix code="2" nom="no"/>
## </option>
## <ta nb_interventions="1" nom="interventions">
## <ta_entete nb_colonnes="3">
## <colonne nom="jultrav"/>
## <colonne nom="profres"/>
## <colonne nom="proftrav"/>
## </ta_entete>
## <intervention nb_colonnes="3">
## ...
## </fichiertec>
** Cultivars**
# Read from a plant file (all cultivars available in a plant file)
get_cultivars_list(file = file.path(workspace,"plant", "pea_plt.xml"))
## [1] "baccara"
df = get_cultivars_param(file = file.path(workspace,"plant", "pea_plt.xml"))
tags$div(
tags$h3("Cultivars list"),
DT::datatable(df, options = list(pageLength = 5))
)
Getting data
Generating multiple meteorological station XML files (*_sta.xml)
# Verification
path_ref = "/home/ardiallo/Bureau/PhD_l/STICS/JavaSTICS-1.5.2-STICS-10.2.0/stics_mod/example_pw"
df_ref = get_param_xml(file.path(path_ref, "SUCS_sta.xml"))[[1]]
df = get_param_xml(file.path(workspace, "ACBB_Mons_sta.xml"))[[1]]
df_ref = data.frame(df_ref)
df = data.frame(df)
all(names(df)==names(df_ref))
get_param_xml(file.path(path_ref, "SUCS_sta.xml"), param = "concrr")
get_param_xml(file.path(workspace, "ACBB_Mons_sta.xml"), param = "concrr")
Focus of a sta
parameters file content sub-list:
## <?xml version="1.0" encoding="UTF-8" standalone="no"?>
## <fichiersta version="10.1.0">
## <formalisme nom="Weather station">
## <param format="real" max="10.0" min="2.0" nom="zr">2.5</param>
## <param format="real" max="10.0" min="0.0" nom="NH3ref">0</param>
## <param format="real" max="3.0" min="0.0" nom="concrr">0.02</param>
## <param format="real" max="90.0" min="-90.0" nom="latitude">49</param>
## <param format="real" max="1200.0" min="800.0" nom="patm">1000</param>
## <param format="real" max="25.0" min="4.0" nom="aclim">12.6115643657415</param>
## </formalisme>
## <formalisme nom="climate">
## <option choix="1" nom="reading OR calculation of PET" nomParam="codeetp">
## <choix code="1" nom="PET-Penman_reading"/>
## <choix code="2" nom="PET-Penman_calculation"/>
## <choix code="3" nom="PET-Shuttleworth-Wallace_calculation"/>
## <choix code="4" nom="PET-Priestley-Taylor_calculation">
## <param format="real" max="2.0" min="1.0" nom="alphapt">1.26</param>
## </choix>
## </option>
## <option choix="1" nom="climate change" nomParam="codeclichange">
## <choix code="1" nom="no"/>
## <choix code="2" nom="yes"/>
## </option>
## <option choix="1" nom="climate in altitude" nomParam="codaltitude">
## <choix code="1" nom="no"/>
## <choix code="2" nom="yes">
## <param format="real" max="2000.0" min="0.0" nom="altistation">0</param>
## <param format="real" max="2000.0" min="0.0" nom="altisimul">0</param>
## <param format="real" max="3.0" min="0.1" nom="gradtn">-0.5</param>
## <param format="real" max="3.0" min="0.1" nom="gradtx">-0.55</param>
## <param format="real" max="2000.0" min="0.0" nom="altinversion">500</param>
## <param format="real" max="3.0" min="0.1" nom="gradtninv">1.3</param>
## <param format="real" max="1.0" min="0.0" nom="cielclair">0.8</param>
## <option choix="1" nom="option.adret.or.ubac" nomParam="codadret">
## <choix code="1" nom="adret(south)"/>
## <choix code="2" nom="ubac(north)">
## <param format="real" max="5.0" min="-5.0" nom="ombragetx">-1.4</param>
## </choix>
## </option>
## </choix>
## </option>
## ...
## </fichiersta>
NOT OK : To be done manually on JavaSTICS
Getting data
Getting data
Generating the observations files (*_obs.xml)
## get the list of USMs
usm_list <- get_usms_list(file = file.path(workspace,"usms.xml"))
#### run the USMs
## define the model options
model_options <- stics_wrapper_options(javastics = javastics,
workspace = txt_dir,
parallel = TRUE)
## run the USMs as they are defined
res <- stics_wrapper(model_options = model_options, var=output)
res_df = CroPlotR::bind_rows(res$sim_list)
# names(res_df)
# head(res_df)
# tail(res_df)
#
##
## $baccara_PP
# plot(ori=res$sim_list,var=c("inn1moy","turfac1moy"))
# p <- plot(res$sim_list, overlap = list(list("mafruit","masec_n"),
# list("turfac1moy","inn1moy")),
# var = c("mafruit","masec_n", "inn1moy","turfac1moy"))
# p
# plot(res$sim_list,successive = list(usm_list))
# ggsave(file.path(eval_dir,"dyn.png"), width=30, units="cm")
A suivre !