% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/summarize_raster_outputs.R
\name{summarize_raster_outputs}
\alias{summarize_raster_outputs}
\title{Summarize Prediction Rasters into Consensus Outputs}
\usage{
summarize_raster_outputs(predictions_dir, output_dir = NULL,
                         consensus = 1, file_pattern = "Prediction_.*\\\.tif$",
                         overwrite = FALSE, verbose = TRUE)
}
\arguments{
\item{predictions_dir}{Character. Directory containing prediction raster
files, typically the \code{output_dir} used in
\code{\link{generate_spatiotemporal_predictions}}.}

\item{output_dir}{Character. Directory for output files. Defaults to
\code{predictions_dir} if \code{NULL}.}

\item{consensus}{Integer. Minimum number of folds that must agree on
suitability for a pixel to be classified as suitable in the binary output.
For example, \code{consensus = 1} marks any pixel suitable if at least one
fold predicts it suitable; \code{consensus = 4} requires at least four folds to
agree. Must be between 1 and the maximum vote count in the rasters (number of
folds). Default is \code{1}.}

\item{file_pattern}{Character. Regular expression to match prediction raster
files. Default is \code{"Prediction_.*\\.tif$"}.}

\item{overwrite}{Logical. If \code{TRUE}, overwrites existing output files.
If \code{FALSE} (default), existing files are skipped.}

\item{verbose}{Logical. If \code{TRUE} (default), prints progress
messages during processing.}
}
\value{
Invisibly returns a list containing:
\itemize{
  \item \code{consensus_stack}: \code{SpatRaster} stack of per-time-step
    binary consensus rasters (one layer per input file).
  \item \code{frequency_raster}: \code{SpatRaster} showing the proportion of
    time steps during which each pixel met the consensus threshold. Values
    range from 0 (never suitable) to 1 (always suitable).
  \item \code{consensus}: the consensus threshold used.
  \item \code{n_timesteps}: number of time steps processed.
  \item \code{consensus_dir}: path to the directory containing per-time-step
    binary consensus rasters.
  \item \code{frequency_file}: path to the written frequency raster file.
}
}
\description{
Post-processing function that synthesizes per-time-step fold-vote rasters
(output from \code{\link{generate_spatiotemporal_predictions}}) into binary
consensus predictions and a temporal frequency summary. Each input raster
contains integer vote counts per pixel the number of cross-validation
folds that classified that pixel as suitable. The \code{consensus} threshold
controls how many folds must agree for a pixel to be classified as suitable
in the output binary rasters.
}
\details{
Input rasters are fold-vote-count rasters produced by
\code{\link{generate_spatiotemporal_predictions}}, where each pixel value is
the number of cross-validation fold models that predicted suitability at that
location for that time step. The \code{consensus} threshold is applied as:
\code{binary = as.integer(vote_count >= consensus)}.

The frequency raster (proportion of time steps suitable under the chosen
consensus) serves as input to \code{\link[TemporalModelR]{analyze_temporal_patterns}} for
identifying long-term trends in suitability.
}
\examples{
pred_dir <- system.file("extdata/predictions",
                        package = "TemporalModelR")

summarize_raster_outputs(
  predictions_dir = pred_dir,
  output_dir      = tempdir(),
  consensus       = 3,
  overwrite       = TRUE,
  verbose         = FALSE
)
}
\seealso{
Upstream: \code{\link{generate_spatiotemporal_predictions}}

Downstream: \code{\link[TemporalModelR]{analyze_temporal_patterns}}
}
