WHC: R6 Class for generating water holding capacity...

WHCR Documentation

R6 Class for generating water holding capacity classifications

Description

R6 class for for creating the water holding capacity (WHC) classification across fields based on remotely sensed data. This class facilitates the importing of the satellite from the OFPE database, calculating the mean and coefficient of variation (CV) of a user specified metric (e.g. NDVI, NDRE, CIRE) at each pixel of the satellite dataset, and generating a classification of WHC across a field (Low, Medium, High).

The mean and CV of the specified metric at each pixel of the satellite data are classified into categories of high, medium, or low in terms of the mean to other means across the field, and into a high, medium, or low CV category based on the relation of the pixel's CV to the total range of other CV values across the field. Every location in the field has an assignment of H/M/L for the mean and CV, creating a 3x3 matrix of combinations of H/M/L mean and CV of the user specified metric.

If the mean and CV of a given pixel are high and low, respectively, the pixel would be categorized as a high WHC because in the given pixel, the metric specified (e.g. NDVI, NDRE, CIRE or other vegetation index) representing productivity is high on average across varying weather conditions while the pixel's low CV indicates that the pixel maintains a consistent productivity across weather conditions. The high productivity with little variation indicates the crop is getting adequate moisture and nutrients to maintain high production in different weather conditions across time. First, we assume that to maintain a high productivity across time, without making assumptions about management, the soil in that pixel would retain water and nutrients well enough to minimize the resource limitation of a crop, even in adverse years. Second, we assume that, because moisture and nutrient retention are related to the WHC of a soil, areas of the field with a high mean productivity and low CV of productivity would have soils with a high WHC and minimized risk of water and nutrient inefficiency

Similarly, if the mean and CV of a given pixel are both low, the pixel would be categorized as a low WHC because in a given pixel, the metric of productivity is consistently low over time, indicating that the crop is never receiving adequate moisture and nutrients, no matter the weather condition. This indicates that these areas are intransigent to any prior management practice to increase production.

Other combinations of H/M/L mean and CV valeus for productivity are used to generate a WHC classification, laid out in Hegedus & Ewing, 2022.

Main initializing requirements are a database connection, and a field name present in the database. The methods include gathering remote sensing information for a set of years from the 'sat' table of a farmer's schema for aggregated data. Additionally, methods include generating classifications of WHC at the resolution of the satellite data based on the the mean and CV at each pixel across a range of years specificed.

Additional methods include adding the data to datasets either directly or in the database.

Public fields

db

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

fieldname

Name of the field to generate WHC classes for.

farmidx

Identifier for the farm boundary to gather remote sensing data from.

farmername

Name of the farmer that manages the specified field.

raw_dat

List of raw raster fields from gatherDBdat method.

dattype

Type of data to use for making classifications from.

whc_dat

Data table with the classifications of mean, CV, and WHC.

not_fallow

Vector of years where the mean NDVI was greater than the fallow cutoff specified in gatherDBdat().

Methods

Public methods


Method new()

Usage
WHC$new(dbCon, fieldname)
Arguments
dbCon

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

fieldname

Name of the field to generate WHC classes for.

Returns

A new 'WHC' object.


Method gatherDBdat()

Function for creating a stack of rasters from a set of years. Requires a user to pass a vector of years as an argument. Also requires specification of a vegetation index. Must be present as a data type in the 'all_farms.gee' table of raster data in the database. The vegetation index (default = NDVI) data from each year is downloaded and clipped to the field boundary. This function pulls from cleaned and aggregated satellite data (in a farmer's '_a.sat' table). Only retrieves Landsat data

Usage
WHC$gatherDBdat(years, dattype = "ndvi", output = FALSE, fallow_cutoff = 0.3)
Arguments
years

Vector of years corresponding to years of historical NDVI information in the database.

dattype

Type of remote sensing data to use. Must be a data type present in the database.

output

Whether to return a figure showing the trends in NDVI across time.

fallow_cutoff

The value of the metric below which indicates a fallow field and removed from list of years to calculate a WHC classification.

Returns

An internal list object with data from each year stored in a 'raw_dat' object.


Method genWHCclass()

Function for generating the WHC classification from data in the database. Must be supplied with a list of data from the 'sat' tables of an aggregated schema or the gatherDBdat() method must be called prior to this.

Usage
WHC$genWHCclass(
  METHOD = "nb",
  save2db = FALSE,
  out_path = NULL,
  output = FALSE,
  epsg = 32612
)
Arguments
METHOD

Method to classify mean and CV values into High/Medium/Low categories. Either "nb" for Jenks or "ei" for equal interval.

save2db

Logical, default to FALSE, on whether to save the WHC classification dataset into the OFPE database in the all_farms.WHC table. Overwrites any existing data for the same field.

out_path

Character path for a folder in which to save the WHC classification data to. File name is 'whc_class_farmer_field.csv'. If NULL does not save.

output

Whether to return a list with the raster data.

epsg

The coordinate reference system code that the satellite data is in.

Returns

A data frame with the WHC classification, if desired.


Method classWHC()

Function for classifying mean and CV classifications into WHC zones.

Usage
WHC$classWHC(whc_dat)
Arguments
whc_dat

Data.table or data.frame with the mean and CV for each row of the satellite data.

Returns

The user's dataset with classifications of WHC.


Method plotRawMaps()

Function for plotting the raw satellite data.

Usage
WHC$plotRawMaps(out_path, epsg, years = NULL, output = FALSE)
Arguments
out_path

Character path for a folder in which to save the map to. File name is 'fieldname_dattype_map_year.png'.

epsg

The coordinate reference system code that the satellite data is in.

years

Vector of year(s) to save and return maps for. If NULL assumes all.

output

Logical, defaults to FALSE, on whether to return maps

Returns

A data frame with the WHC classification, if desired.


Method plotWHCmap()

Function for plotting the WHC classifications.

Usage
WHC$plotWHCmap(out_path, epsg, output = FALSE, METHOD = "nb")
Arguments
out_path

Character path for a folder in which to save the map to. File name is 'fieldname_whc_map.png'.

epsg

The coordinate reference system code that the satellite data is in.

output

Logical, defaults to FALSE, on whether to return maps

METHOD

Method to classify mean and CV values into High/Medium/Low categories. Either "nb" for Jenks or "ei" for equal interval.

Returns

A data frame with the WHC classification, if desired.


Method clone()

The objects of this class are cloneable with this method.

Usage
WHC$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

See Also

DBCon for database connection class


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