library(SticsRFiles) library(dplyr)
suppressWarnings(library(SticsRFiles))
knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = FALSE, workspace_path <- tempdir(), stics_version <- SticsRFiles::get_stics_versions_compat()$latest_version )
In this part information are focusing on functionalities related to STICS XML files generation capabilities based on parameterization for lists of simulations (USMs) stored in tabulated data files; as Excel or CSV files.
The functions operate on data loaded as data.frames from Excel sheets or CSV files
Specialized functions for producing XML files are taking into account: initialization files, stations files, crop management files, usms file and soils files. General parameters files generation are not available, but will be eventually included in future developments.
Observations data files generation have been included even if they are not in XML format.
The generation of weather files is not included yet in the package, but will be included in a future version. One can use the tool provided by JavaSTICS GUI to perform these files generation.
This document has been generated using the latest STICS version r stics_version
.
There is not at the moment an integrated function which is able to produce all needed parameters files. Individual functions are dedicated to each parameter file kind and may be called individually or gathered in a single script for doing all tasks at once. Use examples are given in next parts below.
usms.xml
filesols.xml
file*_ini.xml
)*_tec.xml
)*_sta.xml
)Excel
example file from the SticsRFiles
package {#get-xl}In the following example /path/to/target/dir
must be replaced with a real path depending on the operating system (i.e. starting with c:/
for windows for example)
# Getting the file in the current directory usm_xl_file <- download_usm_xl() # Getting the file in a specic directory xl_dir <- "/path/to/xl/dir" # or something like C:/path/to/xl/dir" for Windows usm_xl_file <- download_usm_xl(out_dir = xl_dir) #> [1] "inputs_stics_example.xlsx has been copied in directory #> "/path/to/xl/dir
usm_xl_file <- download_usm_xl(file = "inputs_stics_example.xlsx", out_dir = workspace_path)
CSV
example file from the SticsRFiles
package {#get-csv}# Getting the file in the current directory usm_csv_file <- download_usm_csv(file = "inputs_stics_example_USMs.csv") # Getting the file in a specific directory csv_dir <- "/path/to/csv/dir" # or something like C:/path/to/xl/dir" for Windows usm_csv_file <- download_usm_csv(file = "inputs_stics_example_USMs.csv", out_dir = csv_dir) #> [1] inputs_stics_example_USMs.csv has been copied in directory #> "/path/to/csv/dir
usm_csv_file <- download_usm_csv(file = "inputs_stics_example_USMs.csv", out_dir = workspace_path)
As told in the previous section, parameters data may be stored either in Excel files containing several sheets or in several equivalent individual CSV files.
Sheets content and CSV files content is the same, only their use is different. But, CSV files are easily traced under version control systems and they also can be generated programmatically with the help of functions dedicated for example to generating crop management parameters like irrigation, fertilization (interventions and doses calculations).
The USMs data which are necessary for generating the usms.xml
must be all provided either through an Excel sheet or a CSV file; as shown in the USMs sheet example.
Other data stored in Excel or CSV files must be adapted to the use cases here after:
For generating new files, containing parameters with different values for each USM, tables must contain values for all the files parameters.
For generating files with a common set of parameter values and only a part of them must be overloaded with values coming from parameters tables, one must give an existing file as a template for files generation to functions gen_*_xml
(listed here).
Excel sheet names are completely free, but must be meaningful regarding the kind of parameters set they contain.
In the example, useful sheets for generating XML parameters files are named: USMs, Ini, Soils, Tec, Station
The first column is used for storing identifiers or files names (or prefix) and the USMs table contains identifiers of the other linked tables in columns names finit, nomsol, fstation, ftec_1, ftec_2 with respect to initialization files, soil name, station files and crop management files (for main crops and optionally associated crops).
The first column names of data tables are automatically detected and must contain keywords prefix to do so as listed: usm_, ini_, soil_, sta_, tec_
These first columns may contain either names identifiers or files names according to data type:
Other columns of tables are named with parameters names according to the following rules:
get_param_info
function)Here is the actual correspondence table of keywords
to be used in parameters tables (i.e excel files for example) in replacement of real names in XML files:
l <- SticsRFiles:::get_params_dict() df <- data.frame(keyword = names(l), realname = unlist(l, use.names = FALSE), stringsAsFactors = FALSE) rmarkdown::paged_table(df)
As an example, looking in the Tec sheet of the previously downloaded Excel file, irrigation parameters for setting days and amount of water supplied, are respectively named julapI_1, julapI_2,… and doseI_1, doseI_2,… instead of using absolute_value/% and amount.
For the moment, no consistency checks (between Excel sheets or CSV equivalents files) functionalities have been included in the package in order to prevent missing generated files or misspelled file names or identifiers.
So, one must take care of links between xml files names for example files names defined for usms related to names declared for example in Excel sheets Tec
, Station
, and so on.
In future developments, checks will be included to run be run prior to files generations, for preventing errors.
The Excel file which contains parameters values to take into account for STICS inputs may contain specific sheets for each kind of parameters groups, i.e. USMs, crop management, soil, weather station, initializations (except plant parameters and general parameters).
The following table contains data extracted from a sheet named USMs containing a list of USMS parameters or from his equivalent CSV example file.
library(readxl) xl_param <- read_params_table(usm_xl_file, sheet = "USMs") knitr::kable(xl_param)
usms
XML file (usms.xml)The gen_usms_xml function is working on a data.frame object that can be loaded either from an Excel file sheet or from a csv file. Here after code shows how to get data from the downloaded examples Excel and CSV files.
# Reading the Excel file usms_param <- read_params_table(usm_xl_file, sheet_name = "USMs") # Or # Reading the CSV file usms_param <- read_params_table(usm_csv_file)
library(readxl) # Reading the Excel file xl_param <- read_params_table(usm_xl_file, sheet_name = "USMs") xl_param <- read_params_table(usm_xl_file, sheet_name = "USMs") rmarkdown::paged_table(xl_param)
# Output file path out_file <- "/path/to/file/usms.xml" # or something like C:/path/to/file/usms.xml" for Windows # Generating a new usms.xml file, for all xl_param lines gen_usms_xml(file = out_file, param_df = usms_param)
out_file <- file.path(workspace_path, "usms.xml") # Generating a new usms.xml file, for all xl_param lines gen_usms_xml(file = out_file, param_df = xl_param)
usms.xml
file contentExample of the first usm
parameters:
l <- readLines(con = out_file) cat(paste(c(l[1:24], "...", l[length(l) - 1]), collapse = "\n"))
sols
XML file (sols.xml)As for gen_usms_xml
, gen_sols_xml
function is working on a data.frame object loaded from an Excel file sheet. The following code only shows here after the sols.xml
file generation section.
# Reading the Excel file soils_param <- read_params_table(usm_xl_file, sheet_name = "Soils")
library(readxl) # Reading the Excel file soils_param <- read_params_table(usm_xl_file, sheet_name = "Soils") rmarkdown::paged_table(soils_param)
# Output file path out_file <- "/path/to/file/sols.xml" # or something like C:/path/to/file/usms.xml" for Windows # Generating a new sols.xml file, for all xl_param lines gen_sols_xml(file = out_file, param_df = soils_param)
out_file <- file.path(workspace_path, "sols.xml") # Generating a new sols.xml file, for all xl_param lines gen_sols_xml(file = out_file, param_df = soils_param)
sols.xml
file contentExample of the first sol
parameters sub-list:
l <- readLines(con = out_file) cat(paste(c(l[1:30], "...", l[110], "...", l[length(l) - 1]), collapse = "\n"))
# Reading the Excel file tec_param <- read_params_table(usm_xl_file, sheet_name = "Tec")
library(readxl) # Reading the Excel file tec_param <- read_params_table(usm_xl_file, sheet_name = "Tec") rmarkdown::paged_table(tec_param)
# *_tec.xml files, one for each xl_param line gen_tec_xml(param_df = tec_param, out_dir = workspace_path)
# *_tec.xml files, one for each xl_param line gen_tec_xml(param_df = tec_param, out_dir = workspace_path)
Example of a tec
parameters file content sub-list:
l <- readLines(con = file.path(workspace_path, "BIN_CAN_05_SEC_220-0-0_34K_CANPC05T3_Q_tec.xml")) cat(paste(c(l[1:30], "...", l[length(l) - 1]), collapse = "\n"))
# Reading the Excel file ini_param <- read_params_table(usm_xl_file, sheet_name = "Ini")
library(readxl) # Reading the Excel file ini_param <- read_params_table(usm_xl_file, sheet_name = "Ini") rmarkdown::paged_table(ini_param)
# *_ini.xml files, one for each xl_param line gen_ini_xml(param_df = ini_param, out_dir = workspace_path)
# *_ini.xml files, one for each xl_param line gen_ini_xml(param_df = ini_param, out_dir = workspace_path)
Example of a ini
parameters file content sub-list:
l <- readLines(con = file.path(workspace_path, "USM_2017_T1_ini.xml")) cat(paste(c(l[1:19], "...", l[length(l) - 1]), collapse = "\n"))
# Reading the Excel file sta_param <- read_params_table(usm_xl_file, sheet_name = "Station")
library(readxl) # Reading the Excel file sta_param <- read_params_table(usm_xl_file, sheet_name = "Station") rmarkdown::paged_table(sta_param)
# *_sta.xml files, one for each xl_param line gen_sta_xml(param_df = sta_param, out_dir = workspace_path)
# *_sta.xml files, one for each xl_param line gen_sta_xml(param_df = sta_param, out_dir = workspace_path)
Example of a sta
parameters file content sub-list:
l <- readLines(con = file.path(workspace_path, "climatex_sta.xml")) cat(paste(c(l[1:41], "...", l[length(l) - 1]), collapse = "\n"))
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.