{"id":13724685,"url":"https://github.com/ytarazona/ForesToolboxRS","last_synced_at":"2025-05-07T18:33:25.172Z","repository":{"id":52588099,"uuid":"302735954","full_name":"ytarazona/ForesToolboxRS","owner":"ytarazona","description":"Remote Sensing Tools for Forest Monitoring","archived":false,"fork":false,"pushed_at":"2024-11-21T14:25:47.000Z","size":16604,"stargazers_count":56,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-17T20:37:06.483Z","etag":null,"topics":["change-detection","deforestation","machine-learning","remote-sensing"],"latest_commit_sha":null,"homepage":"https://ytarazona.github.io/ForesToolboxRS/","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ytarazona.png","metadata":{"files":{"readme":"README.Rmd","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-09T19:31:31.000Z","updated_at":"2025-01-04T08:48:52.000Z","dependencies_parsed_at":"2025-04-17T08:55:37.081Z","dependency_job_id":"7cc7fdf9-4193-45d8-a490-01d0fa5284bb","html_url":"https://github.com/ytarazona/ForesToolboxRS","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytarazona%2FForesToolboxRS","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytarazona%2FForesToolboxRS/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytarazona%2FForesToolboxRS/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ytarazona%2FForesToolboxRS/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ytarazona","download_url":"https://codeload.github.com/ytarazona/ForesToolboxRS/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250416074,"owners_count":21426910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["change-detection","deforestation","machine-learning","remote-sensing"],"created_at":"2024-08-03T01:02:01.784Z","updated_at":"2025-05-07T18:33:25.139Z","avatar_url":"https://github.com/ytarazona.png","language":"R","funding_links":["https://paypal.me/APROGIS?locale.x=es_XC"],"categories":["R","Biosphere"],"sub_categories":["Forest Remote Sensing"],"readme":"---\noutput: github_document\n---\n\n\n```{r README-1, include = FALSE}\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# ForesToolboxRS \u003cimg src=\"man/figures/logo.png\" align=\"right\" width=\"150\"/\u003e\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![GitHub action build status](https://github.com/ytarazona/ForesToolboxRS/workflows/pkgdown/badge.svg)](https://github.com/ytarazona/ForesToolboxRS/actions)\n[![Codecov test\ncoverage](https://codecov.io/gh/ytarazona/ForesToolboxRS/branch/main/graph/badge.svg)](https://codecov.io/gh/ytarazona/ForesToolboxRS?branch=main)\n[![lifecycle](https://img.shields.io/badge/lifecycle-experimental-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)\n\u003c!-- [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://paypal.me/APROGIS?locale.x=es_XC) --\u003e\n\n\u003cimg src=\"man/figures/Readme-image.png\"\u003e\n\n\n# Citation\n\nTo cite the `ForesToolboxRS` package in publications, please use [this paper](https://doi.org/10.1080/07038992.2021.1941823):\n\nYonatan Tarazona, Alaitz Zabala, Xavier Pons, Antoni Broquetas, Jakub Nowosad \u0026 Hamdi A. Zurqani\n  (2021) Fusing Landsat and SAR Data for Mapping Tropical Deforestation through Machine Learning\n  Classification and the PVts-β Non-Seasonal Detection Approach, Canadian Journal of Remote Sensing,\n  DOI: 10.1080/07038992.2021.1941823\n\nLaTeX/BibTeX version can be obtained with:\n```\nlibrary(ForesToolboxRS)\ncitation(\"ForesToolboxRS\")\n```\n\n# Introduction\n\n**ForesToolboxRS** is an R package providing a variety of tools and\nalgorithms for the processing and analysis of satellite images for the\nvarious applications of Remote Sensing for Earth Observations. All\nimplemented algorithms are based on scientific publications.\n\n- Tarazona, Y., Zabala,A., Pons, X., Broquetas, A., Nowosad, J., Zurqani, H.A. (2021). Fusing Landsat and SAR Data for Mapping Tropical Deforestation through Machine Learning Classification and the PVts-β Non-Seasonal Detection Approach. Canadian Journal of Remote Sensing. \n- Tarazona, Y., Maria, Miyasiro-Lopez. (2020). Monitoring tropical forest degradation using remote sensing. Challenges and opportunities in the Madre de Dios region, Peru. Remote Sensing Applications: Society and Environment, 19, 100337.\n- Tarazona, Y., Mantas, V.M., Pereira, A.J.S.C. (2018). Improving tropical deforestation detection through using photosynthetic vegetation time series (PVts-β). Ecological Indicators, 94, 367 379.\n- Hamunyela, E., Verbesselt, J., Roerink, G., \u0026 Herold, M. (2013). Trends in spring phenology of western European deciduous forests. Remote Sensing,5(12), 6159-6179.\n- Souza Jr., C.M., Roberts, D.A., Cochrane, M.A., 2005. Combining spectral and spatialinformation to map canopy damage from selective logging and forest fires. Remote Sens. Environ. 98 (2-3), 329-343.\n- Adams, J. B., Smith, M. O., \u0026 Gillespie, A. R. (1993). Imaging spectroscopy: Interpretation based on spectral mixture analysis. In C. M. Pieters \u0026 P. Englert (Eds.), Remote geochemical analysis: Elements and mineralogical composition. NY: Cambridge Univ. Press 145-166 pp.\n- Shimabukuro, Y.E. and Smith, J., (1991). The least squares mixing models to generate fraction images derived from remote sensing multispectral data. IEEE Transactions on Geoscience and Remote Sensing, 29, pp. 16-21.\n\n**The PVts-Beta approach**, a non-seasonal detection approach, is\nimplemented in this package and can read time series, vector, matrix,\nand raster data. Some functions of this package are intended to show, on\nthe one hand, some progress in methods for mapping deforestation and\nforest degradation, and on the other hand, to provide some tools (not\nyet available) for routine analysis of remotely detected data. Tools for\ncalibration of unsupervised and supervised algorithms through various\ncalibration approaches are some of the functions embedded in this\npackage. Therefore we sincerely hope that **ForesToolboxRS** can facilitate different analyses and simple and robust processes in satellite images\n\nAvailable functions:\n\n| Name of functions       | Description                                                                                                                                                                                                                                                                                                         |\n|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| **`pvts()`**            | This algorithm will allow to detect disturbances in the forests using all the available Landsat set. In fact, it can also be run with sensors such as MODIS.                                                                                                                                                        |\n| **`pvtsRaster()`**      | This algorithm will allow to detect disturbances in the forests using all the available Landsat set. In fact, it can also be run with sensors such as MODIS.                                                                                                                                                        |\n| **`smootH()`**          | In order to eliminate outliers in the time series, a temporary smoothing is used.                                                                                                                                                                                                                                   |\n| **`mla()`**             | This developed function allows to execute supervised classification in satellite images through various algorithms.                                                                                                                                                                                                 |\n| **`calmla()`**          | This function allows to calibrate supervised classification in satellite images through various algorithms and using approches such as Set-Approach, Leave-One-Out Cross-Validation (LOOCV), Cross-Validation (k-fold) and Monte Carlo Cross-Validation (MCCV).                                                     |\n| **`rkmeans()`**         | This function allows to classify satellite images using k-means.                                                                                                                                                                                                                                                    |\n| **`calkmeans()`**       | This function allows to calibrate the kmeans algorithm. It is possible to obtain the best k value and the best embedded algorithm in kmeans.                                                                                                                                                                        |\n| **`coverChange()`**     | This algorithm is able to obtain gain and loss in land cover classification.                                                                                                                                                                                                                                        |\n| **`linearTrend()`**     | Linear trend is useful for mapping forest degradation, land degradation, among others. This algorithm is capable of obtaining the slope of an ordinary least-squares linear regression and its reliability (p-value).                                                                                               |\n| **`fusionRS()`**        | This algorithm allows to fusion images coming from different spectral sensors (e.g., optical-optical, optical and SAR or SAR-SAR). Among many of the qualities of this function, it is possible to obtain the contribution (%) of each variable in the fused image.                                                 |\n| **`sma()`**             | The SMA assumes that the energy received, within the field of vision of the remote sensor, can be considered as the sum of the energies received from each dominant endmember. This function addresses a Linear Mixing Model.                                                                                       |\n| **`ndfiSMA()`**         | The NDFI it is sensitive to the state of the canopy cover, and has been successfully applied to monitor forest degradation and deforestation in Peru and Brazil. This index comes from the endmembers Green Vegetation (GV), non-photosynthetic vegetation (NPV), Soil (S) and the reminder is the shade component. |\n| **`tct()`**             | The Tasseled-Cap Transformation is a linear transformation method for various remote sensing data. Not only can it perform volume data compression, but it can also provide parametersassociated with the physical characteristics, such as brightness, greenness and wetness indices.                              |\n| **`gevi()`**            | Greenness Vegetation Index is obtained from the Tasseled Cap Transformation.                                                                                                                                                                                                                                        |\n| **`indices()`** | This function allows to obtain several remote sensing spectral indices in the optical domain.                                                                                            \n                        \n# Installation\n\nTo install the latest development version directly from the GitHub\nrepository. Before running **ForesToolboxRS**, it is necessary to\ninstall the **remotes** package:\n\n``` r\nlibrary(remotes)\ninstall_github(\"ytarazona/ForesToolboxRS\")\nsuppressMessages(library(ForesToolboxRS))\n```\n\n# Examples\n\n## 1. Breakpoint in an NDFI series (**`pvts`** function)\n\nHere an Normalized Difference Fraction Index (NDFI) between 2000 and\n2019 (28 data) was used. One NDFI for each year was obtained. The idea is to detect a change in 2008 (position 19). The NDFI value ranges from -1 to 1.\n\n```{r README-2}\nlibrary(ForesToolboxRS)\n# NDFI series\nndfi \u003c- c(0.86, 0.93, 0.97, 0.91, 0.95, 0.96, 0.91,\n          0.88, 0.92, 0.89, 0.90, 0.89, 0.91, 0.92,\n          0.89, 0.90, 0.92, 0.84, 0.46, 0.13, 0.12,\n          0.18, 0.14, 0.25, 0.17, 0.15, 0.18, 0.20)\n          \n# Plot\nplot(ndfi, pch = 20, xlab = \"Index\", ylab = \"NDFI value\")\nlines(ndfi, col = \"gray45\")\n```\n\n\n### 1.1 Applying a smoothing (the **`smootH()`** function)\n\nBefore detecting a breakpoint, it is necessary to apply smoothing to\nremove any existing outliers. So, we’ll use the **`smootH()`** function\nfrom the **ForesToolboxRS** package. The mathematical approach of this\nmethod of removing outliers implies the non-modification of the first\nand last values of the historical series.\n\nIf the idea is to detect changes in 2008 (position 19), then we will\nsmooth the data only up to that position (i.e., `ndfi[1:19]`). Let’s do\nthat.\n\n```{r README-3}\nndfi_smooth \u003c- ndfi\nndfi_smooth[1:19] \u003c- smootH(ndfi[1:19])\n\n# Let's plot the real series\nplot(ndfi, pch = 20, xlab = \"Index\", ylab = \"NDFI value\")\nlines(ndfi, col = \"gray45\", lty = 3)\n# Let's plot the smoothed series\nlines(ndfi_smooth, col = \"blue\", ylab = \"NDFI value\", xlab = \"Time\")\npoints(ndfi_smooth, pch = 20, col = \"blue\")\n```\n\n\n\u003e **Note**: You can change the detection threshold if you need to. \n\n### 1.1 Breakpoint using a specific index (vector)\n\nTo detect changes, either we can have a vector (using a specific\nindex/position) or a time series as input. Let’s first detect changes\nwith a vector, a then with a time series.\n\nWe use the output of the **`smootH()`** function (**`ndfi_smooth()`**).\n\nParameters:\n\n-   **x**: smoothed series preferably to optimize detection\n-   **startm**: monitoring year, index 19 (i.e., year 2008)\n-   **endm**: year of final monitoring, index 19 (i.e., also year 2008)\n-   **threshold**: detection threshold (for NDFI series we will use 5).\n    If you are using PV series, NDVI and EVI series you can use 5, 3 and 3\n    respectively. Please see [Tarazona et\n    al. (2018)](https://www.sciencedirect.com/science/article/abs/pii/S1470160X18305326)\n    for more details.\n\n```{r README-4}\n# Detect changes in 2008 (position 19)\ncd \u003c- pvts(x = ndfi_smooth, startm = 19, endm = 19, threshold = 5)\nplot(cd)\n```\n\n\n### 1.3 Breakpoint using Time Series\n\nParameters:\n\n-   **x**: smoothed series preferably to optimize detection\n-   **startm**: monitoring year, in this case year 2008.\n-   **endm**: year of final monitoring, also year 2008.\n-   **threshold**: detection threshold (for NDFI series we will use 5).\n    If you are using PV series, NDVI and EVI series you can use 5, 3 and 3\n    respectively. Please see [Tarazona et\n    al. (2018)](https://www.sciencedirect.com/science/article/abs/pii/S1470160X18305326)\n    for more details.\n\n```{r README-5}\n# Let´s create a time series of the variable \"ndfi\"\nndfi_ts \u003c- ts(ndfi, start = 1990, end = 2017, frequency = 1)\n\n# Applying a smoothing\nndfi_smooth \u003c- ndfi_ts\nndfi_smooth[1:19] \u003c- smootH(ndfi_ts[1:19])\n\n# Detect changes in 2008\ncd \u003c- pvts(x = ndfi_ts, startm = 2008, endm = 2008,  threshold = 5)\nplot(cd)\n```\n\n### 1.4 Breakpoint Not Detected\n\nParameters:\n\n-   **x**: smoothed series preferably to optimize detection\n-   **startm**: monitoring year, index 16 (i.e., year 2005)\n-   **endm**: year of final monitoring, index 16 (i.e., also year 2005)\n-   **threshold**: detection threshold (for NDFI series we will use 5).\n    If you are using PV series, NDVI and EVI series you can use 5, 3 and 3\n    respectively. Please see [Tarazona et\n    al. (2018)](https://www.sciencedirect.com/science/article/abs/pii/S1470160X18305326)\n    for more details.\n\n```{r README-6}\n# Detect changes in 2005\ncd \u003c- pvts(x = ndfi_smooth, startm = 2005, endm = 2005,  threshold = 5)\nplot(cd)\n```\n\n## 2. Supervised classification in Remote Sensing (the **`mla()`** function)\n\nFor this tutorial, Landsat-8 OLI image and signatures were used. To download data please follow this codes:\n\n```{r}\n# Data Preparation\ndir.create(\"testdata\")\n# downloading the image\ndownload.file(\"https://github.com/ytarazona/ft_data/raw/main/data/LC08_232066_20190727_SR.zip\",\n              destfile = \"testdata/LC08_232066_20190727_SR.zip\")\n# unziping the image\nunzip(\"testdata/LC08_232066_20190727_SR.zip\", exdir = \"testdata\")\n# downloading the signatures\ndownload.file(\"https://github.com/ytarazona/ft_data/raw/main/data/signatures.zip\",\n              destfile = \"testdata/signatures.zip\")\n# unziping the signatures\nunzip(\"testdata/signatures.zip\", exdir = \"testdata\")\n```\n\n### 2.1 Applying Random Forest (supervised classification)\n\nParameters:\n\n- **img**: RasterStack (Landsat 8 OLI)\n- **endm**: Signatures, **sf** object (shapefile)\n- **model**: Random Forest like 'randomForest'\n- **training_split**: 80 percent to train and 20 percent to validate the model\n\n```{r README-7, eval=TRUE}\nlibrary(ForesToolboxRS)\nlibrary(raster)\nlibrary(sf)\n\n# Read raster\nimage \u003c- stack(\"testdata/LC08_232066_20190727_SR.tif\")\n\n# Read signatures\nsig \u003c- read_sf(\"testdata/signatures.shp\")\n\n# Classification with Random Forest\nclassRF \u003c- mla(img = image, model = \"randomForest\", endm = sig, training_split = 80)\n\n# Results\nprint(classRF)\n```\n\n\n```{r README-8, eval = TRUE}\n# Classification\ncolmap \u003c- c(\"#0000FF\",\"#228B22\",\"#FF1493\", \"#00FF00\")\nplot(classRF$Classification, main = \"RandomForest Classification\", col = colmap, axes = TRUE)\n```\n\n\n### 2.2 Calibrating with Monte Carlo Cross-Validation (**`calmla()`** function)\n\n**`ForesToolboxRS`** has several approaches to calibrate machine\nlearning algorithms such as **Set-Approach**, **Leave One Out\nCross-Validation (LOOCV)**, **Cross-Validation (k-fold)** and **Monte\nCarlo Cross-Validation (MCCV)**.\n\nParameters:\n\n-   **img**: RasterStack (Landsat-8 OLI)\n-   **endm**: Signatures\n-   **model**: c(“svm”, “randomForest”, “naiveBayes”, “knn”). Machine\n    learning algorithms: Support Vector Machine, Random Forest, Naive\n    Bayes, K-nearest Neighbors\n-   **training\\_split**: 70\n-   **approach**: “MCCV”\n-   **iter**: 10\n\n\u003e **Warning!**: This function may take some time to process depending on the volumen of the data.\n\n```{r README-9, eval=TRUE}\ncal_ml \u003c- calmla(img = image, endm = sig,\n                 model = c(\"svm\", \"randomForest\", \"naiveBayes\", \"knn\"),\n                 training_split = 70, approach = \"MCCV\", iter = 10)\n```\n\n```{r README-10, eval=TRUE}\n# Calibration result\nplot(\n  cal_ml$svm_mccv,\n  main = \"Monte Carlo Cross-Validation calibration\",\n  col = \"darkmagenta\",\n  type = \"b\",\n  ylim = c(0, 0.4),\n  ylab = \"Error between 0 and 1\",\n  xlab = \"Number of iterations\"\n)\nlines(cal_ml$randomForest_mccv, col = \"red\", type = \"b\")\nlines(cal_ml$naiveBayes_mccv, col = \"green\", type = \"b\")\nlines(cal_ml$knn_mccv, col = \"blue\", type = \"b\")\nlegend(\n  \"topleft\",\n  c(\n    \"Support Vector Machine\",\n    \"Random Forest\",\n    \"Naive Bayes\",\n    \"K-nearest Neighbors\"\n  ),\n  col = c(\"darkmagenta\", \"red\", \"green\", \"blue\"),\n  lty = 1,\n  cex = 0.7\n)\n```\n\n### 3. Unsupervised classification in Remote Sensing (**`rkmeans`** function)\n\nFor this tutorial, the same images was used.\n\n#### 3.1 Applying K-means\n\nParameters:\n\n-   **img**: RasterStack (Landsat 8 OLI)\n-   **k**: the number of clusters\n-   **algo**: “MacQueen”\n\n```{r README-11}\nlibrary(ForesToolboxRS)\nlibrary(raster)\n\n# Read raster\nimage \u003c- stack(\"testdata/LC08_232066_20190727_SR.tif\")\n\n# Classification with K-means\nclassKmeans \u003c- rkmeans(img = image, k = 4, algo = \"MacQueen\")\n```\n\n```{r README-12}\n# Plotting classification\ncolmap \u003c- c(\"#0000FF\",\"#00FF00\",\"#228B22\", \"#FF1493\")\nplot(classKmeans, main = \"K-means Classification\", col = colmap, axes = FALSE)\n```\n\n### 3.2 Calibrating k-means (the **`calkmeans()`** function)\n\nThis function allows to calibrate the *kmeans* algorithm. It is possible\nto obtain the best value and the best embedded algorithm in kmeans. If\nwe want to find the optimal value of (clusters or classes), so we must\nput as an argument of the function. Here, we are finding k for which the\nintra-class inertia is stabilized.\n\nParameters:\n\n-   **img**: RasterStack (Landsat 8 OLI)\n-   **k**: The number of clusters\n-   **iter.max**: The maximum number of iterations allowed. Strictly\n    related to k-means\n-   **algo**: It can be “Hartigan-Wong”, “Lloyd”, “Forgy” or “MacQueen”.\n    Algorithms embedded in k-means\n    \u003c!--JN: Algorithms embedded in k-means???--\u003e\n-   **iter**: Iterations number to obtain the best k value\n\n```{r README-13, warning=FALSE}\n# Elbow method\nbest_k \u003c- calkmeans(img = image, k = NULL, iter.max = 10,\n                    algo = c(\"Hartigan-Wong\", \"Lloyd\", \"Forgy\", \"MacQueen\"),\n                    iter = 20)\n```\n\n```{r README-14}\nplot(best_k)\n```\n\n```{r, echo=FALSE, warning=FALSE, message=FALSE}\nunlink(\"testdata\", recursive = TRUE, force = TRUE)\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytarazona%2FForesToolboxRS","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fytarazona%2FForesToolboxRS","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fytarazona%2FForesToolboxRS/lists"}