Tools for transforming weather time series into model-ready features for plant disease epidemiology. The package supports relative-time window panes around biological reference dates, biologically interpretable weather summaries, feature screening, and functional data analysis workflows for comparing weather trajectories between disease classes.
windcut is an R package for plant disease epidemiologists who need to turn
raw weather time series into model-ready predictors. The first version focuses
on relative-time weather windows: generate candidate windows before, after, or
around a biological reference date, summarise the weather inside each window,
and return a wide feature table ready for modeling.
The package website can be built locally with:
source("scripts/build_site.R")
windcut?Disease intensity is often driven by weather in biologically meaningful periods that are not known in advance. Instead of choosing one arbitrary period, you can scan many windows relative to each reference date and ask which combination of timing and weather variables is most informative.
Windows can be generated in two ways: fixed-width windows that slide through
time, such as window_m05_z00, window_m04_p01, and window_m03_p02, or
variable-width windows that also compare different exposure durations. In these
labels, m means before the reference date, z means the reference date, and
p means after the reference date.
make_windows().scan_windows().window_pane().screen_window_features().screen_feature_correlations().Install the development version from GitHub:
pak::pak("AlvesKS/windcut")
library(windcut)
weather <- window_pane_demo_data$weather
assessments <- window_pane_demo_data$assessments
windows <- make_windows(
min_offset = -21,
max_offset = 0,
width = 7,
reference_col = "assessment_time"
)
features <- window_pane(
weather = weather,
assessments = assessments,
id_col = "site_id",
response_col = "disease_intensity",
windows = windows,
reference_col = "assessment_time",
weather_cols = c(
"daily_mean_temp",
"daily_mean_rh",
"daily_sum_rain",
"daily_sum_leaf_wetness"
),
statistics = list(
daily_mean_temp = c("mean", "max"),
daily_mean_rh = list(humid_days = count_at_or_above(90)),
daily_sum_rain = list(total = "sum"),
daily_sum_leaf_wetness = list(wet_days = count_above(0))
)
)
ranked <- screen_window_features(
data = features,
response_col = "disease_intensity",
method = "spearman"
)
less_redundant <- screen_feature_correlations(
data = features,
exclude_cols = c("site_id", "assessment_time", "disease_intensity"),
method = "spearman",
threshold = 0.8
)
statistics can use ordinary R summary names, custom functions, and
multivariable conditions. This lets you create predictors such as humid
observations, temperature-range exposure, rain events, wetness spells, and
infection-favorable periods.
Supply both weather_cols and statistics explicitly. An unnamed
weather_cols vector keeps the original column names; a named vector uses its
names as output aliases. A shared character vector of statistics applies to
every selected variable. A named list must cover exactly those variables (or
aliases), with custom functions nested under each variable and an optional
.conditions entry. For conditions alone, use weather_cols = character().
Condition expressions refer to original input column names, not aliases.
weather <- simulate_weather_series()
weather <- weather |>
derive_vpd(temp, rh) |>
derive_leaf_wetness_from_rh(rh, threshold = 90)
summary_statistics <- list(
temp = list(
mean = "mean",
max = "max",
hours_18_26 = count_between(18, 26),
degree_hours_10 = degree_hours_above(10)
),
rh = list(
mean = "mean",
humid_hours = humid_hours(90),
prop_humid = proportion_at_or_above(90)
),
rain = list(
total = "sum",
rainy_hours = rainy_hours(0),
rain_events = rain_events(0.2)
),
leaf_wetness_est = list(
wet_hours = wet_hours(0),
max_wet_spell = max_consecutive_wet_hours(0)
),
.conditions = list(
favorable_hours = count_when(temp >= 18 & temp <= 26 & rh >= 90),
max_favorable_spell = max_consecutive_when(temp >= 18 & temp <= 26 & rh >= 90),
warm_rain_total = sum_when(rain, temp >= 18 & temp <= 28)
)
)
windows <- make_windows(min_offset = -72, max_offset = 0, width = 24, reference_col = "assessment_time")
assessments <- simulate_assessment_data(weather)
features <- window_pane(
weather = weather,
assessments = assessments,
windows = windows,
reference_col = "assessment_time",
weather_cols = c("temp", "rh", "rain", "leaf_wetness_est"),
statistics = summary_statistics
)
For richer simulated data with daily seasonality, rain events, and one site-specific disease assessment per weather series, use:
weather <- simulate_weather_series(
days = 45,
n_series = 8,
id_col = "site_id",
seed = 40
)
assessments <- simulate_assessment_data(weather, id_col = "site_id", seed = 42)
The result is a single row per assessment with one column per metric-window combination, such as:
temp_mean_window_m03_z00rain_sum_window_m05_z00rh_days_at_or_above_90_window_m10_m05p.adjust()