% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/select_phase.R
\name{select_phase}
\alias{select_phase}
\title{Select and Label Phenophases from PEP Time Series}
\usage{
select_phase(dt, label, sp, yrmin, phases = c(60, 100))
}
\arguments{
\item{dt}{A \code{data.table} containing columns \code{species}, \code{year}, \code{phase_id}, and \code{mean_day}.
Typically produced by aggregating PEP725 data (e.g., via \code{\link{pheno_regional}}).}

\item{label}{A character string used as identifier for source and site columns in the output.}

\item{sp}{Species name (as character string) to filter, e.g., \code{"Triticum aestivum"}.}

\item{yrmin}{Minimum year (inclusive) for filtering.}

\item{phases}{Integer vector of phase IDs to include (default: \code{c(60, 100)} corresponding to "Heading" and "Harvest").}
}
\value{
A \code{data.table} with columns:
\describe{
\item{\code{year}}{Year of observation}
\item{\code{phase}}{Mapped BBCH phenological stage name}
\item{\code{DOY}}{Mean day-of-year for this phase, species, and year}
\item{\code{source}}{Set to \code{label}}
\item{\code{site}}{Set to \code{label}}
}
}
\description{
Extracts a subset of phenological observations from a processed PEP time series (e.g., output from species-level aggregation),
filters by species, year, and phenophase ID, and attaches meaningful phase labels based on standard BBCH codes.
}
\details{
This function uses an internal lookup table to map numeric \code{phase_id} codes to descriptive BBCH phase names (e.g., \code{60 = "Heading"}, \code{100 = "Harvest"}).
Unmapped phase IDs will trigger a warning. If expected phases are missing from the result, a separate warning is issued.

The function is particularly useful for visualizing specific growth stages or comparing phenological trends across datasets and locations.
}
\examples{
\donttest{
pep <- pep_download()
agg <- pheno_regional(pep, species_name = "Triticum aestivum", phase = 60)$pep_agg
df <- select_phase(agg, label = "PEP725", sp = "Triticum aestivum", yrmin = 1961)
head(df)
}

}
\seealso{
\code{\link{pheno_regional}}, \code{\link{pep_download}}, \code{\link{pheno_plot}}
}
\author{
Matthias Templ
}
