| Title: | Calculation of Agricultural Water Needs and Evapotranspiration |
|---|---|
| Description: | An R tool for calculating theoretical irrigation water consumption over a territory. CAWET extracts, models and analyzes agro-climatic data to produce maps, graphics and comparative outputs across different scenarios. The workflow includes data extraction from online databases (via RADIS), modeling (primarily using CropWat), and visualization of results through graphics and maps. |
| Authors: | Pierre Rouault [aut, cre] (ORCID: <https://orcid.org/0009-0002-9473-7232>), David Dorchies [aut] (ORCID: <https://orcid.org/0000-0002-6595-7984>), Claire Richert [aut] (ORCID: <https://orcid.org/0000-0001-7456-6689>) |
| Maintainer: | Pierre Rouault <[email protected]> |
| License: | AGPL (>= 3) |
| Version: | 1.1.0 |
| Built: | 2026-05-29 09:23:41 UTC |
| Source: | https://forge.inrae.fr/umr-g-eau/cawet |
This function creates plots around a point, with a given surface area.
creer_parcelles_autour_point_centre(lon, lat, crops, areas, col_crop, col_area)creer_parcelles_autour_point_centre(lon, lat, crops, areas, col_crop, col_area)
lon |
numeric longitude in decimal degrees. |
lat |
numeric latitude in decimal degrees. |
crops |
|
areas |
numeric vector surface areas of the crops listed in |
col_crop |
character standardized name of the column with the crop names. |
col_area |
character standardized name of the column with the surface area. |
A sf::sf object containing a plot for each crop, with the corresponding surface area.
This function creates plots around a point, with a given surface area.
creer_parcelles_autour_point_repgraph( lon, lat, crops, areas, col_crop, col_area )creer_parcelles_autour_point_repgraph( lon, lat, crops, areas, col_crop, col_area )
lon |
numeric longitude in decimal degrees. |
lat |
numeric latitude in decimal degrees. |
crops |
|
areas |
numeric vector surface areas of the crops listed in |
col_crop |
character standardized name of the column with the crop names. |
col_area |
character standardized name of the column with the surface area. |
A sf::sf object containing a plot for each crop, with the corresponding surface area.
This function constructs a full file path for CAWET by checking if the provided path is already an absolute path. If it is not, it combines it with the specified working directory.
FpCAWET(Working_path, path)FpCAWET(Working_path, path)
Working_path |
A string representing the working directory path. |
path |
A string representing the file path to be checked or combined. |
A string representing the full file path.
Get or create a CAWET run configuration
get_Run_Config( path = NULL, Working_path = dirname(dirname(path)), Scenario = NULL ) get_Path_Run(path = choose.dir(), Working_path, new = FALSE)get_Run_Config( path = NULL, Working_path = dirname(dirname(path)), Scenario = NULL ) get_Path_Run(path = choose.dir(), Working_path, new = FALSE)
path |
Character string specifying the path to an existing run directory. If NA the function retrieves the most recent run directory. By default, a folder selection dialog will be opened. |
Working_path |
Character string specifying the working directory. |
Scenario |
Optional data frame containing scenario data. If provided, it will be saved to the run directory. If NULL, the function will attempt to read the scenario data from the run directory. |
new |
Logical indicating whether to create a new run directory. If TRUE, a new run directory will be created. If FALSE, the most recent existing run directory will be retrieved. |
Behavior depending on the value of Scenario:
If Scenario is provided (non-NULL):
get_Run_Config calls get_Path_Run(..., new = TRUE) which creates a new
run directory at file.path(Working_path, "Runs", paste0("Run_", <timestamp>)).
The provided Scenario data frame is written into Scenarii.csv inside the
new run directory.
A Charged_inputs directory is created inside the run directory and its path is
returned as Path_Run_Chargementdata.
If Scenario is NULL:
get_Run_Config calls get_Path_Run(..., new = FALSE) which:
If path is NA: finds the most recent existing run directory under
file.path(Working_path, "Runs") (the last Run_ entry).
If path is provided: validates that the directory exists and returns it.
The function attempts to read Scenarii.csv from the chosen run directory using
read_ordonnanceur() to populate Scenario.
The Charged_inputs directory is created if missing and its path returned.
Note: the default path uses choose.dir(); when creating a new run the run
timestamp ensures unique run folder names.
get_Run_Config returns a list with the following elements:
Working_path: The working directory used for the run.
Path_Run: The path to the created or selected run directory.
Scenario: A data frame containing the scenario information used for the run.
Path_Run_Chargementdata: The path to the Charged_inputs directory inside the run.
get_Path_Run returns a character string with the path to the run directory.
get_Run_Config(): This function retrieves or creates a run configuration for CAWET,
including the run path, scenario data, and path to charged input data.
get_Path_Run(): Get or create a run path
This function retrieves soil depth information for the given parcels with a specific grid (maille_y). It performs a spatial intersection between the parcels and the soil depth data obtained from the specified source, then calculates the total surface area for each soil depth category within each parcel.
get_soil_depth(sf, source = "BDGSF")get_soil_depth(sf, source = "BDGSF")
sf |
An sf object containing parcels for which soil depth information is to be retrieved. The sf object should have a column named "id_parcel" that uniquely identifies each parcel and a column named "surface_m2" representing the surface area of each parcel. |
source |
A character string specifying the source of soil depth data. Default is "BDGSF". |
A data frame with parcel identifiers and their corresponding soil depth information.
This function retrieves soil texture information for the given parcels with a specific grid (maille_y). It performs a spatial intersection between the parcels and the soil texture data obtained from the specified source, then calculates the mean values of clay, silt, and sand for each parcel.
get_soil_textures(parcelles_avec_maille_y, Depth)get_soil_textures(parcelles_avec_maille_y, Depth)
parcelles_avec_maille_y |
An sf object containing parcels with a specific grid (maille_y) for which soil texture information is to be retrieved. The sf object should have a column named "id_parcel" that uniquely identifies each parcel. |
Depth |
A data frame containing soil depth information for the parcels, with a column named "id_parcel" that uniquely identifies each parcel and a column named "soil_depth" representing the soil depth category. |
A data frame with parcel identifiers and their corresponding mean values of clay, silt, and sand.
This function is a wrapper around ggplot2::ggsave that suppresses messages.
It can be used to avoid cluttering the console with messages when saving plots.
ggsave(...)ggsave(...)
... |
Arguments passed to |
The return value of ggplot2::ggsave, invisibly.
grille_safran is an sf polygon grid derived from Météo-France SAFRAN
mesh coordinates. It is used to associate each territory/plot with a SAFRAN
climate cell for weather data retrieval.
grille_safrangrille_safran
An sf object with 8,969 rows and 4 variables:
Character. SAFRAN grid cell identifier.
Integer. SAFRAN X coordinate in Lambert-93 (hectometers).
Integer. SAFRAN Y coordinate in Lambert-93 (hectometers).
POLYGON geometry (CRS: EPSG 2154, RGF93 / Lambert-93).
Météo-France public dataset "coordonnees-des-mailles_339.csv": https://donneespubliques.meteofrance.fr/client/document/coordonnees-des-mailles_339.csv
data(grille_safran) sf::st_crs(grille_safran)data(grille_safran) sf::st_crs(grille_safran)
This function creates a sf object with polygons associated to identifiers, area, and standardized column names. Polygons can be either agricultural plots associated to a crop and a bigger polygon, or directly the big polygons (in which case, agricultural plots will be retrieved for each year from the RPG database).
prepare_territory_for_existing_plots( Working_path, Scenario, COL = list(poly = "id_poly", plot = "id_parcel", crop = "code_cultu", area = "surface_m2"), col_map, external_plots )prepare_territory_for_existing_plots( Working_path, Scenario, COL = list(poly = "id_poly", plot = "id_parcel", crop = "code_cultu", area = "surface_m2"), col_map, external_plots )
Working_path |
character working directory. |
Scenario |
vector contains information regarding the scenario of interest. |
COL |
list standardized column names for polygon, plot, crop, and area identifiers. |
col_map |
data.frame correspondence table between standardized column names ( |
external_plots |
logical If TRUE, agricultural plots are provided by the user. |
A sf::sf object containing polygons for which data must be retrieved.
This function creates a sf object with polygons associated to identifiers, area, and standardized column names. Polygons are agricultural plots associated to a crop and a bigger polygon
prepare_territory_for_non_existing_plots( Working_path, shp_link, COL = list(poly = "id_poly", plot = "id_parcel", crop = "code_cultu", area = "surface_m2"), col_map )prepare_territory_for_non_existing_plots( Working_path, shp_link, COL = list(poly = "id_poly", plot = "id_parcel", crop = "code_cultu", area = "surface_m2"), col_map )
Working_path |
character working directory. |
shp_link |
character name of the original data file. |
COL |
list standardized column names for polygon, plot, crop, and area identifiers. |
col_map |
data.frame correspondence table between standardized column names ( |
A sf::sf object containing a polygons for which data must be retrieved.
This function returns a numeric vector with a soil characteristic averaged or summed for all soil horizons, depending on the soil depth.
process_soil_characteristic(df, variable, FUN)process_soil_characteristic(df, variable, FUN)
df |
data.frame result of RADIS::get_soil_texture or RADIS::get_soil_awc joined with the result of RADIS::get_soil_depth (depth in [m]). |
variable |
character one of the column returned by get_soil_texture |
FUN |
function the function to use to aggregate the soil characteristic (mean or sum) |
A numeric vector containing averaged texture characteristic.
Read CAWET Data File
read_CAWET_data(Working_path, file) read_ordonnanceur(chemin_ordonnanceur)read_CAWET_data(Working_path, file) read_ordonnanceur(chemin_ordonnanceur)
Working_path |
The working directory path where the CAWET data file is located. |
file |
The name of the CAWET data file to read. |
chemin_ordonnanceur |
The full path to the Ordonnanceur file. |
A data frame containing the contents of the CAWET data file.
read_ordonnanceur reads an Ordonnanceur file (Excel or CSV) and returns
its contents as a data frame with all columns converted to character.
read_CAWET_data(): Reads a CAWET data file (CSV or Excel) from the specified working path.
This function reads a CAWET data file (CSV or Excel) from the specified working path.
read_ordonnanceur(): Read Ordonnanceur File (Excel or CSV)
This function orchestrates the entire CAWET workflow, including verification of the scheduler, extraction of relevant information, modeling/simulation of crops, and generation of result illustrations.
run( chemin_ordonnanceur = file.choose(), Scenario = read_ordonnanceur(chemin_ordonnanceur), Working_path = dirname(dirname(chemin_ordonnanceur)), cfgRun = get_Run_Config(Working_path = Working_path, Scenario = Scenario) )run( chemin_ordonnanceur = file.choose(), Scenario = read_ordonnanceur(chemin_ordonnanceur), Working_path = dirname(dirname(chemin_ordonnanceur)), cfgRun = get_Run_Config(Working_path = Working_path, Scenario = Scenario) )
chemin_ordonnanceur |
(Optional) Character string specifying the path
to the scheduler (ordonnanceur) file.
Uses an interactive file chooser ( |
Scenario |
(Optional) data.frame produced by |
Working_path |
(Optional) Character string specifying the working directory path. |
cfgRun |
(Optional) Running configuration created by |
Returns invisibly the running configuration (See get_Run_Config()).
This function runs the Cropwat CAWET simulation for a specified crop, irrigation method, and sequence. It takes into account various parameters such as irrigation settings, crop characteristics, meteorological data, and simulation settings to generate detailed output results.
Run_Cropwat_CAWET( Irrigation_param, mod_irr, Sequence, carac_date_irr, Link_RPG_mod, Crop, Crops_param, Meteo_maille, liste_not_parametredcrops )Run_Cropwat_CAWET( Irrigation_param, mod_irr, Sequence, carac_date_irr, Link_RPG_mod, Crop, Crops_param, Meteo_maille, liste_not_parametredcrops )
Irrigation_param |
A data frame containing irrigation parameters. |
mod_irr |
A string representing the irrigation method. |
Sequence |
A data frame containing sequence information. |
carac_date_irr |
A logical value indicating whether to use specific irrigation dates |
Link_RPG_mod |
A data frame linking RPG crop names to Cropwat crop names. |
Crop |
A string representing the crop name. |
Crops_param |
A data frame containing crop parameters. |
Meteo_maille |
A data frame containing meteorological data for the grid cell |
liste_not_parametredcrops |
A vector of strings representing crops that are not parameterized. |
None. The function saves the detailed output results to a CSV file.
This script loads and prepares input data for the CAWET model using RADIS data. It reads scenario information from an Excel file, processes spatial data for plots, and prepares meteorological and soil data for each scenario and year. It saves the prepared data in a structured directory for further analysis.
run_script1(cfgRun)run_script1(cfgRun)
cfgRun |
(Optional) Running configuration created by |
Input files and data sources
chemin_ordonnanceur: scheduler file read with read_ordonnanceur() (scenario-level
configuration used throughout the workflow).
Important convention: every Scenario$XXX used in this function corresponds to the
values found in the XXX column of the scheduler file (one value per scenario row).
Working_path/Model_param/odr_to_rpg.csv: mapping table used to harmonize crop codes
between ODR and RPG nomenclatures.
Météo-France grid coordinates file (downloaded from
https://donneespubliques.meteofrance.fr/client/document/coordonnees-des-mailles_339.csv),
used to build the climate network mesh.
Scenario$Wanted_output: scenario-specific file read with read_CAWET_data() to control
optional map/graph exports.
Plot/territory inputs (depending on Scenario$Plots_RADIS_RPG):
Existing plots ("Yes"/"External_plot_map") through
prepare_territory_for_existing_plots().
Synthetic territory ("Non_existant_plots") through
prepare_territory_for_non_existing_plots().
Optional soil input files:
Scenario$Soil_information_link when Scenario$Sol_fixed_RADIS == "No".
Optional supplementary AWC raster directory from
Scenario$Sol_carte_sup_RU_link_to_doss (files matching RU_*.tif).
Optional climate inputs:
Scenario$Climat_link_fixe for forced/unique climate mode.
Scenario$Climat_link_Drias parameter table for DRIAS extraction.
Main processing steps
Read scheduler, initialize run directories with get_Run_Config(), and validate unique
scenario names.
Build the SAFRAN grid geometry and scenario-specific working folders.
Load and save wanted outputs table (Wanted_outputs.csv).
Build plot geometries per scenario and year:
Download RPG polygons (RADIS::get_rpg_data()) when requested.
Harmonize crop codes using odr_to_rpg.csv.
Keep/rename standard columns (id_poly, id_parcel, code_cultu, surface_m2).
Spatially link plots to climate meshes and sub-meshes:
Create network/subnetwork intersections.
Export link table between plots and meshes.
Optionally generate cartographic diagnostic figures.
Enrich plots with soil attributes (depth, AWC, texture), depending on scenario mode:
External fixed soil table.
RADIS BDGSF / Info&Sols retrieval.
Optional AWC replacement from supplementary raster maps.
Aggregate yearly plot information by crop/polygon/mesh/sub-mesh and write spatial outputs.
Retrieve climate time series (Unique/Forced, SAFRAN, or DRIAS) and write per-scenario/per-mesh files.
Build and save linear yearly tables (surface, depth, AWC, clay, silt, sand) per crop, polygon and sub-mesh.
For synthetic territories, export additional illustration and map files.
Outputs created
For each scenario, files are written under cfgRun$Path_Run_Chargementdata/<index>_<Scenario>/:
Wanted_outputs.csv
Networkplots_<Year>.shp
Link_plots_mailles_<Year>.csv
Plots_all_RADIS_information_<Year>.shp
Crops_all_RADIS_information.shp (all years combined)
Meteo/Meteo.csv (unique/forced climate mode) or
Meteo/Meteo_maille<id>.csv (network mode)
Optional maps in Meteo/:
Plots_in_climaticalnetwork_<Year>.png
Plots_in_climaticalnetwork_<Year>_withsubnetwork.png
Illustration_plots_maille.png (synthetic territory mode)
Formodification/Territoire_repartition_cultures_<Year>.csv
Formodification/Soil_average_<Year>.csv
Linear tables:
Surf_table_<Scenario>.csv
Prof_table_<Scenario>.csv
AWC_table_<Scenario>.csv
Arg_mean_table_<Scenario>.csv
Lim_mean_table_<Scenario>.csv
Sab_mean_table_<Scenario>.csv
Additional file for synthetic territory:
Plots_location_notcenteredforillustration.shp
A list containing:
Run_path: The path to the run directory.
Scenario: A data frame containing scenario data.
Path_Run_Chargementdata: The path to the charged input data directory.
This function runs the simulation (script 2) for crop water management modeling. It performs the following tasks:
Sets up a portable R library for package management.
Loads required R packages.
Reads scenario configurations and input data. Processes simulations for different crops, polygons, and irrigation methods.
Saves detailed output results and generates verification graphs.
Handles missing crop parameter warnings.
run_script2(cfgRun = get_Run_Config(Working_path = Working_path))run_script2(cfgRun = get_Run_Config(Working_path = Working_path))
cfgRun |
(Optional) Running configuration created by |
None. The function saves output files to the specified directories.
This script generates graphs based on the results of a CAWET scenario simulation. It reads the simulation results and creates various visualizations such as pie charts for crop distribution, bar charts for annual and monthly irrigation data, and comparison graphs with validation data if provided. It saves the generated graphs in a specified directory for further analysis.
run_script3_1(cfgRun = get_Run_Config(Working_path = Working_path))run_script3_1(cfgRun = get_Run_Config(Working_path = Working_path))
cfgRun |
(Optional) Running configuration created by |
This function does not return a value but saves graphs to the specified directory.
This function runs the script 3.2 for comparing scenarios based on the last run or a chosen run path. It generates comparison plots and CSV files for area, irrigation, and ETc in the Results_comparison folder.
run_script3_2(cfgRun = get_Run_Config(Working_path = Working_path))run_script3_2(cfgRun = get_Run_Config(Working_path = Working_path))
cfgRun |
(Optional) Running configuration created by |
This function does not return a value but generates comparison plots and CSV files in the Results_comparison folder.
This function calculates climatic indicators from meteorological data and generates corresponding graphs.
run_script3_3(cfgRun = get_Run_Config(Working_path = Working_path))run_script3_3(cfgRun = get_Run_Config(Working_path = Working_path))
cfgRun |
(Optional) Running configuration created by |
None. The function saves the results and graphs in the specified directories.
This function copies all necessary files from the CAWET package's extdata directory to a user-specified destination directory.
setup_CAWET(destdir)setup_CAWET(destdir)
destdir |
Character string specifying the destination directory where the CAWET instance should be set up. |
None. The function performs file copy operations.
destdir <- file.path(tempdir(), "CAWET") setup_CAWET(destdir) list.files(destdir)destdir <- file.path(tempdir(), "CAWET") setup_CAWET(destdir) list.files(destdir)
This function is a wrapper around sf::st_read that suppresses messages.
It can be used to avoid cluttering the console with messages when reading spatial data.
st_read(...)st_read(...)
... |
Arguments passed to |
The return value of sf::st_read, invisibly.
This function verifies the content of the ordonnanceur (scenario file) for CAWET. It checks for the existence and correctness of various parameters and files specified in the ordonnanceur.
Verif_ordonnanceur_CAWET(cfgRun)Verif_ordonnanceur_CAWET(cfgRun)
cfgRun |
(Optional) Running configuration created by |
None. The function stops execution and raises an error if any verification fails.