mh_overlay: Overlay Mahalanobis-based Climate Representativeness...

View source: R/mh_overlay.R

mh_overlayR Documentation

Overlay Mahalanobis-based Climate Representativeness Classifications

Description

Combines multiple single-layer rasters (tif), outputs from mh_rep or mh_rep_ch for different input polygons, into a multi-layered SpatRaster.

This function handles inputs from both mh_rep (which primarily contains Represented areas) and mh_rep_ch (which includes Retained, Lost, and Novel areas). The output layers consistently represent counts of each input.

Usage

mh_overlay(folder_path)

Arguments

folder_path

character. The path to the directory containing the classification rasters (.tif) generated by mh_rep or mh_rep_ch. These rasters should primarily contain the categories: 1 (Retained/Represented), 2 (Lost), and 3 (Novel). Category 0 (Non-represented) will be ignored for the RGB output.

Details

This function streamlines the aggregation of Climate Representativeness classifications. It is designed to work with outputs from both mh_rep and mh_rep_ch.

For each of the three key categories (Lost, Retained/Represented, Novel), the function:

  1. Identifies and reads all .tif files within the folder_path.

  2. For each input raster, it creates a binary layer: 1 if the cell's value matches the target category (e.g., 2 for 'Lost'), and 0 otherwise.

  3. Sums these binary layers to generate a cumulative count for that specific category at each grid cell.

The three resulting count layers (Lost, Retained, Novel) are then consistently stacked in the following order:

  • First layer (Red): Cumulative count of Lost.

  • Second layer (Green): Cumulative count of Retained.

  • Third layer (Blue): Cumulative count of Novel.

This fixed order ensures that the output SpatRaster is immediately ready for direct RGB visualization using terra::plotRGB(), where the color mixtures will intuitively reflect the spatial agreement of these change types.

The output SpatRaster contains raw counts. While terra::plotRGB() often handles stretching for visualization, users might normalize these counts manually (e.g., to 0-255) for finer control over visual contrast.

A new subfolder named ⁠overlay/⁠ will be created within the folder_path. The resulting three-layered RGB will be saved as ClimaRep_overlay.tif inside this new ⁠overlay/⁠ subfolder.

Value

Writes the multi-layered (ClimaRep_overlay.tif) outputs to disk in a new overlay subfolder within the folder_path. When mh_rep_ch results are used, the output layers consistently represent counts for Lost (Red), Retained (Green), and Novel (Blue) categories across all input rasters. Designed for direct RGB plotting. When mh_rep results are used, the output layers consistently represent counts for Represented categories across all input rasters.

Examples

ClimaRep_overlay <- ClimaRep::mh_overlay(folder_path = system.file("extdata", package = "ClimaRep"))
terra::plotRGB(ClimaRep_overlay)
terra::plot(ClimaRep_overlay)

ClimaRep documentation built on June 28, 2025, 1:07 a.m.