% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/events_phase_plots.R
\name{dm_event_climate}
\alias{dm_event_climate}
\title{Extract climate at and before phase events}
\usage{
dm_event_climate(
  x,
  clim_df,
  event = c("phase_start", "phase_end", "max_twd"),
  phase = "all",
  windows = c(0, 1, 3, 6, 12, 24, 48),
  mean_vars = NULL,
  max_vars = NULL,
  min_vars = NULL,
  sum_vars = NULL,
  median_vars = NULL,
  instant_vars = NULL,
  instant_match = c("nearest", "previous", "next")
)
}
\arguments{
\item{x}{Output of \code{phase.zg()} or \code{phase.sc()}.}

\item{clim_df}{Subdaily climate input. This can be a standardized climate
object from \code{read.climate()}, a raw climate data frame, or a valid
climate file path.}

\item{event}{One of \code{"phase_start"}, \code{"phase_end"}, or
\code{"max_twd"}.}

\item{phase}{Phase selector. For \code{ZG_output}: \code{"all"},
\code{"TWD"}, or \code{"GRO"}. For \code{SC_output}: \code{"all"},
\code{"Shrinkage"}, \code{"Expansion"}, or \code{"Increment"}.}

\item{windows}{Numeric vector of antecedent windows in hours, e.g.
\code{c(0, 1, 3, 6, 12, 24, 48)}. A value of \code{0} extracts climate at
the event time.}

\item{mean_vars, max_vars, min_vars, sum_vars, median_vars}{Climate variables to
summarize in antecedent windows.}

\item{instant_vars}{Climate variables to extract at the exact event time.
If \code{NULL}, all selected variables are used.}

\item{instant_match}{Matching rule for event-time extraction:
\code{"nearest"}, \code{"previous"}, or \code{"next"}.}
}
\value{
A tibble with one row per event and climate summaries in the
  requested antecedent windows.
}
\description{
Extracts climate at event times and summarizes climate in windows preceding
those events. Event times can be phase starts, phase ends, or
\code{Max.twd.time} for \code{phase.zg()} output.
}
\examples{
\donttest{
data(gf_nepa17)
data(ktm_clim_hourly)

zg <- phase.zg(df = gf_nepa17[1:800, ], TreeNum = 1)

evt_zg <- dm_event_climate(
  zg,
  ktm_clim_hourly,
  event = "phase_start",
  phase = "all",
  windows = c(0, 1, 3, 6, 12, 24),
  mean_vars = c("temp", "VPD", "RH"),
  max_vars  = c("temp", "VPD"),
  sum_vars  = c("prec")
)

head(evt_zg)

evt_maxtwd <- dm_event_climate(
  zg,
  ktm_clim_hourly,
  event = "max_twd",
  windows = c(0, 1, 3, 6, 12, 24),
  mean_vars = c("temp", "VPD", "RH"),
  max_vars  = c("VPD"),
  sum_vars  = c("prec")
)

head(evt_maxtwd)
}
}
