Title: | Design on-Farm Precision Field Agronomic Trials |
---|---|
Description: | A comprehensive system for designing and implementing on-farm precision field agronomic trials. You provide field data, tell 'ofpetrial' how to design a trial, and get readily-usable trial design files and a report checks the validity and reliability of the trial design. |
Authors: | Taro Mieno [aut, cre, cph] , Brittani Edge [aut, ctb] |
Maintainer: | Taro Mieno <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.1 |
Built: | 2024-11-12 05:28:18 UTC |
Source: | https://github.com/difm-brain/ofpetrial |
Delineate blocks on a trial design and assign block id to all the plots
add_blocks(td)
add_blocks(td)
td |
trial design made by applying assign_rates() to experimental plots made by make_exp_plots() |
trial design with block_id added
#--- load rate information ---# data(td_single_input) #--- add blocks ---# td_with_blocks <- add_blocks(td_single_input) #--- take a look ---# td_with_blocks$trial_design #--- visualize ---# viz(td_with_blocks, type = "block_id")
#--- load rate information ---# data(td_single_input) #--- add blocks ---# td_with_blocks <- add_blocks(td_single_input) #--- take a look ---# td_with_blocks$trial_design #--- visualize ---# viz(td_with_blocks, type = "block_id")
This functions assign input rates for the plots created by make_exp_plots() according to the rate designs specified by the user in rate_info, which can be created by prep_rateingle().
assign_rates(exp_data, rate_info)
assign_rates(exp_data, rate_info)
exp_data |
experiment plots created by make_exp_plots() |
rate_info |
rate information created by prep_rate() |
trial design as sf (experiment plots with rates assigned)
#--- load experiment plots made by make_exp_plots() ---# data(exp_data) exp_data #--- load rate information ---# data(rate_info) rate_info #--- assign rates ---# td <- assign_rates(exp_data, rate_info) #--- visualization of the assigned rates ---# viz(td)
#--- load experiment plots made by make_exp_plots() ---# data(exp_data) exp_data #--- load rate information ---# data(rate_info) rate_info #--- assign rates ---# td <- assign_rates(exp_data, rate_info) #--- visualization of the assigned rates ---# viz(td)
Change the assigned rates by plot and strip
change_rates( td, input_name = NA, strip_ids, plot_ids = NULL, new_rates, rate_by = "all" )
change_rates( td, input_name = NA, strip_ids, plot_ids = NULL, new_rates, rate_by = "all" )
td |
trial design |
input_name |
(character) input name |
strip_ids |
(numeric) vector of strip_ids |
plot_ids |
(numeric) vector of plot_ids |
new_rates |
(numeric) single numeric number for 'rate_by = "all"“, a vector of numeric values for 'rate_by = "strip"“, a matrix of numeric numbers for 'rate_by = "plot"'. |
rate_by |
(character) default is "all". The other options are "plot" and "strip". |
trial design with changed rates
#--- load rate information ---# data(td_single_input) #--- change rates of some strips ---# strip_ids <- 1:5 plot_ids <- 5:10 new_rates <- 200 td_modified <- change_rates(td_single_input, "NH3", strip_ids, plot_ids, new_rates) #--- visualize ---# viz(td_modified)
#--- load rate information ---# data(td_single_input) #--- change rates of some strips ---# strip_ids <- 1:5 plot_ids <- 5:10 new_rates <- 200 td_modified <- change_rates(td_single_input, "NH3", strip_ids, plot_ids, new_rates) #--- visualize ---# viz(td_modified)
Check the alignment of harvester and applicator/planter for mixed treatment problems where multiple input rates are associated with yield monitor data
check_alignment(td)
check_alignment(td)
td |
trial design data created by make_exp_plots() and assign_rates() |
a tibble
#--- load trial design ---# data(td_single_input) #--- check the alignment of harvester and applicator/planter ---# machine_alignment <- check_alignment(td_single_input) #--- check the degree of mixed treatment problem ---# machine_alignment$overlap_data #--- visualize the degree of mixed treatment problem ---# machine_alignment$g_overlap[[1]]
#--- load trial design ---# data(td_single_input) #--- check the alignment of harvester and applicator/planter ---# machine_alignment <- check_alignment(td_single_input) #--- check the degree of mixed treatment problem ---# machine_alignment$overlap_data #--- visualize the degree of mixed treatment problem ---# machine_alignment$g_overlap[[1]]
Check the correlation between the rates of the two inputs for a two-input experiment.
check_ortho_inputs(td)
check_ortho_inputs(td)
td |
trial design for a two-input experiment with rates assigned |
table
#--- load a trial design for a two-input experiment ---# data(td_two_input) #--- check correlation ---# check_ortho_inputs(td_two_input)
#--- load a trial design for a two-input experiment ---# data(td_two_input) #--- check correlation ---# check_ortho_inputs(td_two_input)
Check the orthogonality of the trial input rates and observed characteristics provided by the user
check_ortho_with_chars(td, sp_data_list, vars_list)
check_ortho_with_chars(td, sp_data_list, vars_list)
td |
(tibble) trial design data created by make_exp_plots() and assign_rates() |
sp_data_list |
(list) list of spatial datasets as 'sf' from the 'sf' package or 'SpatRaster' from the 'terra' package |
vars_list |
(list) list of character vectors indicating the name of the variables to be used in the datasets specified in sp_data_list |
a list
data(td_single_input) yield_sf <- sf::st_read(system.file("extdata", "yield-simple1.shp", package = "ofpetrial")) ssurgo_sf <- sf::st_read(system.file("extdata", "ssurgo-simple1.shp", package = "ofpetrial")) %>% dplyr::mutate(mukey = factor(mukey)) topo_rast <- c( terra::rast(system.file("extdata", "slope.tif", package = "ofpetrial")), terra::rast(system.file("extdata", "twi.tif", package = "ofpetrial")) ) checks <- check_ortho_with_chars( td = td_single_input, sp_data_list = list(yield_sf, ssurgo_sf, topo_rast), vars_list = list("Yld_Vol_Dr", c("mukey", "clay"), names(topo_rast)) ) checks$summary_data[[1]] checks$summary_fig[[1]]
data(td_single_input) yield_sf <- sf::st_read(system.file("extdata", "yield-simple1.shp", package = "ofpetrial")) ssurgo_sf <- sf::st_read(system.file("extdata", "ssurgo-simple1.shp", package = "ofpetrial")) %>% dplyr::mutate(mukey = factor(mukey)) topo_rast <- c( terra::rast(system.file("extdata", "slope.tif", package = "ofpetrial")), terra::rast(system.file("extdata", "twi.tif", package = "ofpetrial")) ) checks <- check_ortho_with_chars( td = td_single_input, sp_data_list = list(yield_sf, ssurgo_sf, topo_rast), vars_list = list("Yld_Vol_Dr", c("mukey", "clay"), names(topo_rast)) ) checks$summary_data[[1]] checks$summary_fig[[1]]
Data on the experiment created by running the 'make_exp_plot()' function, which includes various sf objects (e.g., experiment plots, ab-line, headland, etc). This data exists only for the purpose of making examples in some function references succinct.
exp_data
exp_data
tbl_df tbl data.frame 'exp_data' A data frame with 1 rows and 9 columns:
input name
width of the harvester
width of the plots to be made
field boundary as an sf object
headland as an sf object
experiment plots as an sf object
ab-lines for the applicator/planter as an sf object
ab-lines for the harvester as an sf object
(character) one of "free", "lock", "none" indicating the way ab-line is (or not) created
Make experimental plots/strips inside the field boundary, harvester ab-line, and applicator/planter ab-line.
make_exp_plots( input_plot_info, boundary_data, abline_data = NA, abline_type = "free" )
make_exp_plots( input_plot_info, boundary_data, abline_data = NA, abline_type = "free" )
input_plot_info |
(data.fram or a list of two data.frames) list of plot information created by make_input_plot() |
boundary_data |
(character) path of the field boundary file or boundary as an sf |
abline_data |
(character or sf) path of the ab-line file or ab-line as an sf |
abline_type |
(character) the type of ab-line generation. Select from "free", "lock", and "none" |
a tibble that include experimental plots as sf
n_plot_info <- prep_plot( input_name = "NH3", unit_system = "imperial", machine_width = 30, section_num = 1, harvester_width = 20, headland_length = 30, side_length = 60 ) exp_data <- make_exp_plots( input_plot_info = n_plot_info, boundary_data = system.file("extdata", "boundary-simple1.shp", package = "ofpetrial"), abline_data = system.file("extdata", "ab-line-simple1.shp", package = "ofpetrial"), abline_type = "free" ) exp_data$exp_plots
n_plot_info <- prep_plot( input_name = "NH3", unit_system = "imperial", machine_width = 30, section_num = 1, harvester_width = 20, headland_length = 30, side_length = 60 ) exp_data <- make_exp_plots( input_plot_info = n_plot_info, boundary_data = system.file("extdata", "boundary-simple1.shp", package = "ofpetrial"), abline_data = system.file("extdata", "ab-line-simple1.shp", package = "ofpetrial"), abline_type = "free" ) exp_data$exp_plots
This function creates an html report describing the trial design created by the user with assign_rates() and includes figures showing machine alignment
make_trial_report(td, folder_path, trial_name = NA, keep_rmd = FALSE)
make_trial_report(td, folder_path, trial_name = NA, keep_rmd = FALSE)
td |
trial design created by assign_rates() |
folder_path |
(character) path to the folder in which the report will be saved |
trial_name |
(character) name of trial to be used in report |
keep_rmd |
(logical) If FALSE (Default), the original rmd file will be deleted upon creating an html report. Otherwise, the rmd file will be saved in the folder specified by 'folder_path'. |
path to the resulting html file (invisible)
#--- load experiment made by assign_rates() ---# data(td_single_input) make_trial_report( td = td_single_input, folder_path = tempdir() )
#--- load experiment made by assign_rates() ---# data(td_single_input) make_trial_report( td = td_single_input, folder_path = tempdir() )
Plot information for creating experiment plots using 'make_exp_plot()'. This data exists only for the purpose of making examples in some function references succinct.
plot_info
plot_info
data.frame 'plot_info' A data frame with 1 rows and 10 columns:
input name
measurement system (metric or imperial)
width of the applicator/planter
number of the sections of the machine
width of a section of the machine
width of the harvester
width of the plots to be made
length of the headland
length of the side
minimum plot length allowed
maximum plot length allowed
Prepare plot information for a single-input experiment case. All the length values need to be specified in meter.
prep_plot( input_name, unit_system, machine_width, section_num, harvester_width, plot_width = NA, headland_length = NA, side_length = NA, max_plot_width = NA, min_plot_length = NA, max_plot_length = NA )
prep_plot( input_name, unit_system, machine_width, section_num, harvester_width, plot_width = NA, headland_length = NA, side_length = NA, max_plot_width = NA, min_plot_length = NA, max_plot_length = NA )
input_name |
(character) Input name |
unit_system |
(character) A character of either 'metric' or 'imperial' indicating the system of measurement used |
machine_width |
(numeric) A numeric number in units specified in unit_system that indicates the width of the applicator or planter of the input |
section_num |
(numeric) A numeric number that indicates the number of sections of the applicator or planter of the input |
harvester_width |
(numeric) A numeric number that indicates the width of the harvester |
plot_width |
(numeric) Default is c(NA, NA). |
headland_length |
(numeric) A numeric number that indicates the length of the headland (how long the non-experimental space is in the direction machines drive). Default is NA. |
side_length |
(numeric) A numeric number that indicates the length of the two sides of the field (how long the non-experimental space is in the direction perpendicular to the direction of machines). Default is NA. |
max_plot_width |
(numeric) Maximum width of the plots. Default is 36.576 meter (120 feet). |
min_plot_length |
(numeric) Minimum length of the plots. Default is 73.152 meter (240 feet). |
max_plot_length |
(numeric) Maximum length of the plots. Default is 91.440 meter (300 feet) |
a tibble with plot information necessary to create experiment plots
input_name <- "seed" unit_system <- "metric" machine_width <- 12 section_num <- 12 plot_width <- NA harvester_width <- 24 prep_plot(input_name, unit_system, machine_width, section_num, harvester_width)
input_name <- "seed" unit_system <- "metric" machine_width <- 12 section_num <- 12 plot_width <- NA harvester_width <- 24 prep_plot(input_name, unit_system, machine_width, section_num, harvester_width)
Create data of input rate information for a single input with some checks on the validity of the information provided by the user. This can be used to assign rates to experiment plots using assign_rates().
prep_rate( plot_info, gc_rate, unit, rates = NULL, min_rate = NA, max_rate = NA, num_rates = 5, design_type = NA, rank_seq_ws = NULL, rank_seq_as = NULL, rate_jump_threshold = NA )
prep_rate( plot_info, gc_rate, unit, rates = NULL, min_rate = NA, max_rate = NA, num_rates = 5, design_type = NA, rank_seq_ws = NULL, rank_seq_as = NULL, rate_jump_threshold = NA )
plot_info |
(data.frame) plot information created by make_input_plot_data |
gc_rate |
(numeric) Input rate the grower would have chosen if not running an experiment. This rate is assigned to the non-experiment part of the field. This rate also becomes one of the trial input rates unless you specify the trial rates directly using rates argument |
unit |
(string) unit of input |
rates |
(numeric vector) Default is NULL. Sequence of trial rates in the ascending order. |
min_rate |
(numeric) minimum input rate. Ignored if rates are specified. |
max_rate |
(numeric) maximum input rate. Ignored if rates are specified |
num_rates |
(numeric) Default is 5. It has to be an even number if design_type is "ejca". Ignored if rates are specified. |
design_type |
(string) type of trial design. available options are Latin Square ("ls"), Strip ("str"), Randomized Strip ("rstr"), Randomized Block ("rb"), Sparse ("sparse"), and Extra Jump-conscious Alternate "ejca". See the article on trial design for more details. |
rank_seq_ws |
(integer) vector of integers indicating the order of the ranking of the rates, which will be repeated "within" a strip. |
rank_seq_as |
(integer) vector of integers indicating the order of the ranking of the rates, which will be repeated "across" strip for their first plots. |
rate_jump_threshold |
(integer) highest jump in rate rank acceptable |
data.frame of input rate information
plot_info <- prep_plot( input_name = "seed", unit_system = "imperial", machine_width = 60, section_num = 24, harvester_width = 30, plot_width = 30 ) prep_rate( plot_info, gc_rate = 30000, unit = "seeds", rates = c(20000, 25000, 30000, 35000, 40000) )
plot_info <- prep_plot( input_name = "seed", unit_system = "imperial", machine_width = 60, section_num = 24, harvester_width = 30, plot_width = 30 ) prep_rate( plot_info, gc_rate = 30000, unit = "seeds", rates = c(20000, 25000, 30000, 35000, 40000) )
Rate information for assigning rates to the experiment plots using the 'assign_rates()' function. This data exists only for the purpose of making examples in some function references succinct.
rate_info
rate_info
data.frame 'rate_info' A data frame with 1 rows and 7 columns:
input name
type of the trial design to be created
normal rate the grower would have used if not running an experiment
unit of the input
data.frame of rates and their ranks
vector of the ranking of rates that will repeated within a strip
vector of the ranking of rates that will repeated as the first rate of the strips
Trial design data created by assigning rates to experiment plots running the 'assign_rates()' function. This data exists only for the purpose of making examples in some function references succinct.
td_curved
td_curved
tbl_df tbl data.frame 'td_curved' A data frame with 1 rows and 9 columns:
input name
shorthand for the type of the input: "N" for nitrogen, "S" for seed, etc.
experiment plots with input rats assigned as an sf object
type of the trial design used
unit of the input
(character) one of "free", "lock", "none" indicating the way ab-line is (or not) created
ab-lines for the applicator/planter as an sf object
ab-lines for the harvester as an sf object
field boundary as an sf object
width of the harvester
Trial design data created by assigning rates to experiment plots running the 'assign_rates()' function. This data exists only for the purpose of making examples in some function references succinct.
td_single_input
td_single_input
tbl_df tbl data.frame 'td_single_input' A data frame with 1 rows and 9 columns:
input name
shorthand for the type of the input: "N" for nitrogen, "S" for seed, etc.
experiment plots with input rats assigned as an sf object
type of the trial design used
unit of the input
(character) one of "free", "lock", "none" indicating the way ab-line is (or not) created
ab-lines for the applicator/planter as an sf object
ab-lines for the harvester as an sf object
field boundary as an sf object
width of the harvester
Trial design data created by assigning rates to experiment plots running the 'assign_rates()' function. This data exists only for the purpose of making examples in some function references succinct.
td_two_input
td_two_input
tbl_df tbl data.frame 'td_two_input' A data frame with 1 rows and 9 columns:
input name
shorthand for the type of the input: "N" for nitrogen, "S" for seed, etc.
experiment plots with input rats assigned as an sf object
type of the trial design used
unit of the input
(character) one of "free", "lock", "none" indicating the way ab-line is (or not) created
ab-lines for the applicator/planter as an sf object
ab-lines for the harvester as an sf object
field boundary as an sf object
width of the harvester
Create plots of experiment rates, plot layout, plot_id, strip_id, and block_id, which can be specified by the 'type' argument.
viz( td, type = "rates", input_index = c(1, 2), text_size = 3, abline = FALSE, leaflet = FALSE )
viz( td, type = "rates", input_index = c(1, 2), text_size = 3, abline = FALSE, leaflet = FALSE )
td |
(tibble) experiment plots made by make_exp_plots() |
type |
(character) type of plots to create. Available options are "rates", "layout", "plot_id", "strip_id", "block_id", "ab_line" |
input_index |
(numeric) a vector of length 1 or 2. 1 means the 1st input of the td, 2 means the second input of the td, and c(1, 2) means both of the inputs, which is the DEFAULT |
text_size |
(numeric) the size of plot ID, strip ID, and block ID numbers printed in the plots |
abline |
(logical) If TRUE, ab-lines are displayed as well. Default = FALSE. This applies only ton type = "rates" and type = "layout". |
leaflet |
(logical) If TRUE, the plot will be superimposed on a satellite imagery of the field. Default is FALSE. This option is effective only for type = "rates". |
ggplot or leaflet (if leaflet == TRUE) object
#--- load trial design ---# data(td_two_input) viz(td_two_input)
#--- load trial design ---# data(td_two_input) viz(td_two_input)
Write out all the necessary files to implement the trial design created. Exported files include
write_trial_files(td, folder_path, ext = "shp", zip = FALSE, zip_name = NA)
write_trial_files(td, folder_path, ext = "shp", zip = FALSE, zip_name = NA)
td |
(tibble) a tibble of a trial design created by applying assign_rate() to experimental plots made by make_exp_plots(). |
folder_path |
(character) path to the folder in which the files will be saved |
ext |
(character) Default = "shp". Extension to use to save the files, "geojson" or any other extension supported by sf::st_write() |
zip |
(logical) Default = FALSE. If TRUE, all the files that are being written will be zipped. |
zip_name |
(character) name of the zip file created when zip = TRUE. |
nothing
#--- load trial design ---# data(td_two_input) write_trial_files( td = td_two_input, folder_path = tempdir(), zip = FALSE )
#--- load trial design ---# data(td_two_input) write_trial_files( td = td_two_input, folder_path = tempdir(), zip = FALSE )