### Install Rwofost R Package (Development Version) Source: https://github.com/cropmodels/rwofost/blob/master/README.md Installs the development version of the Rwofost R package from GitHub. This version may contain newer features or bug fixes but is less tested than the CRAN version. Requires the 'remotes' package. ```R install.packages("meteor") remotes::install_github("cropmodels/Rwofost") ``` -------------------------------- ### Install Rwofost R Package (CRAN) Source: https://github.com/cropmodels/rwofost/blob/master/README.md Installs the stable version of the Rwofost R package directly from CRAN. This is the recommended method for most users. ```R install.packages("Rwofost") ``` -------------------------------- ### Configure Simulation Control with Rwofost Source: https://context7.com/cropmodels/rwofost/llms.txt Sets up control parameters for WOFOST simulations, including simulation start date, location (latitude, elevation), atmospheric CO2 concentration, and simulation duration. It allows configuration for both potential and water-limited production scenarios. ```r library(Rwofost) control <- wofost_control() str(control) ``` ```r control$modelstart <- as.Date("1980-03-15") control$latitude <- 52.0 control$elevation <- 10 control$water_limited <- 0 control$CO2 <- 400 ``` ```r control_watlim <- wofost_control() control_watlim$water_limited <- 1 control_watlim$watlim_oxygen <- 1 control_watlim$modelstart <- as.Date("1985-01-01") control_watlim$latitude <- 14.18 control_watlim$elevation <- 21 ``` ```r control$max_duration <- 300 control$stop_maturity <- 1 ``` -------------------------------- ### Format and Validate Weather Data Source: https://context7.com/cropmodels/rwofost/llms.txt Explains the required structure for weather input data, including mandatory columns and units. It provides an example of generating synthetic weather data and verifying the integrity of the date sequence. ```R library(Rwofost) dates <- seq(as.Date("2020-01-01"), as.Date("2020-12-31"), by = "day") n <- length(dates) weather <- data.frame( date = dates, srad = runif(n, 5000, 25000), tmin = 5 + 10 * sin(2*pi*(1:n)/365), tmax = 15 + 12 * sin(2*pi*(1:n)/365), prec = rgamma(n, shape = 0.5, rate = 0.2), wind = runif(n, 1, 5), vapr = runif(n, 0.5, 2.0) ) date_gaps <- diff(weather$date) all(date_gaps == 1) ``` -------------------------------- ### Configure and Run Spatial WOFOST Model Source: https://context7.com/cropmodels/rwofost/llms.txt Demonstrates how to initialize a WOFOST model object for spatial prediction, including setting up weather datasets and soil parameter lists. This approach is intended for regional-scale modeling using spatial raster inputs. ```R model <- wofost_model( crop = wofost_crop("maize_1"), soil = wofost_soil("ec1"), control = wofost_control() ) model$control$water_limited <- 1 model$control$latitude <- 40 soiltypes <- list( wofost_soil("ec1"), wofost_soil("ec2"), wofost_soil("ec3") ) ``` -------------------------------- ### wofost_crop - Load Crop Parameters Source: https://context7.com/cropmodels/rwofost/llms.txt Returns a list of crop parameters for use in WOFOST simulations. Can load built-in parameter sets or read custom parameters from an INI file. ```APIDOC ## wofost_crop - Load Crop Parameters ### Description Loads and returns a list of crop-specific parameters required for WOFOST simulations. Supports built-in parameter sets for various crops and custom INI files. ### Method `wofost_crop(crop_name_or_path)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```r library(Rwofost) # Load parameters for barley barley_params <- wofost_crop("barley") # Load parameters for potato potato_params <- wofost_crop("potato_704") # Load custom parameters from an INI file (example path) # custom_params <- wofost_crop("path/to/your/custom_crop.ini") ``` ### Response #### Success Response (200) - **crop_parameters** (list) - A list containing parameters for the specified crop. #### Response Example ``` # The output is a list of parameters, e.g.: # $name # [1] "barley" # $pheno # $photosyn # ... (many other parameters) ``` ``` -------------------------------- ### Create and Manage Reusable WOFOST Model Objects Source: https://context7.com/cropmodels/rwofost/llms.txt Demonstrates the use of wofost_model() to create a persistent model object. This allows for iterative parameter updates and multiple simulation runs, which is ideal for scenario comparisons and sensitivity analysis. ```R library(Rwofost) library(meteor) weather_file <- system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) model <- wofost_model( crop = wofost_crop("barley"), weather = weather, soil = wofost_soil("ec1"), control = wofost_control() ) model$control$modelstart <- as.Date("1980-02-06") model$control$latitude <- 52.57 model$control$elevation <- 50 results1 <- run(model) model$control$modelstart <- as.Date("1980-02-20") results2 <- run(model) plot(results1$date, results1$LAI, type = "l", col = "blue", xlab = "Date", ylab = "LAI", main = "Effect of Sowing Date on LAI") lines(results2$date, results2$LAI, col = "red") legend("topright", legend = c("Feb 6", "Feb 20"), col = c("blue", "red"), lty = 1) crop(model) <- wofost_crop("potato_704") results3 <- run(model) lines(results3$date, results3$LAI, col = "green") ``` -------------------------------- ### Update Model Parameters with Setter Methods Source: https://context7.com/cropmodels/rwofost/llms.txt Shows how to use setter methods to modify crop, soil, and control parameters on an existing model object. This approach is more efficient for running multiple scenarios compared to re-initializing the model. ```R library(Rwofost) library(meteor) weather_file <- system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) model <- wofost_model() crop(model) <- wofost_crop("winterwheat_101") soil(model) <- wofost_soil("ec2") weather(model) <- weather control(model) <- wofost_control() model$control$modelstart <- as.Date("1979-10-01") ww_results <- run(model) crop(model) <- wofost_crop("barley") model$control$modelstart <- as.Date("1980-03-01") barley_results <- run(model) soil(model) <- wofost_soil("ec4") barley_ec4 <- run(model) ``` -------------------------------- ### Run Water-Limited vs Potential Crop Simulation Source: https://context7.com/cropmodels/rwofost/llms.txt Demonstrates how to configure and run WOFOST simulations to compare potential and water-limited crop yields. It involves setting up crop, soil, and weather inputs, toggling water-limited flags, and visualizing the results. ```R weather_file <- system.file("extdata/Philippines_IRRI.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) required_cols <- c("date", "srad", "tmin", "tmax", "prec", "wind", "vapr") print(all(required_cols %in% names(weather))) crop <- wofost_crop("maize_1") soil <- wofost_soil("ec3") control <- wofost_control() control$modelstart <- as.Date("1985-01-01") control$latitude <- 14.18 control$elevation <- 21 control$water_limited <- 1 control$watlim_oxygen <- 1 results_watlim <- wofost(crop, weather, soil, control) control$water_limited <- 0 results_pot <- wofost(crop, weather, soil, control) cat("Potential yield:", round(tail(results_pot$WSO, 1)), "kg/ha\n") cat("Water-limited yield:", round(tail(results_watlim$WSO, 1)), "kg/ha\n") ``` -------------------------------- ### POST /wofost Source: https://context7.com/cropmodels/rwofost/llms.txt Executes a single-point crop growth simulation based on provided crop, soil, weather, and control parameters. ```APIDOC ## POST /wofost ### Description Performs a time-series simulation of crop growth, returning daily state variables including biomass components and phenological stages. ### Method POST ### Endpoint /wofost ### Parameters #### Request Body - **crop** (object) - Required - Crop configuration object created via wofost_crop() - **weather** (data.frame) - Required - Daily weather data containing tmin, tmax, srad, prec, vapr, wind, and date - **soil** (object) - Required - Soil configuration object created via wofost_soil() - **control** (object) - Required - Simulation control parameters created via wofost_control() ### Request Example { "crop": "barley", "weather": "[data.frame]", "soil": "ec1", "control": {"modelstart": "1980-02-06", "latitude": 52.57} } ### Response #### Success Response (200) - **results** (data.frame) - Daily simulation values including DVS, LAI, WRT, WLV, WST, WSO, EVAP, TRAN #### Response Example { "date": "1980-06-01", "DVS": 1.5, "LAI": 4.2, "WSO": 3500 } ``` -------------------------------- ### POST /predict Source: https://context7.com/cropmodels/rwofost/llms.txt Executes a spatial crop growth simulation across a geographic area using raster datasets for weather and soil inputs. ```APIDOC ## POST /predict ### Description Runs spatial yield predictions by processing raster datasets for weather and soil, allowing for regional-scale agricultural monitoring. ### Method POST ### Endpoint /predict ### Parameters #### Request Body - **model** (object) - Required - Configured wofost_model object - **weather** (SpatRasterDataset) - Required - Daily weather layers (tmin, tmax, srad, prec, vapr, wind) - **mstart** (Date) - Required - Start date(s) for the simulation - **soils** (SpatRaster) - Required - Raster containing soil indices, depth, latitude, and elevation - **soiltypes** (list) - Required - List of soil configuration objects ### Request Example { "model": "[wofost_model_object]", "weather": "[SpatRasterDataset]", "mstart": "2020-03-01", "soils": "[SpatRaster]" } ### Response #### Success Response (200) - **results** (SpatRaster) - Yield map with one layer per start date #### Response Example { "status": "success", "output": "yield_map.tif" } ``` -------------------------------- ### Execute Single-Point Crop Simulation and Analyze Results Source: https://context7.com/cropmodels/rwofost/llms.txt Performs a complete crop growth simulation for a single location and extracts key phenological stages and biomass components. It demonstrates how to filter results by Development Stage (DVS) and visualize biomass accumulation over time. ```R library(Rwofost) library(meteor) weather <- read.csv(system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor")) weather$date <- as.Date(weather$date) crop <- wofost_crop("barley") soil <- wofost_soil("ec1") control <- wofost_control() control$modelstart <- as.Date("1980-02-06") control$latitude <- 52.57 control$elevation <- 50 results <- wofost(crop, weather, soil, control) emergence <- results[which.min(abs(results$DVS - 0)), ] anthesis <- results[which.min(abs(results$DVS - 1)), ] maturity <- results[which.min(abs(results$DVS - 2)), ] plot(results$date, results$WSO, type = "l", col = "gold", lwd = 2, xlab = "Date", ylab = "Biomass (kg/ha)", main = "Barley Biomass Partitioning") ``` -------------------------------- ### Load Crop Parameters with Rwofost Source: https://context7.com/cropmodels/rwofost/llms.txt Loads built-in or custom crop parameters for WOFOST simulations. It can list available crops, load specific crop data, and optionally include descriptive information. ```r available_crops <- wofost_crop("") print(available_crops) ``` ```r barley <- wofost_crop("barley") str(barley[1:10]) ``` ```r barley <- wofost_crop("barley", describe = TRUE) ``` -------------------------------- ### Run Water-limited Production Simulation and Plot Results Source: https://github.com/cropmodels/rwofost/blob/master/tests/_waterlimited.rmd This script iterates through a directory of test data, retrieves production parameters using the Rwofost package, and generates multi-panel plots for each variable. It includes a conditional check to skip cases involving vernalization. ```R library(Rwofost) source("pcse_tests.R") ydir <- "../ex_tests/test_data/" group <- "waterlimitedproduction" for (i in 1:44) { x <- getPR(ydir, group, i) if (is.null(x)) next par(mfrow=c(4,2), mai=c(.5,.75,.1,.1)) for (v in colnames(x$P)[-c(1,2)]) complot(x, v) print(paste(group, i)) } ``` -------------------------------- ### Run Single WOFOST Crop Growth Simulation Source: https://context7.com/cropmodels/rwofost/llms.txt Executes a single crop growth simulation using the wofost() function. It requires crop, weather, soil, and control parameters, returning a data frame of daily growth metrics such as LAI and biomass. ```R library(Rwofost) library(meteor) weather_file <- system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) crop <- wofost_crop("barley") soil <- wofost_soil("ec1") control <- wofost_control() control$modelstart <- as.Date("1980-02-06") control$latitude <- 52.57 control$elevation <- 50 results <- wofost(crop, weather, soil, control) head(results) plot(results$date, results$LAI, type = "l", xlab = "Date", ylab = "LAI (m²/m²)", main = "Barley Leaf Area Index Development") final_yield <- tail(results$WSO, 1) print(paste("Final yield:", round(final_yield), "kg/ha")) ``` -------------------------------- ### Run Water-Limited Production Simulation with Rwofost Source: https://context7.com/cropmodels/rwofost/llms.txt Initiates a crop growth simulation under water-limited conditions using the Rwofost package. This requires loading crop and soil parameters, configuring control settings, and ensuring necessary weather data is available. ```r library(Rwofost) library(meteor) ``` -------------------------------- ### Calculate and Plot Potential Production using Rwofost Source: https://github.com/cropmodels/rwofost/blob/master/tests/_potential.rmd This R code snippet iterates through a dataset to calculate potential production using the getPR function from the Rwofost package. It then generates plots for various parameters of the production data. Dependencies include the Rwofost library and a source file for helper functions. The input is a directory path and a group name, and the output is a series of plots visualizing production parameters. ```R library(Rwofost) source("pcse_tests.R") ydir <- "../ex_tests/test_data/" ydir <- "C:/github/cropmodels/Rwofost_test/test_data/" group <- "potentialproduction" for (i in 1:44) { x <- getPR(ydir, group, i) if (is.null(x)) next # skipping vernalization cases par(mfrow=c(4,2), mai=c(.5,.75,.1,.1)) for (v in colnames(x$P)[-c(1,2)]) complot(x, v) print(paste(group, i)) } ``` -------------------------------- ### Load Soil Parameters with Rwofost Source: https://context7.com/cropmodels/rwofost/llms.txt Loads soil parameters essential for water-limited production simulations. It supports listing available soils, loading specific soil types (e.g., 'ec1'), and viewing key parameters like wilting point and field capacity. ```r library(Rwofost) available_soils <- wofost_soil("") print(available_soils) ``` ```r soil <- wofost_soil("ec1") cat("Soil moisture at wilting point (SMW):", soil$SMW, "cm³/cm³\n") cat("Soil moisture at field capacity (SMFCF):", soil$SMFCF, "cm³/cm³\n") cat("Soil moisture at saturation (SM0):", soil$SM0, "cm³/cm³\n") cat("Maximum rooting depth (RDMSOL):", soil$RDMSOL, "cm\n") cat("Hydraulic conductivity (K0):", soil$K0, "cm/day\n") ``` ```r soil$SMTAB ``` -------------------------------- ### wofost - Run Crop Growth Simulation Source: https://context7.com/cropmodels/rwofost/llms.txt The main function to run a single WOFOST crop growth simulation. It takes crop parameters, weather data, soil parameters, and control settings to simulate daily crop growth from emergence to maturity. ```APIDOC ## wofost - Run Crop Growth Simulation ### Description Runs a single WOFOST crop growth simulation using provided crop, weather, soil, and control parameters. Returns daily simulation results. ### Method `wofost(crop, weather, soil, control)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```r library(Rwofost) library(meteor) # Load weather data weather_file <- system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) # Load crop and soil parameters crop <- wofost_crop("barley") soil <- wofost_soil("ec1") # Configure control parameters control <- wofost_control() control$modelstart <- as.Date("1980-02-06") control$latitude <- 52.57 control$elevation <- 50 # Run simulation results <- wofost(crop, weather, soil, control) # View output structure head(results) ``` ### Response #### Success Response (200) - **results** (data.frame) - A data frame containing daily simulation results, including LAI, biomass, and development stage. #### Response Example ``` date step Tsum DVS LAI WRT WLV WST WSO EVAP TRAN 1 1980-02-06 1 0.00 0.0000 0.2740 36.00 23.56 0.44 0.000 0.12 0.04 2 1980-02-07 2 2.35 0.0029 0.2742 36.78 23.66 0.56 0.000 0.10 0.05 ``` ``` -------------------------------- ### Visualize Assimilation Data with Rwofost Source: https://github.com/cropmodels/rwofost/blob/master/tests/_assimilation.rmd This script iterates through a directory of assimilation test files, retrieves data using internal Rwofost functions, and generates plots for the 'PGASS' variable. It is designed for batch processing of test data files. ```R library(Rwofost) ydir <- "../ex_tests/test_data/" group <- "assimilation" for (i in 1:44) { x <- Rwofost:::.getPR(ydir, group, i) Rwofost:::.complot(x, "PGASS") print(paste(group, i)); flush.console() } ``` -------------------------------- ### wofost_model - Create Reusable Model Object Source: https://context7.com/cropmodels/rwofost/llms.txt Creates a WOFOST model object that can be configured incrementally and run multiple times with different parameters. This is useful for sensitivity analyses or scenario comparisons. ```APIDOC ## wofost_model - Create Reusable Model Object ### Description Creates a WOFOST model object that can be configured and run multiple times. Allows for modification of parameters like sowing date or crop type between runs. ### Method `wofost_model(crop, weather, soil, control)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```r library(Rwofost) library(meteor) # Load weather data weather_file <- system.file("extdata/Netherlands_Swifterbant.csv", package = "meteor") weather <- read.csv(weather_file) weather$date <- as.Date(weather$date) # Create model object model <- wofost_model( crop = wofost_crop("barley"), weather = weather, soil = wofost_soil("ec1"), control = wofost_control() ) # Configure and run model$control$modelstart <- as.Date("1980-02-06") results1 <- run(model) # Modify and run again model$control$modelstart <- as.Date("1980-02-20") results2 <- run(model) # Change crop type and run crop(model) <- wofost_crop("potato_704") results3 <- run(model) ``` ### Response #### Success Response (200) - **model** (list) - A WOFOST model object that can be further configured and run using the `run()` function. #### Response Example ``` # The output is a model object, not a direct data structure like a table. # Example of accessing results after running: # results1 <- run(model) # head(results1) ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.