Package {TrackTrap}


Title: Calculate and Visualize Degree-Days for Pest Monitoring
Version: 1.1.0
Description: Combines pest trap observations with daily temperatures to calculate and visualize cumulative degree-days. Temperature inputs include 'Daymet' https://daymet.ornl.gov, 'Open-Meteo' https://open-meteo.com/, reports from the California Irrigation Management Information System ('CIMIS') https://cimis.water.ca.gov, and user-supplied daily weather data. Degree-days are calculated using the simple-average method with either an upper threshold applied to the daily mean or an explicitly selected calculation without an upper cutoff. The first positive trap count defines the biofix for every pest, with accumulation beginning on the following day. Negative daily degree-day values are set to zero. Users can provide temperature thresholds and optional thermal reference values. Thermal reference markers and their multiples do not independently establish flight or generation identities. Complete daily calculations and weather provenance are retained with the output to support reproducibility.
License: MIT + file LICENSE
Encoding: UTF-8
Depends: R (≥ 3.5.0)
LazyData: true
Imports: daymetr, dplyr, ggplot2 (≥ 3.4.0), httr, magrittr, utils, rlang, tools
Config/roxygen2/version: 8.1.0
Suggests: testthat (≥ 3.0.0), knitr, rmarkdown
VignetteBuilder: knitr
Config/testthat/edition: 3
NeedsCompilation: no
Packaged: 2026-10-29 05:05:53 UTC; r3113219
Author: Santosh Bhandari [aut, cre], Lalit Kharel [aut], Mahesh Ghimire [aut]
Maintainer: Santosh Bhandari <santoshbhandari4556@gmail.com>
Repository: CRAN
Date/Publication: 2026-10-29 08:50:31 UTC

TrackTrap: Calculate and Visualize Degree-Days for Pest Monitoring

Description

Combines pest trap observations with daily temperatures to calculate and visualize cumulative degree-days. Temperature inputs include 'Daymet' https://daymet.ornl.gov, 'Open-Meteo' https://open-meteo.com/, reports from the California Irrigation Management Information System ('CIMIS') https://cimis.water.ca.gov, and user-supplied daily weather data. Degree-days are calculated using the simple-average method with either an upper threshold applied to the daily mean or an explicitly selected calculation without an upper cutoff. The first positive trap count defines the biofix for every pest, with accumulation beginning on the following day. Negative daily degree-day values are set to zero. Users can provide temperature thresholds and optional thermal reference values. Thermal reference markers and their multiples do not independently establish flight or generation identities. Complete daily calculations and weather provenance are retained with the output to support reproducibility.

Author(s)

Maintainer: Santosh Bhandari santoshbhandari4556@gmail.com

Authors:


Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling rhs(lhs).


Calculate a simple-average degree-day index for trap observations

Description

Calculate a simple-average degree-day index for trap observations

Usage

calc_pest_phenology(
  trap_data,
  pest = NULL,
  lat = NULL,
  lon = NULL,
  weather_source = "open_meteo",
  cimis_csv_path = NULL,
  custom_lower = NULL,
  custom_upper = NULL,
  custom_thermal_requirement = NULL,
  custom_flight_interval = NULL,
  custom_pest_label = NULL,
  upper_cutoff = c("explicit", "none", "horizontal"),
  weather_data = NULL,
  weather_provenance = NULL,
  timezone = "auto",
  open_meteo_model = "era5_land",
  database = NULL
)

Arguments

trap_data

Data frame with date and trap_counts, one row per date.

pest

Optional database code.

lat, lon

Weather coordinates.

weather_source

open_meteo, daymet, cimis_csv, or supplied.

cimis_csv_path

Path to CIMIS Fahrenheit daily report.

custom_lower, custom_upper

Optional Fahrenheit threshold overrides.

custom_thermal_requirement

Optional user-defined thermal marker (Fahrenheit DD).

custom_flight_interval

Deprecated alias for custom_thermal_requirement.

custom_pest_label

Optional plot label.

upper_cutoff

"explicit", "none", or "horizontal". Missing database upper thresholds require an explicit "none" choice or a supplied upper.

weather_data

Optional daily Date, tmin, tmax data in Fahrenheit.

weather_provenance

Description of provided temperatures/station/time convention.

timezone, open_meteo_model

Open-Meteo settings.

database

Optional database; defaults to TrackTrap::pest_thresholds.

Details

Biofix is always the first positive trap count; its DD is excluded. Daily DD is max(min(mean temperature, upper) - lower, 0), or no upper cap.

Value

Original data frame.


Fetch daily historical Open-Meteo temperatures in Fahrenheit

Description

Fetch daily historical Open-Meteo temperatures in Fahrenheit

Usage

fetch_open_meteo(
  lat,
  lon,
  start_date,
  end_date = as.character(Sys.Date()),
  timezone = "auto",
  model = "era5_land"
)

Arguments

lat, lon

Coordinates.

start_date, end_date

Requested dates, inclusive.

timezone

IANA timezone or "auto"

model

Explicit archive model identifier.


Pest temperature thresholds and thermal reference values

Description

Reference parameters and source information for 90 pest records. Missing parameters are stored as NA. Inclusion does not imply that a complete or independently validated phenology model is available.

Usage

pest_thresholds

Format

A data frame with 90 rows and 10 variables:

pest_code

Unique pest identifier.

pest_name

Common name.

scientific_name

Scientific name.

lower_thresh

Lower temperature threshold in degrees Fahrenheit.

upper_thresh

Upper temperature threshold in degrees Fahrenheit, where available.

thermal_requirement_dd

Thermal reference value in Fahrenheit degree-days for the stated endpoint; not necessarily a flight interval.

lower_source

Reference supporting the lower threshold.

upper_source

Reference supporting the upper threshold.

thermal_requirement_source

Reference for the thermal value.

thermal_requirement_endpoint

Developmental or phenological endpoint associated with the thermal value.

Details

Parameter sources and model compatibility require assessment before application. Seasonal event thresholds and developmental requirements are not interchangeable.


Plot trap catches against the calculated DD index

Description

Plot trap catches against the calculated DD index

Usage

plot_trap_phenology(
  pheno_data,
  pest = NULL,
  year = NULL,
  lat = NULL,
  lon = NULL,
  custom_thermal_requirement = NULL,
  repeat_markers = FALSE,
  custom_flight_interval = NULL,
  custom_pest_label = NULL
)

Arguments

pheno_data

Output of calc_pest_phenology().

pest

Optional label only; never used to retrieve marker intervals.

year, lat, lon

Optional title settings.

custom_thermal_requirement

Optional user-defined marker in Fahrenheit DD.

repeat_markers

If TRUE, show user-defined multiples; default FALSE.

custom_flight_interval

Deprecated alias for custom_thermal_requirement.

custom_pest_label

Optional title label.

Details

When a thermal marker is selected, the subtitle displays its value. A matching database reference supplies the developmental endpoint; otherwise the endpoint is reported as unspecified. The caption explains the reference and distinguishes first-capture multiples from observed generations. Database requirements are not automatically selected as markers.