Title: | R Frontend for Rosetta Pedotransfer Functions |
---|---|
Description: | Access Python rosetta-soil pedotransfer functions in an R environment. Rosetta is a neural network-based model for predicting unsaturated soil hydraulic parameters from basic soil characterization data. The model predicts parameters for the van Genuchten unsaturated soil hydraulic properties model, using sand, silt, and clay, bulk density and water content. The codebase is now maintained by Dr. Todd Skaggs and other U.S. Department of Agriculture employees. This R package is intended to provide for use cases that involve many thousands of calls to the pedotransfer function. Less demanding use cases are encouraged to use the web interface or API endpoint. There are additional wrappers of the API endpoints provided by the soilDB R package `ROSETTA()` method. |
Authors: | Soil and Plant Science Division Staff |
Maintainer: | Andrew G. Brown <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.1.5 |
Built: | 2024-10-25 04:46:56 UTC |
Source: | https://github.com/ncss-tech/rosettaPTF |
Extended Rosetta Predictions, Parameter Distributions and Summary Statistics after Zhang & Schaap (2017)
ann_predict(object, soildata, sum_data = TRUE) ## Default S3 method: ann_predict(object, soildata, sum_data = TRUE) ## S3 method for class 'Rosetta' ann_predict(object, soildata, sum_data = TRUE)
ann_predict(object, soildata, sum_data = TRUE) ## Default S3 method: ann_predict(object, soildata, sum_data = TRUE) ## S3 method for class 'Rosetta' ann_predict(object, soildata, sum_data = TRUE)
object |
Rosetta object containing class instance (e.g. from |
soildata |
A list containing vectors; with number of parameters matching the model type of |
sum_data |
Default: |
# ann_predict(Rosetta(), list(c(30, 30, 40, 1.5), c(55, 25, 20, 1.1)))
# ann_predict(Rosetta(), list(c(30, 30, 40, 1.5), c(55, 25, 20, 1.1)))
If you are using the rosettaPTF package for the first time you will need to have Python installed to obtain the necessary modules. You can set up reticulate to install into a virtual or Conda environment. Usually reticulate should cover most or all of the setup.
find_python( envname = NULL, pypath = NULL, arcpy_path = getOption("rosettaPTF.arcpy_path") )
find_python( envname = NULL, pypath = NULL, arcpy_path = getOption("rosettaPTF.arcpy_path") )
envname |
As in |
pypath |
Optional: Path to |
arcpy_path |
Optional: Path to ArcGIS Pro Python installation. For example: |
If you have Python set up correctly you should be able to run reticulate::py_config()
or reticulate::py_discover_config()
and discover your shared library.
A common problem with reticulate is not pointing at the correct (or any) python
binary or libpython
shared library. Use reticulate::use_python("/path/to/python", required = TRUE)
to set the path or, alternately, be sure python
can be found on your PATH. reticulate has a preference for Python environments that have numpy
installed.
Use reticulate::install_miniconda()
if you'd like to install a Miniconda Python environment. Conda is default on Windows.
For devices with limited ability to install new software that have ArcGIS Pro installed (some USDA computers), this method can look for a Python installation in "C:/Program Files/ArcGIS/Pro/bin/Python/envs/arcgispro-py3"
and Conda executable in "C:/Program Files/ArcGIS/Pro/bin/Python/Scripts"
. The base file path to "Python" directory can be customized using the arcpy_path
argument.
On Linux and OS X you can create a virtual environment using reticulate::virtualenv_create()
. The default environment name will be "r-reticulate"
.
character path to python
or NULL
if no suitable environment can be found. The result is stored as the package option rosettaPTF.python_path
.
find_python()
find_python()
Get Rosetta module object reference
get_rosetta_module()
get_rosetta_module()
An R object wrapping a Python module. Module attributes can be accessed via the $
operator, or via py_get_attr()
.
Wrapper around reticulate::py_install()
to install the Rosetta Pedotransfer Function Python package
install_rosetta( envname = NULL, method = "auto", conda = "auto", pip = TRUE, user = FALSE, upgrade = TRUE, system = FALSE, arcpy_path = getOption("rosettaPTF.arcpy_path") )
install_rosetta( envname = NULL, method = "auto", conda = "auto", pip = TRUE, user = FALSE, upgrade = TRUE, system = FALSE, arcpy_path = getOption("rosettaPTF.arcpy_path") )
envname |
The name, or full path, of the environment in which Python packages are to be installed. When |
method |
|
conda |
Default: |
pip |
logical. Use |
user |
logical. Default: |
upgrade |
logical. Install latest versions of Python packages by passing |
system |
logical. Default: |
arcpy_path |
Argument passed to |
From reticulate::py_install()
: On Linux and OS X the "virtualenv" method will be used by default ("conda" will be used if virtualenv isn't available). On Windows, the "conda" method is always used.
mukey
Sample SSURGO Mapunit Web Coverage Service Data: matrix of mukey
Predict Rosetta Parameter Values and Standard Deviations from a Rosetta instance
## S3 method for class 'Rosetta' predict(object, soildata, ...)
## S3 method for class 'Rosetta' predict(object, soildata, ...)
object |
Rosetta object containing class instance (e.g. from |
soildata |
A list containing vectors; with number of parameters matching the model type of |
... |
not used |
# predict(Rosetta(), list(c(30, 30, 40, 1.5), c(55, 25, 20, 1.1)))
# predict(Rosetta(), list(c(30, 30, 40, 1.5), c(55, 25, 20, 1.1)))
predict()
methodsMake a Rosetta object instance for running predict()
methods
Rosetta(rosetta_version = 3, model_code = 3)
Rosetta(rosetta_version = 3, model_code = 3)
rosetta_version |
Default: |
model_code |
One of |
2
: sand, silt, clay ("SSC")
3
: sand, silt, clay + bulk density ("BD")
4
: sand, silt, clay + bulk density + field capacity water content (1/3 bar or 33 kPa tension)
5
: sand, silt, clay + bulk density + field capacity water content + wilting point water content (15 bar or 1500 kPa tension)
-1
: no result returned, inadequate or erroneous data
an instance of the Rosetta
class defined by the Python module; suitable for running predict
or ann_predict
methods.
Check if Rosetta module is available for import from local Python environment
rosetta_module_available()
rosetta_module_available()
logical
rosetta()
method from Python moduleRun rosetta()
method from Python module
## Default S3 method: run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'data.frame' run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'matrix' run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'RasterStack' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE ) ## S3 method for class 'RasterBrick' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE ) ## S3 method for class 'SpatRaster' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE )
## Default S3 method: run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'data.frame' run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'matrix' run_rosetta(soildata, vars = NULL, rosetta_version = 3, ...) ## S3 method for class 'RasterStack' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE ) ## S3 method for class 'RasterBrick' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE ) ## S3 method for class 'SpatRaster' run_rosetta( soildata, vars = NULL, rosetta_version = 3, cores = 1, core_thresh = 20000L, file = paste0(tempfile(), ".tif"), nrows = nrow(soildata)/(terra::ncell(soildata)/core_thresh), overwrite = TRUE )
soildata |
A list of numeric vectors each containing 3 to 6 values: |
vars |
character. Optional: names and order of custom column names if |
rosetta_version |
Default: 3 |
... |
additional arguments not used |
cores |
number of cores; used only for processing SpatRaster or Raster* input |
core_thresh |
Magic number for determining processing chunk size. Default |
file |
path to write incremental raster processing output for large inputs that do not fit in memory; passed to |
nrows |
number of rows to use per block chunk; passed to |
overwrite |
logical; overwrite |
A data.frame containing mean
and stdev
for following five columns (parameters for van Genuchten-Mualem equation)
"theta_r"
, residual water content
"theta_s"
, saturated water content
"log10(alpha)"
, 'alpha' shape parameter, log10(1/cm)
"log10(npar)"
, 'n' shape parameter
"log10(Ksat)"
, saturated hydraulic conductivity, log10(cm/day)
SoilDataFromArray
: convert a list of numeric vectors containing soil properties to a rosetta.rosetta.SoilData
class
py_to_r(<rosetta.rosetta.SoilData>)
: Wrapper S3 method for SoilData objects to prevent automatic conversion of SoilData (subclass of "python.builtin.list"
) to an R "list"
SoilDataFromArray(x) ## S3 method for class 'rosetta.rosetta.SoilData' py_to_r(x)
SoilDataFromArray(x) ## S3 method for class 'rosetta.rosetta.SoilData' py_to_r(x)
x |
a list of numeric vectors |
an object reference to a Rosetta SoilData Python object constructed from x