% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/scale_rasters.R
\name{scale_rasters}
\alias{scale_rasters}
\title{Scale Environmental Rasters Using Species Occurrence Data}
\usage{
scale_rasters(input_dir, output_dir, scaling_params_file,
              variable_patterns, time_cols = NULL, output_suffix = "_Scaled",
              overwrite = FALSE, verbose = TRUE)
}
\arguments{
\item{input_dir}{Character. Directory containing aligned input .tif raster files,
typically the output of \code{\link{raster_align}}.}

\item{output_dir}{Character. Directory where scaled rasters will be saved.}

\item{scaling_params_file}{Character. Path to CSV file with columns:
variable, mean, sd. Typically generated by
\code{\link{temporally_explicit_extraction}}.}

\item{variable_patterns}{Named character vector mapping clean variable names
to raster filename patterns. For time-varying variables include the time
placeholder in the pattern (e.g. \code{"forest_cover" = "forest_cover_YEAR"});
for static variables omit it (e.g. \code{"elevation" = "elevation"}). Time
placeholders must match entries in \code{time_cols}.}

\item{time_cols}{Character vector of time placeholders for dynamic variables.
Default is \code{NULL}.}

\item{output_suffix}{Character. Suffix to append to output raster filenames.
Default is \code{"_Scaled"}.}

\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. Includes per-variable scaling progress.}
}
\value{
Invisibly returns a list containing:
\itemize{
  \item \code{n_scaled}: Integer. Total number of variables successfully
    scaled (static plus dynamic).
  \item \code{output_dir}: Character. Path to the directory containing scaled
    rasters.
}
}
\description{
Preprocessing function that standardizes raster files using precomputed mean
and standard deviation values from species occurrence data. Supports both
temporally static and dynamic rasters.
}
\details{
Applies scaling to rasters via z-score transformation: (value - mean) / sd
as is calculated during \code{\link{temporally_explicit_extraction}}. Scaled
rasters are written to output_dir.

Scaled rasters should use the same scaling parameters derived from species
occurrence data to ensure consistent standardization between training data
and prediction layers.
}
\examples{
aln_dir     <- system.file("extdata/rasters_aligned",
                           package = "TemporalModelR")

params_file <- system.file(
  "extdata/points/extracted_seasonal_Scaling_Parameters.csv",
  package = "TemporalModelR"
)

out_dir <- file.path(tempdir(), "scaled")

scale_rasters(
  input_dir           = aln_dir,
  output_dir          = out_dir,
  scaling_params_file = params_file,
  variable_patterns   = c(
    "elevation"    = "elevation",
    "forest_cover" = "forest_cover_YEAR",
    "prseas"       = "prseas_YEAR_SEASON"
  ),
  time_cols           = c("year", "season"),
  overwrite           = TRUE,
  verbose             = FALSE
)
}
\seealso{
Preprocessing: \code{\link{temporally_explicit_extraction}},
  \code{\link{raster_align}}
}
