% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calc_thermal_units.R
\name{calc_thermal_sum}
\alias{calc_thermal_sum}
\title{Calculate Thermal Sum at Phenological Events}
\usage{
calc_thermal_sum(
  pep,
  temp_data,
  t_base = 5,
  t_start = 1,
  by = NULL,
  method = "average"
)
}
\arguments{
\item{pep}{A \code{pep} object or data.table with phenological observations.
Must contain \code{year} and \code{day} columns.}

\item{temp_data}{A data.frame or data.table with daily temperature data.
Must contain columns: \code{year}, \code{doy} (day of year),
\code{tmin}, \code{tmax} (or \code{tmean}).}

\item{t_base}{Numeric. Base temperature (°C). Default 5.}

\item{t_start}{Integer. Start day of year for accumulation. Default 1 (Jan 1).
Use 60 for March 1, etc.}

\item{by}{Character vector. Columns to match temperature data to phenology
(e.g., \code{"s_id"} for station-specific temperatures). Default \code{NULL}
uses same temperature for all observations in a year.}

\item{method}{Character. GDD calculation method (see \code{\link{calc_thermal_units}}).}
}
\value{
The input data with an additional \code{thermal_sum} column containing
the accumulated GDD from \code{t_start} to the observed DOY.
}
\description{
Computes the accumulated thermal units (GDD) from a start date to the
observed phenological event date. Useful for determining the thermal
requirements of different phenophases.
}
\details{
This function joins phenological observations with temperature data and
calculates the thermal sum (accumulated GDD) at each observation date.
This is useful for:
\itemize{
\item Determining thermal requirements of phenophases
\item Comparing thermal sums across years, locations, or species
\item Validating phenological models
}
}
\examples{
\donttest{
# Load phenology data
data(pep_seed)

# Create example temperature data (normally from weather stations/reanalysis)
temp <- data.frame(
  year = rep(2000:2015, each = 365),
  doy = rep(1:365, 16),
  tmin = rnorm(365 * 16, mean = 5, sd = 8),
  tmax = rnorm(365 * 16, mean = 15, sd = 8)
)

# Add thermal sum to phenology data
pep_thermal <- calc_thermal_sum(pep_seed, temp, t_base = 5)
}

}
\seealso{
\code{\link{calc_thermal_units}} for the underlying GDD calculation
}
\author{
Matthias Templ
}
