Skip to contents

For each candidate window, subsets the weather series relative to a reference time and computes summary features. The reference can be an assessment date, planting date, flowering date, inoculation date, or any other biologically meaningful timestamp.

Usage

scan_windows(
  weather,
  reference_time,
  windows,
  weather_cols,
  time_col = "time",
  unit = c("days", "hours"),
  statistics,
  sampling_interval = NULL,
  max_allowed_missing_pct = NULL
)

Arguments

weather

A weather data frame.

reference_time

Reference time used to place the candidate windows.

windows

A data frame created by make_windows() or define_windows().

weather_cols

Required character vector of existing numeric weather columns. Column names must be unique, non-missing, and non-empty. If named, every entry must have a unique, non-missing, non-empty output alias; .conditions is reserved. No columns are inferred. Use character() explicitly for condition-only summaries.

time_col

Name of the weather timestamp column.

unit

Time unit for relative-time windows. One of "days" or "hours".

statistics

Required summary specification. Use a non-empty character vector to apply the same statistics to all weather_cols, such as c("mean", "sd", "IQR"). Alternatively, use a named list keyed by every selected column's output alias (or column name when unnamed), with no unknown keys. Each entry must be a non-empty character vector or a nested named list of functions or single function names, for example list(temp = list(avg = "mean", spread = stats::sd)). Statistic names must be unique, non-missing, and non-empty. No summaries are inferred. The optional .conditions entry is a named list of multivariable condition summaries such as count_when(temp >= 18 & rh >= 90).

sampling_interval

Expected spacing between measurements, in unit. If NULL, uses the shortest gap between recorded timestamps within the series, or one unit if fewer than two timestamps are available. Supply the spacing when gaps may hide the actual sampling frequency.

max_allowed_missing_pct

Optional maximum missing percentage (0 to 100). If any window exceeds it, drop that predictor across windows. The missing_pct_ diagnostics are retained. NULL keeps all predictors.

Value

A list of two data frames with one row per candidate window. features contains window metadata and summary metrics. coverage contains window metadata, row counts, and missing percentages.

Details

The configured time column cannot be selected in weather_cols. Summary names must not collide with window metadata. An empty window grid is returned unchanged after validating the explicit summary specification.