RxClass | R Documentation |
R6 class for for creating a prescription or experiment for a field of interest. The user can create a new experiment with inputs randomly applied across the field with no stratification, or select data from the database on which to stratify experimental rates. Alternatively the user can create a prescription or experimental prescription based on the optimized rates from the user selected management scenario for given economic and weather conditions. This process builds off of the simulation R6 class (SimClass), where the Monte Carlo simulation for a year or year(s) the user thinks the upcoming year is going to resemble, with the user specified economic data, is used for identifying the optimum rates for each management strategy at each part.
If the user decides to do an experimental prescription, the optimum rates of the user specified management scenario from the simulation is used as the base map for the experimental prescription. Experimental rates can be generated from gaps in the optimum rates to create a distribution of rates across the field to be used for fitting crop response models in upcoming years, or from user specified experimental rates. These are then randomly applied to the field according to user specified proportions for each rate, stratified on the optimum rates.
If the user decides to make an OFPE prescription with no experiment, the optimum rates for each point for the user specified management scenario is taken as the prescription. Instead of applying experimental rates, a farmer selected rate representing the rate they would have applied is randomly placed across the field, stratified on the optimum rates. These are used as a check to evaluate the performance of the optimized rates or whether further experimentation is needed.
When creating an experimental prescription or a prescription, the user must pass a set up SimClass. This implies that the user has initialized and set up the required DatClass, ModClass, and EconDat R6 objects. The user must pass a SimClass object that has been executed. This simulation output data is used to generate the experimental prescriptions and the prescriptions.
If the user allows, the prescriptions or experiments are saved to the 'Outputs' folder and are saved in the OFPE database in the farmer specific aggregated schema in a table called 'rx' (farmername_a.rx).
dbCon
Database connection object connected to an OFPE formatted database, see DBCon class.
gen_type
What type of output to generate; 'NewExp_NoStrat' for a new experiment with randomly placed experimental rates with no stratification, 'NewExp_wStrat' for a new experiment with randomly placed experimental rates stratified on user specified data, 'ExpRx' for a experimental rates randomly placed, stratified on the optimum rates from the user selected prescription, or 'Rx' where the prescription is output to the user, with check rates of a farmer selected base rate randomly placed, stratified on optimum rates.
trt_length
Length, given in feet and converted to meters, for which to apply treatments.
trt_width
The width of the treatment blocks. Should be a multiple of the sprayer boom or spreader width, given as feet (converted to meters).
heading
Numeric, heading in degrees from true north to rotate the experiment/prescription to. Default is 0 (no rotation). Note that if a heading is provided, the grid is trimmed based on the buffered boundary but rotation caused by providing a heading may skew treatment rates so that they encroach into the cleanup strip.
fld_prop
The proportion of the field to apply experimental rates to (i.e. 0.5 or 1.0), OR, the percent of available cells to apply check rates to (i.e. 0.05, 0.1).
conv
The conversion factor between lbs of the input to the units of the as-applied input (i.e. lbs N/ac to unit input/ac)
base_rate
The rate to apply between the experimental rates and the field edge, or as check rates in the prescription selected option.
rx_years
The year or vector of years to base the prescription off of. If the user passes in multiple years, the average optimum rate from the simulations will be used. If the user has passed in a SimClass object where the simulation has been executed, the RxClass will check the output data to avoid redundantly running a simulation.
rx_for_year
Provide the year that the prescription or experiment is made for. Used for labeling outputs.
SAVE
Logical, whether to save figures and the experiment or prescription. Autofilled to FALSE if a user selects NA in the 'out_path' or is NULL. Autofilled to TRUE otherwise. If not applied and a SimClass object has been supplied, the selected option in that class will be used.
out_path
Provide the path to the folder in which to store and save figures and the prescription Type NA to not create any folders. You will not be able to save any outputs. (Note, even if a path is provided, the user can pass FALSE as the sole argument to the 'setupOP' method to prevent the creation of folders. This will automatically prevent any plots to be saved.). If not applied and a SimClass object has been supplied, the selected option in that class will be used.
to_DB
Logical, whether to save the prescription or experiment into the database.
farmername
If the user is creating a new experiment, provide or select the name of the farmer that owns or manages the field(s) that an experiment is going to be generated for.
fieldname
If the user is creating a new experiment, provide or select the fieldname of the field to use. The field list is from the available fields in the database for experimentation.
exp_rate_length
Provide the length of experimental rates to apply. This applies to new experiments and experimental prescriptions. This represents the equipment constraints of the farmer. In the case of the experimental prescription, this number of rates does not include the number of rates for the optimized base map, so take your selections for the management scenario and number of optimum rates into account.
exp_rates
Provide a vector of experimental rates equal to the number of experimental rates provided in 'exp_rate_length'. This is required for all new experiments, however can be left to null for experimental prescriptions if experimental rates should be generated based on gaps in optimum rates.
exp_rates_prop
Provide proportions (0 - 1) for the length of experimental rates provided in 'exp_rate_length'. This is required for all new experiments and experimental prescriptions.
strat_dat_parms
Named list by fieldname that contains a list for each field containing named slots for 'table', 'grid_size', 'path', 'year', and 'col_name' to define the stratification data to use for randomly applying experimental rates. Set named slots to NA for any fields that you don't want to make stratified rates on. You can stratify on multiple variables per field, with priority given by order. Each of the sublist slots for each field must have the same dimensions. Note that more stratification variables increases processing times.
The table ('table') indicates the location within the database that the stratification data is stored in. This can either be from an aggregated table ('yld', 'pro', or 'sat') or can be from a raw table. Simply specify the table name and the schema will be derived from the farmername. For data from an aggregated table, the user must also provide the size ('grid_size') of the grid cells used to aggregate the data the user desires in the aggregated dataset (i.e. 10, 30 meters). This is a numeric variable and if stratifying on raw data, this parameter can be left NA. Conversely, if you are stratifying on raw data, an additional parameter called 'path' needs to be supplied in a named slot of each field's sublist to specify the original filename of the data imported into the database. If the desired data is from an aggregated table than enter NA for the 'path'. The year of the desired data must also be provided ('year'). This is to specify which data in the aggregated table to use. If using raw data, the year is automatically derived from the data specified by the filename. Finally, the user must supply the column name ('col_name') of the variable to stratify on. This must be supplied for both raw and aggregated data.
simClass
If the user is creating an experimental prescription or prescription an R6 class SimClass object must be supplied. This has to be set up. The RxClass will check the SimClass for simulation output data from which years(s) can be selected from.
exp_rate_gen
Logical, for the experimental prescription provide TRUE or FALSE for whether to create experimentla rates from gaps in the optimized rates. These experimental rates are placed between optimum rates to establish a range of rates for which to improve model predictions in future years.
opt_rate_length
Provide the number of oprimum rates to use. This applies to prescriptions and experimental prescriptions. This represents the equipment constraints of the farmer. In the case of the experimental prescription, this number of rates does not include the number of experimental rates, so take your selections for the management scenario and number of experimental rates into account.
mgmt_scen
If the user is creating a prescription or experimental prescription, they must provide the management scenario to use for their prescription. The user can choose from the management options listed in the SimClass. The options are 'SSOPT': site-specific optimized rates, 'FFOPT': full-field optimum uniform rate, 'FS': farmer selected uniform rate, 'Min': applying the least intensive input rates (i.e. 0 lbs N/ac, or 25 lbs seed/ac), 'Opp' is omitted because this strategy is the least intensive input rate in conventional system types, and the farmer selected rate for organic systems, both of which are already provided.
expvar
Experimental variable to optimize, select/input 'As-Applied Nitrogen' or 'As-Applied Seed Rate'. This is the type of input that is experimentally varied across the field as part of the on-farm experimentation.
min_app_rate
The minimum as-applied rate that the equipment can apply. This must be in the units of the input applied to the field, which is not necessarily the same as the experimental input. This is an equipment restriction specific to the farmer.
buffer_width
The width of the buffer from the field edge within which to place experiments or prescriptions. Provided by the user in feet and converted to meters internally.
min_rate_jumps
Optional, supply either 'N/S' or 'E/W' to indicate direction in which to minimize rate jumps. This is the predominant direction that the experimental input is applied across the field. This function minimizes the difference in rates between adjacent treatments for easier use on the equipment. Note that this will eradicate any randomization/optimization of rates and will partially or completely remove stratification. This function makes sure that the rates do not vary by more than 2 rate levels in the direction specified. Default is NULL, which prevents execution. This will not guarantee eradication of all rate jumps, but will reduce the amount.
out_gen
An output generator R6 class (i.e. ExpGen or RxGen), that produces the output specified by the user. There are different classes with different required arguments based on whether the user is setting up a new experiment or creating a prescription. These are automatically called by this 'SetupGen' method.
new()
Initializing this class can be performed independent or after running the analysis and simulation step of the OFPE data cycle. If the user is creating a new experiment for a field, they should initialize the class with the arguments specified in the documentation for that method. It is recommended that the user uses the interactive setup method rather than passing in arguments, unless an experienced user. For new experiments, the user will not require a set up SimClass object, however if creating a prescription or experimental prescription the user will need to pass in a set up and/or executed SimClass R6 class, EVEN IF using the interactive methods.
RxClass$new( dbCon, simClass = NULL, gen_type = NULL, trt_length = NULL, trt_width = NULL, heading = 0, fld_prop = NULL, conv = NULL, base_rate = NULL, rx_years = NULL, rx_for_year = NULL, out_path = NULL, SAVE = NULL, to_DB = NULL, fieldname = NULL, farmername = NULL, exp_rate_length = NULL, exp_rates = NULL, exp_rates_prop = NULL, strat_dat_parms = NULL, exp_rate_gen = NULL, opt_rate_length = NULL, mgmt_scen = NULL, expvar = NULL, min_app_rate = NULL, buffer_width = 0, min_rate_jumps = NULL )
dbCon
Database connection object connected to an OFPE formatted database, see DBCon class.
simClass
If the user is creating an experimental prescription or prescription an R6 class SimClass object must be supplied. This has to be set up and simulations from years that the user expects the upcoming year will be like must be executed.
gen_type
What type of output to generate; 'NewExp_NoStrat' for a new experiment with randomly placed experimental rates with no stratification, 'NewExp_wStrat' for a new experiment with randomly placed experimental rates stratified on user specified data, 'ExpRx' for a experimental rates randomly placed, stratified on the optimum rates from the user selected prescription, or 'Rx' where the prescription is output to the user, with check rates of a farmer selected base rate randomly placed, stratified on optimum rates.
trt_length
Length, in feet, for which to apply treatments.
trt_width
The width, in feet, for which to apply treatments.
heading
Numeric, heading in degrees from true north to rotate the experiment/prescription to. Default is 0 (no rotation). Note that if a heading is provided, the grid is trimmed based on the buffered boundary but rotation caused by providing a heading may skew treatment rates so that they encroach into the cleanup strip.
fld_prop
The proportion of the field to apply experimental rates to (i.e. 0.5 or 1.0), OR, the percent of available cells to apply check rates to (i.e. 0.05, 0.1).
conv
The conversion factor between lbs of the input to the units of the as-applied input (i.e. lbs N/ac to unit input/ac)
base_rate
The rate to apply between the experimental rates and the field edge, or as check rates in the prescription selected option.
rx_years
The year or vector of years to base the prescription off of. If the user passes in multiple years, the average optimum rate from the simulations will be used. If the user has passed in a SimClass object where the simulation has been executed, the RxClass will check the output data to avoid redundantly running a simulation.
rx_for_year
Provide the year that the prescription or experiment is made for. Used for labeling outputs.
out_path
Provide the path to the folder in which to store and save figures and the prescription Type NA to not create any folders. You will not be able to save any outputs. (Note, even if a path is provided, the user can pass FALSE as the sole argument to the 'setupOP' method to prevent the creation of folders. This will automatically prevent any plots to be saved.). If not applied and a SimClass object has been supplied, the selected option in that class will be used.
SAVE
Logical, whether to save figures and the experiment or prescription. Autofilled to FALSE if a user selects NA in the 'out_path' or is NULL. Autofilled to TRUE otherwise. If not applied and a SimClass object has been supplied, the selected option in that class will be used.
to_DB
Logical, whether to save the prescription or experiment into the database.
fieldname
If the user is creating a new experiment, provide or select the fieldname of the field to use. The field list is from the available fields in the database for experimentation.
farmername
If the user is creating a new experiment, provide or select the name of the farmer that owns or manages the field(s) that an experiment is going to be generated for.
exp_rate_length
Provide the length of experimental rates to apply. This applies to new experiments and experimental prescriptions. This represents the equipment constraints of the farmer. In the case of the experimental prescription, this number of rates does not include the number of rates for the optimized base map, so take your selections for the management scenario and number of optimum rates into account.
exp_rates
Provide a vector of experimental rates equal to the number of experimental rates provided in 'exp_rate_length'. This is required for all new experiments, however can be left to null for experimental prescriptions if experimental rates should be generated based on gaps in optimum rates.
exp_rates_prop
Provide proportions (0 - 1) for the length of experimental rates provided in 'exp_rate_length'. This is required for all new experiments and experimental prescriptions.
strat_dat_parms
Named list by fieldname that contains a list for each field containing named slots for 'table', 'grid_size', 'path', 'year', and 'col_name' to define the stratification data to use for randomly applying experimental rates. You can stratify on multiple variables per field, with priority given by order. Each of the sublist slots for each field must have the same dimensions. Note that more stratification variables increases processing times.
The table ('table') indicates the location within the database that the stratification data is stored in. This can either be from an aggregated table ('yld', 'pro', or 'sat') or can be from a raw table. Simply specify the table name and the schema will be derived from the farmername. For data from an aggregated table, the user must also provide the size ('grid_size') of the grid cells used to aggregate the data the user desires in the aggregated dataset (i.e. 10, 30 meters). This is a numeric variable and if stratifying on raw data, this parameter can be left NA. Conversely, if you are stratifying on raw data, an additional parameter called 'path' needs to be supplied in a named slot of each field's sublist to specify the original filename of the data imported into the database. If the desired data is from an aggregated table than enter NA for the 'path'. The year of the desired data must also be provided ('year'). This is to specify which data in the aggregated table to use. If using raw data, the year is automatically derived from the data specified by the filename. Finally, the user must supply the column name ('col_name') of the variable to stratify on. This must be supplied for both raw and aggregated data.
exp_rate_gen
Logical, for the experimental prescription provide TRUE or FALSE for whether to create experimental rates from gaps in the optimized rates. These experimental rates are placed between optimum rates to establish a range of rates for which to improve model predictions in future years.
opt_rate_length
Provide the number of optimum rates to use. This applies to prescriptions and experimental prescriptions. This represents the equipment constraints of the farmer. In the case of the experimental prescription, this number of rates does not include the number of experimental rates, so take your selections for the management scenario and number of experimental rates into account.
mgmt_scen
If the user is creating a prescription or experimental prescription, they must provide the management scenario to use for their prescription. The user can choose from the management options listed in the SimClass. The options are 'SSOPT': site-specific optimized rates, 'FFOPT': full-field optimum uniform rate, 'FS': farmer selected uniform rate, 'Min': applying the least intensive input rates (i.e. 0 lbs N/ac, or 25 lbs seed/ac), 'Opp' is omitted because this strategy is the least intensive input rate in conventional system types, and the farmer selected rate for organic systems, both of which are already provided.
expvar
Experimental variable to optimize, select/input 'As-Applied Nitrogen' or 'As-Applied Seed Rate'. This is the type of input that is experimentally varied across the field as part of the on-farm experimentation.
min_app_rate
The minimum as-applied rate that the equipment can apply. This must be in the units of the input applied to the field, which is not necessarily the same as the experimental input. This is an equipment restriction specific to the farmer.
buffer_width
The width of the buffer from field edge for experiments or prescriptions (feet).
min_rate_jumps
Optional, supply either 'N/S' or 'E/W' to indicate direction in which to minimize rate jumps. This is the predominant direction that the experimental input is applied across the field. This function minimizes the difference in rates between adjacent treatments for easier use on the equipment. Note that this will eradicate any randomization/optimization of rates and will partially or completely remove stratification. This function makes sure that the rates do not vary by more than 2 rate levels in the direction specified. Default is NULL, which prevents execution. This will not guarantee eradication of all rate jumps, but will reduce the amount.
An initialized RxClass R6 class object.
selectInputs()
Interactive method for selecting inputs related to the prescription or experiment generation process. It is recommended to use this interactive method rather than passing in inputs as arguments unless an experienced user. If the user is creating an experimental prescription or prescription, they must have set up this class with a SimClass object, even if using this interactive method for selecting other inputs.
The user first selects whether to make a prescription or experiment. If the user specifies a type and has not passed in a required input upon initialization, an error will be thrown. Based on the user specification different selections are required for the user to set up the generation method.
The user will have to select the treatment length and width, the heading to align the treatments relative to N/S, the base rate to apply to around experiments or for checks in the prescription, the year(s) the farmer thinks the upcoming year will resemble and to make the prescription for, and whether to save the prescription or experiment in the database.
RxClass$selectInputs()
None
No arguments needed because passed in during class instantiation.
A 'RxClass' object with complete user selections.
setupOP()
Method used to setup the output location for the prescription and related figures.
RxClass$setupOP(create = TRUE)
create
Logical, whether to create folders for output. If not, no plots will be saved by default.
A folder created in the path for model output figures.
setupGen()
Method used to setup the experiment or prescription generator based on the user select 'gen_type'. This initializes the output generator selected by the user with the arguments needed for that generator.
RxClass$setupGen()
rxClass
rxClass R6 class object. This method passes it's own class instantiation into the generator class.
An instantiated output generator class.
executeOutGen()
Method for calling the execution method of the experiment or prescription generator. These call the methods in the generator R6 classes.
RxClass$executeOutGen()
None
All parametes supplied upon initialization.
A completed experiment or prescription.
saveOutputs()
Method for saving prescriptions or experiments and related plots. This only save plots if the user has supplied a folder path to save the plots to, and if the user does not select SAVE == FALSE. If the user passes in an argument to SAVE, this replaces any previously selected SAVE option (e.g. if SAVE was set to TRUE in the class initialization and the user passes FALSE as an argument here, the class' selection for SAVE is set to FALSE from TRUE).
RxClass$saveOutputs(SAVE = NULL, to_DB = NULL)
SAVE
Whether to save diagnostic plots. If NULL uses the user selected choice. If not NULL and is logical, argument replaces previously set SAVE options for the entire class.
to_DB
Logical, whether to save the prescription or experiment into the database. If NULL uses the user selected choice. If not NULL and is logical, argument replaces previously set to_DB options for the entire class.
Shapefile and map saved in 'Outputs' folder and in database.
plotRxMap()
This method is for plotting maps of simulation outcomes. These include the net-returns from the management strategies, predicted responses, and optimized rates. Is a wrapper to a private plotRxMap method.
RxClass$plotRxMap(SAVE = TRUE)
SAVE
Logical, whether to save figure.
Maps saved in 'Outputs/Rx/' and/or returned.
plotCellTypeMap()
This method is for plotting a map showing the distribution of cell types. This shows which cells are the optimized or management scenario rates, which are experimental rates, and where base rates are applied.
RxClass$plotCellTypeMap(SAVE = TRUE)
SAVE
Logical, whether to save figure.
Maps saved in 'Outputs/Rx/' and/or returned.
uploadRxFun()
This method is for uploading the experiment or prescription to the database.
RxClass$uploadRxFun( RX, db, farmername, fieldname, rx_year, size, mgmt_scen, dtype = "rx_poly" )
RX
Data frame with the net-returns and experimental optimums for every point for every simulation iteration.
db
Database connection connected to an OFPE formatted database.
farmername
The name of the farmer that manages the field.
fieldname
Unique field name corresponding to all fields used in the simulation.
rx_year
Provide the year that the prescription or experiment is made for. Used for labeling outputs.
size
The size of the treatment zones, which is the treatment width x the treatment length.
mgmt_scen
If the user is creating a prescription or experimental prescription, they must provide the management scenario to use for their prescription. The user can choose from the management options listed in the SimClass. The options are 'SSOPT': site-specific optimized rates, 'FFOPT': full-field optimum uniform rate, 'FS': farmer selected uniform rate, 'Min': applying the least intensive input rates (i.e. 0 lbs N/ac, or 25 lbs seed/ac), 'Opp' is omitted because this strategy is the least intensive input rate in conventional system types, and the farmer selected rate for organic systems, both of which are already provided. This is set to 'exp' for all new experiments.
dtype
The data type of the data for upload to the database, default to 'rx'.
Output experiment or prescription saved in database.
clone()
The objects of this class are cloneable with this method.
RxClass$clone(deep = FALSE)
deep
Whether to make a deep clone.
DBCon
for the database connection class,
SimClass
for the class that contains simulation outputs,
ExpGen
for the class for creating new experiments, and
RxGen
for the class that creates experimental prescriptions
or pure prescriptions.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.