ExpGen: R6 Class for generating a OFPE experiments

ExpGenR Documentation

R6 Class for generating a OFPE experiments

Description

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 on which to stratify experimental rates. This class randomly places experimental input rates across a field(s) selected from the database, with the user's choice for stratification.

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.

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.

fld_prop

The proportion of the field to apply experimental or optimum check rates to.

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_for_year

Provide the year that the experiment is made for. Used for labeling outputs.

SAVE

Logical, whether to save figures and the experiment. Autofilled to FALSE if a user selects NA in the 'out_path' or is NULL. Autofilled to TRUE otherwise.

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

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

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

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 including the unique fieldname and year the experiment is being generated for.

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 labeling for plotting in RxClass.

var_col_name

The name of the column of the variable in the supplied data ('dat'). Used in figure labeling 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 labeling for plotting in RxClass.

var_main_label

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

mgmt_scen

For this class, the management scenario is always an experiment so this parameter is set to 'exp'.

size

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

strat_dat

List holding all of the data used for stratification.

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
ExpGen$new(
  dbCon,
  trt_length,
  trt_width,
  heading = 0,
  fld_prop,
  expvar,
  conv,
  base_rate,
  rx_for_year,
  out_path = NULL,
  SAVE,
  fieldname,
  farmername,
  exp_rate_length,
  exp_rates,
  exp_rates_prop,
  buffer_width = 0,
  min_rate_jumps = NULL,
  strat_dat_parms = NULL
)
Arguments
dbCon

Database connection object connected to an OFPE formatted database, see DBCon class.

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.

fld_prop

The proportion of the field to apply experimental or optimum check rates to.

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_for_year

Provide the year that 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.).

SAVE

Logical, whether to save figures and the experiment Autofilled to FALSE if a user selects NA in the 'out_path' or is NULL. Autofilled to TRUE otherwise.

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.

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.

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.

Returns

An initialized ExpGen R6 class object.


Method executeOutput()

Method for calling the execution method of the experiment generator. This randomly applies the experimental rates across the field. If the user selected stratification data, these are used for stratification during the random placement.

Usage
ExpGen$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
ExpGen$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

DBCon for the database connection class, and RxGen for the alternative class that creates experimental prescriptions or pure prescriptions.


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