Introduction

The goal of SticsRFiles is to perform manipulations of all types of files related to the input and outputs of the STICS model.

This article presents the design of the package and its basic features, i.e. the main functions to deal with the XML files. For a complete introduction to SticsRPacks (managing files, running simulations, plotting, optimization…), see the tutorial from the SticsRPacks package.

Concepts

Input files

Text files

The executable of the STICS model reads text files with standard names and format to import the inputs describing a single unit of simulation (USM), e.g. one crop for one year.

Here’s a typical list of the input files for the STICS executable (without the optional files):

workspace

├── 📜climat.txt               # The meteorological data for the USM
├── 📜ficini.txt               # The initialization
├── 📜ficplt1.txt              # Parameters for the plant to be simulated
├── 📜fictec1.txt              # The management applied to the soil and crop
├── 📜new_travail.usm          # The general configuration parameters for the USM
├── 📜param.sol                # Soil parameters
├── 📜station.txt              # The site parameters (*e.g.* altitude, latitude)
├── 📜tempopar.sti             # More general parameters not in the other files
├── 📜tempoparv6.sti           # Parameters for the custom versions of STICS
└── 📜var.mod                  # Variables to write in the outputs

Because these files only describe one USM at a time and can be tedious to explore and parameterize, we usually don’t interact with them directly, but through another program: JavaSTICS.

XML files

JavaSTICS is a graphical user interface used to easily create input text files for the STICS executable according to the user’s choices, and for managing STICS simulations. JavaSTICS saves the parameter values and options choices in XML files.

The XML files store more information than the text files: not only do they store the parameter values but also their description, maximum and minimum boundary values, all existing formalisms, the different choices allowed, and more importantly they allow for the management of several USMs in the same folder (called workspace), and can help make successive USMs.

It is important to note that only JavaSTICS interact with the XML files, not the STICS executable. The STICS input text files are then automatically created by JavaSTICS when running a simulation, just before calling the STICS executable.

SticsRFiles

SticsRFiles is an R package that uses JavaSTICS from the command line to manage the XML and the text files. We can generate XML or text files, get and set parameter values, import simulations outputs, and manage observation files.

Advanced features also include:

  • The generation of XML input files from templates included in the package, and
  • The production of XML input files using a mailing process from XML templates and Excel sheets containing multiple simulations contexts

Short example

Here’s a simple example usage of SticsRFiles using an example workspace.

Example data

All the example data used in this article are available from the data repository in the SticsRPacks organization.

SticsRFiles provides a function to download it from the command line. Please execute the following command in R:

library(SticsRFiles)
example_data <- SticsRFiles::download_data(example_dirs = "study_case_1",
                                           "V10.0")

The example data is downloaded by default in a temporary folder.

For the sake of readability, we’ll declare the workspace path and the path to the plant file here. But remember the functions can be applied to any XML files or workspaces.

workspace <- file.path(example_data, "XmlFiles")
plant_file <- file.path(workspace, "plant", "maisopti_plt.xml")

Example usage

Find a STICS variable

get_var_info() helps to get any STICS variable name by doing a fuzzy search. For example to get all variables with lai in their names, you would do:

SticsRFiles::get_var_info("lai")
#>              name
#> 5       albedolai
#> 242        exolai
#> 338        innlai
#> 353        lai(n)
#> 354 lai_mx_av_cut
#> 355        laimax
#> 356     laisen(n)
#> 742         splai
#> 805       ulai(n)
#>                                                           definition
#> 5                   albedo of the crop including soil and vegetation
#> 242              reduction factor on leaf growth due to water excess
#> 338 reduction factor on leaf growth due to NNI (nitrogen deficiency)
#> 353                                          leaf area index (table)
#> 354            LAI before cut (for cut crops , for others = lai(n) )
#> 355                                          maximum leaf area index
#> 356                      leaf area index of senescent leaves (table)
#> 742                source to sink ratio of assimilates in the leaves
#> 805                                relative development unit for LAI
#>            unit type
#> 5            SD real
#> 242         0-1 real
#> 338 innmin to 1 real
#> 353      m2.m-2 real
#> 354          SD real
#> 355      m2.m-2 real
#> 356      m2.m-2 real
#> 742          SD real
#> 805         0-3 real

Sometimes it is also useful to search in the variable definition instead of its name. To do so, you can use the keyword argument like so:

SticsRFiles::get_var_info(keyword = "lai")
#>                   name
#> 5            albedolai
#> 171 diftemp1intercoupe
#> 172 diftemp2intercoupe
#> 242             exolai
#> 334     inn1intercoupe
#> 336     inn2intercoupe
#> 338             innlai
#> 353             lai(n)
#> 354      lai_mx_av_cut
#> 355             laimax
#> 356          laisen(n)
#> 360               leai
#> 742              splai
#> 745     str1intercoupe
#> 746     str2intercoupe
#> 747     stu1intercoupe
#> 748     stu2intercoupe
#> 801           tustress
#> 805            ulai(n)
#>                                                                                                         definition
#> 5                                                                 albedo of the crop including soil and vegetation
#> 171        mean difference between crop and air temperatures during the vegetative phase (emergence - maximum LAI)
#> 172       mean difference between crop and air temperatures during the reproductive phase (maximum LAI - maturity)
#> 242                                                            reduction factor on leaf growth due to water excess
#> 334                               average NNI during the cut (cut crop vegetative phase: emergence to maximum LAI)
#> 336                             average NNI during the cut (cut crop reproductive phase: maximum LAI  to maturity)
#> 338                                               reduction factor on leaf growth due to NNI (nitrogen deficiency)
#> 353                                                                                        leaf area index (table)
#> 354                                                          LAI before cut (for cut crops , for others = lai(n) )
#> 355                                                                                        maximum leaf area index
#> 356                                                                    leaf area index of senescent leaves (table)
#> 360                                                                                 Leaf+ear area index = lai +eai
#> 742                                                              source to sink ratio of assimilates in the leaves
#> 745      average stomatal water stress index during the vegetative phase (emergence - maximum LAI) of forage crops
#> 746    average stomatal water stress index during the reproductive phase (maximum LAI  - maturity) of forage crops
#> 747   average turgescence water stress index during the vegetative phase (emergence - maximum LAI) of forage crops
#> 748 average turgescence water stress index during the reproductive phase (maximum LAI  - maturity) of forage crops
#> 801                      reduction factor on leaf growth due to the effective water stress  (= min(turfac,innlai))
#> 805                                                                              relative development unit for LAI
#>            unit type
#> 5            SD real
#> 171     degreeC real
#> 172     degreeC real
#> 242         0-1 real
#> 334         0-2 real
#> 336         0-2 real
#> 338 innmin to 1 real
#> 353      m2.m-2 real
#> 354          SD real
#> 355      m2.m-2 real
#> 356      m2.m-2 real
#> 360      m2.m-2 real
#> 742          SD real
#> 745         0-1 real
#> 746         0-1 real
#> 747         0-1 real
#> 748         0-1 real
#> 801         0-1 real
#> 805         0-3 real

Get informations on parameters

get_param_info() can be used giving a part of parameters names :

get_param_info(param = "lai")
#>                 name       file   min max
#> 225        cielclair    STATION     0   1
#> 305     codeclaircie     PARTEC     1   2
#> 339        codelaitr     PARPLT     1   2
#> 408        codlainet     PARPLT     1   2
#> 556          dlaimax     PARPLT 5e-06 0.5
#> 557      dlaimaxbrut     PARPLT 5e-06 0.5
#> 558          dlaimin     PARPLT     0   1
#> 699             flai USM/USMXML     0   0
#> 827           inilai     PARPLT     0   1
#> 899        juleclair     PARTEC     1 731
#> 900     juleclair(1)     PARTEC     1 731
#> 901    juleclair(10)     PARTEC     1 731
#> 902     juleclair(2)     PARTEC     1 731
#> 903     juleclair(3)     PARTEC     1 731
#> 904     juleclair(4)     PARTEC     1 731
#> 905     juleclair(5)     PARTEC     1 731
#> 906     juleclair(6)     PARTEC     1 731
#> 907     juleclair(7)     PARTEC     1 731
#> 908     juleclair(8)     PARTEC     1 731
#> 909     juleclair(9)     PARTEC     1 731
#> 1021             lai       INIT     0  10
#> 1022            lai0       INIT     0  10
#> 1023         laicomp     PARPLT     0   1
#> 1024       laidebeff     PARTEC     1  10
#> 1025      laieffeuil     PARTEC  0.05  10
#> 1026     laiplantule     PARPLT     0   8
#> 1027     lairesiduel     PARTEC     0   2
#> 1028  lairesiduel(1)     PARTEC     0   2
#> 1029 lairesiduel(10)     PARTEC     0   2
#> 1030 lairesiduel(11)     PARTEC     0   2
#> 1031 lairesiduel(12)     PARTEC     0   2
#> 1032 lairesiduel(13)     PARTEC     0   2
#> 1033 lairesiduel(14)     PARTEC     0   2
#> 1034 lairesiduel(15)     PARTEC     0   2
#> 1035 lairesiduel(16)     PARTEC     0   2
#> 1036 lairesiduel(17)     PARTEC     0   2
#> 1037 lairesiduel(18)     PARTEC     0   2
#> 1038 lairesiduel(19)     PARTEC     0   2
#> 1039  lairesiduel(2)     PARTEC     0   2
#> 1040 lairesiduel(20)     PARTEC     0   2
#> 1041  lairesiduel(3)     PARTEC     0   2
#> 1042  lairesiduel(4)     PARTEC     0   2
#> 1043  lairesiduel(5)     PARTEC     0   2
#> 1044  lairesiduel(6)     PARTEC     0   2
#> 1045  lairesiduel(7)     PARTEC     0   2
#> 1046  lairesiduel(8)     PARTEC     0   2
#> 1047  lairesiduel(9)     PARTEC     0   2
#> 1221      pentlaimax     PARPLT     0  10
#> 1425    seuilLAIapex     PARPLT     0  10
#> 1433        splaimax     PARPLT   0.7   2
#> 1434        splaimin     PARPLT  0.01   1
#> 1581        udlaimax     PARPLT     1   3
#> 1645         vlaimax     PARPLT   1.5 2.5
#>                                                                                        definition
#> 225              fraction of sunny hours allowing the inversion of thermal gradient with altitude
#> 305                      option to simulate fruit removal: 1 = no, 2 = yes (for smallest fruits) 
#> 339           option to calculate the intercepted radiation according to: 1 = LAI, 2 = soil cover
#> 408  option to calculate the LAI: 1 = net LAI, 2 = difference between gross LAI and senescent LAI
#> 556                                                     maximum rate of net daily increase of LAI
#> 557                                                   maximum rate of gross daily increase of LAI
#> 558                                                accelerating parameter for the lai growth rate
#> 699                                                                          name of the LAI file
#> 827                                                           initial value of lai for cotyledons
#> 899                                                                         day of fruits removal
#> 900                                                                         day of fruits removal
#> 901                                                                         day of fruits removal
#> 902                                                                         day of fruits removal
#> 903                                                                         day of fruits removal
#> 904                                                                         day of fruits removal
#> 905                                                                         day of fruits removal
#> 906                                                                         day of fruits removal
#> 907                                                                         day of fruits removal
#> 908                                                                         day of fruits removal
#> 909                                                                         day of fruits removal
#> 1021                                                                      initial leaf area index
#> 1022                                                                      initial leaf area index
#> 1023                                            LAI above which competition between plants starts
#> 1024                                                         LAI at the beginning of leaf removal
#> 1025                                                  LAI removed from the crop at day juleffeuil
#> 1026                                                            LAI of plantlet at the plantation
#> 1027                                                   residual LAI after each cut of forage crop
#> 1028                                                   residual LAI after each cut of forage crop
#> 1029                                                   residual LAI after each cut of forage crop
#> 1030                                                   residual LAI after each cut of forage crop
#> 1031                                                   residual LAI after each cut of forage crop
#> 1032                                                   residual LAI after each cut of forage crop
#> 1033                                                   residual LAI after each cut of forage crop
#> 1034                                                   residual LAI after each cut of forage crop
#> 1035                                                   residual LAI after each cut of forage crop
#> 1036                                                   residual LAI after each cut of forage crop
#> 1037                                                   residual LAI after each cut of forage crop
#> 1038                                                   residual LAI after each cut of forage crop
#> 1039                                                   residual LAI after each cut of forage crop
#> 1040                                                   residual LAI after each cut of forage crop
#> 1041                                                   residual LAI after each cut of forage crop
#> 1042                                                   residual LAI after each cut of forage crop
#> 1043                                                   residual LAI after each cut of forage crop
#> 1044                                                   residual LAI after each cut of forage crop
#> 1045                                                   residual LAI after each cut of forage crop
#> 1046                                                   residual LAI after each cut of forage crop
#> 1047                                                   residual LAI after each cut of forage crop
#> 1221                                               parameter of the logistic curve of LAI growth 
#> 1425                                             maximal value of LAI+LAIapex when LAIapex is > 0
#> 1433         maximal sources/sinks value allowing the trophic stress calculation for leaf growing
#> 1434                                    minimal value of ratio sources/sinks for the leaf growth 
#> 1581                                           ulai from which the rate of leaf growth decreases 
#> 1645                                   ulai at the inflexion point of the function DELTAI=f(ULAI)

it can also be used by giving a keyword that will be searched in the parameters names and definitions:

get_param_info(keyword = "plant")
#>                        name       file   min  max
#> 4                     adens     PARPLT    -2    0
#> 6                      adil     PARPLT     1    7
#> 7                   adilmax     PARPLT     3   10
#> 57       albedomulchresidus      PARAM  0.05  0.8
#> 58    albedomulchresidus(1)      PARAM  0.05  0.8
#> 59   albedomulchresidus(10)      PARAM  0.05  0.8
#> 60   albedomulchresidus(11)      PARAM  0.05  0.8
#> 61   albedomulchresidus(12)      PARAM  0.05  0.8
#> 62   albedomulchresidus(13)      PARAM  0.05  0.8
#> 63   albedomulchresidus(14)      PARAM  0.05  0.8
#> 64   albedomulchresidus(15)      PARAM  0.05  0.8
#> 65   albedomulchresidus(16)      PARAM  0.05  0.8
#> 66   albedomulchresidus(17)      PARAM  0.05  0.8
#> 67   albedomulchresidus(18)      PARAM  0.05  0.8
#> 68   albedomulchresidus(19)      PARAM  0.05  0.8
#> 69    albedomulchresidus(2)      PARAM  0.05  0.8
#> 70   albedomulchresidus(20)      PARAM  0.05  0.8
#> 71   albedomulchresidus(21)      PARAM  0.05  0.8
#> 72    albedomulchresidus(3)      PARAM  0.05  0.8
#> 73    albedomulchresidus(4)      PARAM  0.05  0.8
#> 74    albedomulchresidus(5)      PARAM  0.05  0.8
#> 75    albedomulchresidus(6)      PARAM  0.05  0.8
#> 76    albedomulchresidus(7)      PARAM  0.05  0.8
#> 77    albedomulchresidus(8)      PARAM  0.05  0.8
#> 78    albedomulchresidus(9)      PARAM  0.05  0.8
#> 135                   bdens     PARPLT     1  200
#> 136                    bdil     PARPLT  0.01  0.8
#> 137                 bdilmax     PARPLT  0.01  0.8
#> 219                  celong     PARPLT     1   10
#> 276             codazofruit     PARPLT     1    2
#> 322              codeffeuil     PARTEC     1    2
#> 323              codefixpot     PARPLT     1    3
#> 331                codehypo     PARPLT     1    2
#> 346             codemonocot     PARPLT     1    2
#> 354           codepalissage     PARTEC     1    3
#> 356                codephot     PARPLT     1    2
#> 358              codeplante     PARPLT     0    0
#> 359            codeplisoleN     PARPLT     1    2
#> 389                codetemp     PARPLT     1    2
#> 404               codgellev     PARPLT     1    2
#> 547              densitesem     PARTEC  0.05 2000
#> 617                draclong     PARPLT     1 1000
#> 620            durviesupmax     PARPLT     0    1
#> 640                 effeuil     PARTEC     0    1
#> 705                    fplt USM/USMXML     0    0
#> 767              hautmaxtec     PARTEC   0.5    3
#> 768               hautrogne     PARTEC   0.2    2
#> 825                inflomax     PARPLT     0  100
#> 946                julrogne     PARTEC     1  731
#> 986               kcouvmlch      PARAM     0    1
#> 987            kcouvmlch(1)      PARAM     0    1
#> 988           kcouvmlch(10)      PARAM     0    1
#> 989           kcouvmlch(11)      PARAM     0    1
#> 990           kcouvmlch(12)      PARAM     0    1
#> 991           kcouvmlch(13)      PARAM     0    1
#> 992           kcouvmlch(14)      PARAM     0    1
#> 993           kcouvmlch(15)      PARAM     0    1
#> 994           kcouvmlch(16)      PARAM     0    1
#> 995           kcouvmlch(17)      PARAM     0    1
#> 996           kcouvmlch(18)      PARAM     0    1
#> 997           kcouvmlch(19)      PARAM     0    1
#> 998            kcouvmlch(2)      PARAM     0    1
#> 999           kcouvmlch(20)      PARAM     0    1
#> 1000          kcouvmlch(21)      PARAM     0    1
#> 1001           kcouvmlch(3)      PARAM     0    1
#> 1002           kcouvmlch(4)      PARAM     0    1
#> 1003           kcouvmlch(5)      PARAM     0    1
#> 1004           kcouvmlch(6)      PARAM     0    1
#> 1005           kcouvmlch(7)      PARAM     0    1
#> 1006           kcouvmlch(8)      PARAM     0    1
#> 1007           kcouvmlch(9)      PARAM     0    1
#> 1023                laicomp     PARPLT     0    1
#> 1026            laiplantule     PARPLT     0    8
#> 1061             margerogne     PARTEC  0.01    1
#> 1062                  masec       INIT     0   10
#> 1063                 masec0       INIT     0   10
#> 1064              masecmeta     PARPLT   0.1    1
#> 1068          masecplantule     PARPLT 0.002    4
#> 1138           nbfeuilplant     PARPLT     0   10
#> 1142                nbinflo     PARPLT     1 1000
#> 1164              nbplantes USM/USMXML     1    2
#> 1173               nlevlim1     PARPLT     1  100
#> 1174               nlevlim2     PARPLT     1  100
#> 1175                  Nmeta     PARPLT     0  100
#> 1198               Nreserve     PARPLT     0  100
#> 1219               penterui     PARSOL     0    5
#> 1346               QNplante       INIT     0   10
#> 1347              QNplante0       INIT     0   10
#> 1348             QNplantenp       INIT     0  200
#> 1349            QNplantenp0       INIT     0  200
#> 1350            QNpltminINN      PARAM     0   50
#> 1502         tauxrecouvkmax     PARPLT   0.5    2
#> 1503          tauxrecouvmax     PARPLT   0.5    2
#> 1507                tdebgel     PARPLT    -5    5
#> 1514                  temax     PARPLT    15   40
#> 1542                  teopt     PARPLT    10   30
#> 1543               teoptbis     PARPLT    10   30
#> 1549              tgellev10     PARPLT   -25    0
#> 1550              tgellev90     PARPLT   -25    0
#> 1556                tletale     PARPLT   -30   -1
#> 1636                variete     PARTEC     1  200
#> 1637             vigueurbat     PARPLT 1e-04    1
#> 1695           zracplantule     PARPLT     0  200
#>                                                                                                                   definition
#> 4                                                                                           Interplant competition parameter
#> 6                                                         parameter of the critical dilution curve [Nplante]=adil MS^(-bdil)
#> 7                                                    parameter of the maximum dilution curve [Nplante]=adilmax MS^(-bdilmax)
#> 57                                                                                                     albedo of plant mulch
#> 58                                                                                                     albedo of plant mulch
#> 59                                                                                                     albedo of plant mulch
#> 60                                                                                                     albedo of plant mulch
#> 61                                                                                                     albedo of plant mulch
#> 62                                                                                                     albedo of plant mulch
#> 63                                                                                                     albedo of plant mulch
#> 64                                                                                                     albedo of plant mulch
#> 65                                                                                                     albedo of plant mulch
#> 66                                                                                                     albedo of plant mulch
#> 67                                                                                                     albedo of plant mulch
#> 68                                                                                                     albedo of plant mulch
#> 69                                                                                                     albedo of plant mulch
#> 70                                                                                                     albedo of plant mulch
#> 71                                                                                                     albedo of plant mulch
#> 72                                                                                                     albedo of plant mulch
#> 73                                                                                                     albedo of plant mulch
#> 74                                                                                                     albedo of plant mulch
#> 75                                                                                                     albedo of plant mulch
#> 76                                                                                                     albedo of plant mulch
#> 77                                                                                                     albedo of plant mulch
#> 78                                                                                                     albedo of plant mulch
#> 135                                                          minimal plant density above which interplant competition starts
#> 136                                                       parameter of the critical dilution curve [Nplante]=adil MS^(-bdil)
#> 137                                                  parameter of the maximum dilution curve [Nplante]=adilmax MS^(-bdilmax)
#> 219                                                                               parameter of the plantlet elongation curve
#> 276                        option to activate the direct effect of N plant status on the fruit/grain number: 1 = no, 2 = yes
#> 322                                                                       option to activate plant thinning: 1 = no, 2 = yes
#> 323  option to calculate the maximal symbiotic fixation: 1 = fixed value read in the plant file,  2 = depends on growth rate
#> 331             option to simulate plant emergency: 1 = phase of hypocotyl growth (sown crops),  2 = plantation of plantlets
#> 346                                                                option to define the type of plant: 1 = monocot, 2 =dicot
#> 354                                           option to define if the plant is fixed onto a vertical support: 1 = no, 2 =yes
#> 356                                                                   option to define plant photoperiodism: 1 = yes, 2 = no
#> 358                                                             option to define the coding name of the plant (3 characters)
#> 359           option to define N requirements at the beginning of the cycle: 1 = dense plant population, 2 = isolated plants
#> 389           option to calculate thermal time for plant growth: 1 = based on air temperature, 2 = based on crop temperature
#> 404                                                  option to activate the frost effect on plantlet growth: 1 = no, 2 = yes
#> 547                                                                                                    plant sowing density 
#> 617                                                                         maximum rate of root length production per plant
#> 620                                                          relative additional lifespan due to N excess in plant (INN > 1)
#> 640                                                                               fraction of leaf removed by plant thinning
#> 705                                                                                                   name of the plant file
#> 767                                                                    maximal height of the plant allowed by the management
#> 768                                                                                        cutting height for trimmed plants
#> 825                                                                               maximal number of inflorescences per plant
#> 946                                                                                                    day of plant trimming
#> 986                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 987                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 988                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 989                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 990                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 991                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 992                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 993                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 994                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 995                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 996                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 997                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 998                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 999                                            extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1000                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1001                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1002                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1003                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1004                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1005                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1006                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1007                                           extinction coefficient connecting the soil cover to the amount of plant mulch
#> 1023                                                                       LAI above which competition between plants starts
#> 1026                                                                                       LAI of plantlet at the plantation
#> 1061                    topping occurs when plant height exceeds (hautrogne+margerogne) when automatic trimming is activated
#> 1062                                     initial plant biomass (if the option to simulate N and C reserves is not activated)
#> 1063                                     initial plant biomass (if the option to simulate N and C reserves is not activated)
#> 1064                                                          biomass of the plantlet supposed to be composed of metabolic N
#> 1068                                                                                       initial shoot biomass of plantlet
#> 1138                                                                                     leaf number per plant when planting
#> 1142                                                                              imposed number of inflorescences per plant
#> 1164                                                                                              number of simulated plants
#> 1173                                                 number of days after germination after which plant emergence is reduced
#> 1174                                              number of days after germination after which plant emergence is impossible
#> 1175                                                                               proportion of metabolic N in the plantlet
#> 1198                 maximal proportion of N in plant reserves (difference between the maximal and critical dilution curves)
#> 1219                                                                  runoff coefficient taking into account the plant mulch
#> 1346                             initial N amount in the plant (if the option to simulate N and C reserves is not activated)
#> 1347                             initial N amount in the plant (if the option to simulate N and C reserves is not activated)
#> 1348                                                                   initial N amount in non-perennial organs of the plant
#> 1349                                                                   initial N amount in non-perennial organs of the plant
#> 1350                                                                minimal amount of N in the plant required to compute INN
#> 1502      soil cover rate corresponding to the maximal crop coefficient for water requirement (plant surface / soil surface)
#> 1503                                                                  maximal soil cover rate (plant surface / soil surface)
#> 1507                                                                      temperature below which frost affects plant growth
#> 1514                                                                      maximal temperature above which plant growth stops
#> 1542                                                                              optimal temperature (1/2) for plant growth
#> 1543                                                                              optimal temperature (2/2) for plant growth
#> 1549                                                               temperature resulting in 10% of frost damages on plantlet
#> 1550                                                               temperature resulting in 90% of frost damages on plantlet
#> 1556                                                                                        lethal temperature for the plant
#> 1636                                                    cultivar number corresponding to the cultivar name in the plant file
#> 1637                                                              plant vigor index allowing to emerge through a soil crust 
#> 1695                                                                              initial depth of root apex of the plantlet

Get parameter values

get_param_xml() is used to get the values of a parameter in an XML file. For example if we want to get dlaimax, we would do:

dlaimax <- get_param_xml(plant_file, "dlaimax")
dlaimax
#> $maisopti_plt.xml
#> $maisopti_plt.xml$dlaimax
#> [1] 0.00321 0.00321 0.00321 0.00321 0.00321

But this function is way more powerful than just that. You can also get the values for all parameters in a given formalism (formalisme in French, yes some variables are still written in French in STICS). To do so, use the select argument like so:

values <- get_param_xml(plant_file, select = "formalisme",
                        select_value = "radiation interception")
unlist(values) # For pretty-printing
#> maisopti_plt.xml.codetransrad        maisopti_plt.xml.forme 
#>                             1                             1 
#>     maisopti_plt.xml.rapforme        maisopti_plt.xml.adfol 
#>                             4                             1 
#>      maisopti_plt.xml.dfolbas     maisopti_plt.xml.dfolhaut 
#>                             5                             5

Set parameter values

We can also change the value of a parameter programmatically using set_param_xml(). It is used similarly to get_param_xml(). For example if we want to increase dlaimax by 30%:

set_param_xml(plant_file, "dlaimax", unlist(dlaimax) * 1.3, overwrite = TRUE)

Don’t forget to use the overwrite argument and set it to TRUE. It is FALSE by default to avoid any mishandling.

New values written in the file can be checked:

dlaimax <- get_param_xml(plant_file, "dlaimax")
dlaimax
#> $maisopti_plt.xml
#> $maisopti_plt.xml$dlaimax
#> [1] 0.004173 0.004173 0.004173 0.004173 0.004173

Generate observations files

We can generate observation files from a data.frame using gen_obs().

Lets create some dummy data.frame first:

obs_df <- data.frame(usm_name = "Test", ian = 2021, mo = 3:10, jo = 1,
                     `masec(n)` = 0.1 * 3:10)

Then we can write the data to a file using gen_obs():

gen_obs(df = obs_df, out_dir = "/path/to/dest/dir")

Read observations files

We can read the observation files in a workspace using get_obs(). Note that all observation files should be named after the USM they are linked to. See the help page for more details, e.g. about intercrops.

obs <- get_obs(workspace)
#> bo96iN+.obs
#> bou00t1.obs
#> bou00t3.obs
#> bou99t1.obs
#> bou99t3.obs
#> lu96iN+.obs
#> lu96iN6.obs
#> lu97iN+.obs

Read simulation files

Likewise, we can read the observation files in a workspace using get_sim():

sim <- get_sim(workspace)
#> Warning in get_file_(workspace = x, usm_name = usm_name, usms_filepath =
#> usms_path, : Not any sim file detected in
#> workspace/tmp/RtmpjkDYAq/data-master/
#> study_case_1/V10.0/XmlFiles

But as there aren’t any simulations yet in the workspace, the function will return an error. To make a simulation, head to SticsOnR. Then to plot both observations and simulations, you can use CroPlotR.