`rOPTRAM`

implements The OPtical TRapezoid Model (OPTRAM) to derive soil moisture based on the linear relation between a vegetation index, i.e. NDVI, and Shortwave Infra-red (SWIR). The SWIR band is transformed to SWIR Transformed Reflectance (STR).

A scatterplot of NDVI vs. STR is used to produce wet and dry linear regression lines, and the slope/intercept coefficients of these lines comprise the trapezoid. These coefficients are then used on a new satellite image to determine soil moisture.

See: Sadeghi et al. (2017), Burdun et al. (2020), Ambrosone et al. (2020)

## Installation

`rOPTRAM`

resides on github. You can install the development version of rOPTRAM like so:

```
# Install remotes package
if (! require("remotes")) {
install.packages("remotes")
}
remotes::install_github("ropensci/rOPTRAM")
```

#### Prerequisites

Only a small number of commonly used R packages are required to use {rOPTRAM}. This includes: - base packages {tools} and {utils} - spatial packages {sf} and {terra} - data.frame and plotting {dplyr}, {ggplot2}, {MASS}

Users can download Sentinel-2 tiles from the Copernicus manually, and run thru the steps to produce the OPTRAM trapezoid, and predicted soil moisture maps. However, this approach is not optimal. By installing a few additional packages, the workflow can be initiated by a single function call to download, clip to area of interest, and produce the trapezoid coefficients. The all-inclusive approach is highly recommended since processing of the Sentinel-2 data is performed “in the cloud” and only the final products are downloaded, **greatly** reducing the download file sizes.

To run the all-inclusive approach, the first step of acquiring Sentinel-2 imagery is handled by the R package {CDSE}. (see Karaman (2023)). The {jsonlite} package is also necessary.

That R package interfaces with the Copernicus DataSpace Ecosystem in one of two ways: - Thru the Scihub API. - Thru the openEO platform

Both methods require registering on the Copernicus DataSpace

## Available functions

#### optram_options()

Several package options are defined, with default values, when {rOPTRAM} first loads. Each of these can be set individually to user chosen values. For example, the package uses a vegetation index (compared to SWIR Transformed Reflectance) values to plot the trapezoid. The default index is “NDVI”. In a low vegetation, arid region, users can choose an alternative such as “SAVI” (see example below). The default maximum cloud cover is set to 12 [%], and users can choose any value between 0-100.

#### optram()

A main wrapper function to run the whole OPTRAM procedure. This function performs the following steps:

- Acquire Sentinel 2 images covering the requested date range, and clipped to the input area of interest. This step relies on the {CDSE} package
- Create the set of SWIR Transformed Reflectance (STR) rasters;
- Prepare a dataframe of NDVI and STR values for all pixels from all images;
- Calculate the trapezoid wet and dry regression lines, and save coefficients to a CSV file. Returns: RMSE values of the fitted regression lines of the trapezoid.

#### optram_acquire_s2()

Acquire Sentinel 2 images covering the requested date range, and clipped to the input area of interest.

Among the function parameters, the `method`

can be specified as either “scihub” or “openeo”, thus choosing one of the two available acqquistion methods.

Returns: a list of downloaded Sentinel 2 images

#### optram_calculate_str()

Extracts the required bands and prepares the vegetation index and SWIR transformed reflectance.

#### optram_ndvi_str()

Collects all pixel values from both the vegetation index and STR rasters, for all acquisition dates, and saves into a data.frame

Returns: the full data.frame

#### optram_wetdry_coefficients()

Calculates the wet-dry trapezoid from the data.frame of NDVI and STR values, and obtains regression slope and intercept for both lines

Three possible fitting methods are offered in this function, thru the “trapezoid_method” parameter. The user can choose to match the upper (wet) and lower (dry) bounds of the trapezoid either as a linear regression line, an exponential curve, or a second order polynomial function.

Returns: the set of four (or six, in the case of polynomial curve) coefficients.

#### optram_calculate_soil_moisture()

Calculates soil moisture rasters for a time series of images, using the OPTRAM model coefficients from above procedure.

## Example

First, a demonstration of choosing non-default package options.

```
# Show default options
rOPTRAM::optram_options()
#> [1] "edge_points = TRUE"
#> [1] "feature_col = ID"
#> [1] "max_cloud = 12"
#> [1] "max_tbl_size = 1e+06"
#> [1] "only_vi_str = FALSE"
#> [1] "overwrite = FALSE"
#> [1] "period = full"
#> [1] "plot_colors = no"
#> [1] "remote = scihub"
#> [1] "rm.hi.str = FALSE"
#> [1] "rm.low.vi = FALSE"
#> [1] "scm_mask = TRUE"
#> [1] "SWIR_band = 11"
#> [1] "tileid = NA"
#> [1] "trapezoid_method = linear"
#> [1] "veg_index = NDVI"
#> [1] "vi_step = 0.005"
#> NULL
# Change one options
rOPTRAM::optram_options("veg_index", "SAVI", show_opts = FALSE)
#>
#> Option for: veg_index set to: SAVI
```

Next a basic example which shows how to:

- retrieve Sentinel 2 imagery for a specific area of interest
- covering a date range
- preprocess the imagery to obtain a vegetation index and STR band
- use these to derive coefficients of slope and intercept for the OPTRAM trapezoid
- using the “linear” fitting method

## Note

In order to download Sentinel 2 images, the {CDSE} package is used: (Karaman (2023))

That package should be installed in advance in order to run the `optram()`

wrapper function.

If, on the other hand, Sentinel 2 imagery has been downloaded in advance, then {CDSE} is not strictly necessary. Instead, the following workflow can be used:

- call
`optram_safe()`

to prepare NDVI and STR rasters - call
`optram_calculate_str()`

to calculate SWIR Transform - call
`optram_ndvi_str()`

to build a data.frame of pixel values - call
`optram_wetdry_coefficients()`

to derive slope and intercept of the trapezoid.

## Meta

- Please report any issues on github
- Anyone interested in collaborating is invited to “sign up” by contacting the maintainers.
- This package is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

*International Journal of Applied Earth Observation and Geoinformation*89 (July): 102113. https://doi.org/10.1016/j.jag.2020.102113.

*Remote Sensing*12 (18): 2936. https://doi.org/10.3390/rs12182936.

*Remote Sensing of Environment*198 (September): 52–68. https://doi.org/10.1016/j.rse.2017.05.041.