RxGen: R6 Class for generating a OFPE prescriptions or experimental...

RxGenR Documentation

R6 Class for generating a OFPE prescriptions or experimental prescriptions

Description

R6 class for for creating a prescription or experimental prescription for a field of interest. 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 an 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 select the years that the farmer thinks the upcoming year will resemble and generate the experimental prescriptions and the prescriptions.

This class follows the generator interface that includes an initialization method and an 'executeOutput' method.

Public fields

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, however does not need to have the execution method performed. The RxClass will check the SimClass for simulation output data that matches the year of the data provided, and execute simulations for any years not present.

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.

trt_length

Length, in meters, for which to apply treatments.

trt_width

Width, in meters, 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.

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.

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 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.

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.

fld_prop

The percent of available cells to apply check rates to (i.e. 0.05, 0.1).

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.

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.

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.

unique_fieldname

Unique fieldname for the field(s) used for the experiment. This concatenates multiple fields with an ampersand. Used for labelling.

rx_dt

Data frame that contains the coordinates of locations to apply experimental inputs. For an experiment, these are the centroids of the grid made to aggregate data for the field.

RX

Table containing the geographic locations of the experiment. Also contains the rates in the experimental and as-applied units. This can be saved as a shapefile and given to the equipment applying the input.

out_name

Created parameter for the file name of the prescription data, used for saving the data to the 'Outputs' folder.

out_map_name

Created parameter with the file name for the map of the prescription. Used for saving the map to the 'Outputs' folder.

cell_out_map_name

Created parameter with the file name for the map of the rate type applied to each cell. Used for saving the map to the 'Outputs' folder.

var

The label of the variable to map. Used in figure labelling for plotting in RxClass.

var_col_name

The name of the column of the variable in the supplied data ('dat'). Used in figure labelling for plotting in RxClass.

var_label

The label to be applied to the legend of the map corresponding to the variable mapped. Used in figure labelling for plotting in RxClass.

var_main_label

The main label to apply to the map. Used in figure labelling for plotting in RxClass.

size

The size of the treatment zones, which is the treatment width x the treatment length.

Methods

Public methods


Method new()

It is recommended to initialize this class through the RxClass, because it is integrated into the OFPE workflow. This also ensures all of the inputs are in the correct format and present.

Usage
RxGen$new(
  dbCon,
  simClass = NULL,
  mgmt_scen,
  trt_length,
  trt_width,
  heading = 0,
  expvar,
  conv,
  base_rate,
  rx_years,
  rx_for_year,
  out_path = NULL,
  SAVE,
  opt_rate_length,
  fld_prop,
  buffer_width = 0,
  min_rate_jumps = NULL,
  exp_rate_gen = NULL,
  exp_rate_length = NULL,
  exp_rates = NULL,
  exp_rates_prop = NULL
)
Arguments
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 class is queried for relevant information, most importantly, a path the the output data.

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.

trt_length

Length, in meters, for which to apply treatments.

trt_width

Width, in meters, 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.

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.

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 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.

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.

fld_prop

The percent of available cells to apply check rates to (i.e. 0.05, 0.1).

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.

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. Not needed if pure prescription.

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. Not needed if pure prescription.

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. Not needed if pure prescription.

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. Not needed if pure prescription.

Returns

An initialized RxGen R6 class object.


Method executeOutput()

Method for calling the execution method of the experiment generator. This applies the prescription/experimental rates across the field. Check rates are stratified across prescription/experimental rates for representative checks.

Usage
RxGen$executeOutput()
Arguments
None

All parameters supplied upon initialization.

Returns

A completed experiment table containing the output.


Method clone()

The objects of this class are cloneable with this method.

Usage
RxGen$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

DBCon for the database connection class, SimClass for the class that contains simulation outputs, and ExpGen for the alternative class that creates new experiments.


paulhegedus/OFPE documentation built on Nov. 23, 2022, 5:09 a.m.