WHC | R Documentation |
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.
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().
new()
WHC$new(dbCon, fieldname)
dbCon
Database connection object connected to an OFPE formatted database, see DBCon class.
fieldname
Name of the field to generate WHC classes for.
A new 'WHC' object.
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
WHC$gatherDBdat(years, dattype = "ndvi", output = FALSE, fallow_cutoff = 0.3)
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.
An internal list object with data from each year stored in a 'raw_dat' object.
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.
WHC$genWHCclass( METHOD = "nb", save2db = FALSE, out_path = NULL, output = FALSE, epsg = 32612 )
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.
A data frame with the WHC classification, if desired.
classWHC()
Function for classifying mean and CV classifications into WHC zones.
WHC$classWHC(whc_dat)
whc_dat
Data.table or data.frame with the mean and CV for each row of the satellite data.
The user's dataset with classifications of WHC.
plotRawMaps()
Function for plotting the raw satellite data.
WHC$plotRawMaps(out_path, epsg, years = NULL, output = FALSE)
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
A data frame with the WHC classification, if desired.
plotWHCmap()
Function for plotting the WHC classifications.
WHC$plotWHCmap(out_path, epsg, output = FALSE, METHOD = "nb")
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.
A data frame with the WHC classification, if desired.
clone()
The objects of this class are cloneable with this method.
WHC$clone(deep = FALSE)
deep
Whether to make a deep clone.
DBCon
for database connection class
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.