| Title: | R Frontend for Rosetta Pedotransfer Functions |
|---|---|
| Description: | Access the rosetta-soil Python pedotransfer functions from R. Rosetta is a neural network-based model for predicting unsaturated soil hydraulic parameters from basic soil characterization data (sand, silt, clay, bulk density, and water content). Predictions are made for the van Genuchten unsaturated hydraulic properties model, with uncertainty quantification via bootstrap ensemble. Designed for efficient batch processing of large datasets through vectorized computation and optional parallel processing. |
| Authors: | Andrew Brown [aut, cre] (ORCID: <https://orcid.org/0000-0002-4565-533X>) |
| Maintainer: | Andrew Brown <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.2.0 |
| Built: | 2026-05-21 09:52:32 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 |
A list containing mean and stdev matrices (one row per sample).
For rosetta-soil >= 0.3, the columns are: theta_r, theta_s, alpha, npar, ksat.
Note that these parameters are in the scale produced by the underlying model (often log10 for alpha, npar, and ksat).
# 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 K0 and L from retention parameters
## S3 method for class 'UnsaturatedK' predict(object, retc_params, ...)## S3 method for class 'UnsaturatedK' predict(object, retc_params, ...)
object |
UnsaturatedK object |
retc_params |
A list or matrix of retention parameters (theta_r, theta_s, alpha, npar) |
... |
not used |
a data.frame with log10_K0_mean, lpar_mean, log10_K0_sd, lpar_sd
Run rosesoil() from rosetta-soil >= 0.3.0
rosesoil(soildata, rosetta_version = 3, estimate_type = "arith", vars = NULL)rosesoil(soildata, rosetta_version = 3, estimate_type = "arith", vars = NULL)
soildata |
A list of numeric vectors or a data.frame (3-6 columns: sand, silt, clay, optionally bulk density, th33, and th1500) |
rosetta_version |
integer, 1-3. Default: 3 |
estimate_type |
character. One of |
vars |
optional column name mapping (same as run_rosetta) |
a data.frame with all RosettaResult fields
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, estimate_type = "log", ... ) ## S3 method for class 'data.frame' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", ... ) ## S3 method for class 'matrix' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", ... ) ## S3 method for class 'RasterStack' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", 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, estimate_type = "log", 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, estimate_type = "log", 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, estimate_type = "log", ... ) ## S3 method for class 'data.frame' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", ... ) ## S3 method for class 'matrix' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", ... ) ## S3 method for class 'RasterStack' run_rosetta( soildata, vars = NULL, rosetta_version = 3, estimate_type = "log", 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, estimate_type = "log", 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, estimate_type = "log", 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 |
estimate_type |
character. One of |
... |
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 |
Use cores > 1 with SpatRaster or Raster* inputs to parallelize processing of cells across multiple cores.
A data.frame containing mean and stdev for the following columns (parameters for van Genuchten-Mualem equation)
"theta_r", residual water content
"theta_s", saturated water content
"alpha", 'alpha' shape parameter (1/cm). Logarithmic (log10) scale if estimate_type="log" (default); Geometric mean if estimate_type="geo".
"npar", 'n' shape parameter. Logarithmic (log10) scale if estimate_type="log" (default); Geometric mean if estimate_type="geo".
"Ksat", saturated hydraulic conductivity (cm/day). Logarithmic (log10) scale if estimate_type="log" (default); Geometric mean if estimate_type="geo".
"K0", unsaturated hydraulic conductivity (cm/day). Only if rosetta-soil >= 0.3.1. Logarithmic (log10) scale if estimate_type="log" (default); Geometric mean if estimate_type="geo".
"lpar", unsaturated hydraulic conductivity exponent. Only if rosetta-soil >= 0.3.1.
If the sum of sand, silt, and clay is not 100%, the parameter value estimates will be NaN.
SoilDataFromArray: convert a list of numeric vectors containing soil properties to a rosetta.rosetta.SoilData class. In rosetta-soil >= 0.3, direct list input is preferred.
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
UnsaturatedK: Create an instance of the UnsaturatedK class from rosetta-soil >= 0.3. This class is used to predict K0 and L from retention parameters.
UnsaturatedK()UnsaturatedK()
an instance of the UnsaturatedK class.