Understanding how climate variability influences ecological and agricultural systems is essential for climate adaptation, biodiversity conservation, and environmental modeling. climatrends provides a unified framework to compute temperature, precipitation, and crop-related climate indices. These indices serve as inputs for crop models, ecological analyses, phenology studies, and assessments of climate trends.
The methods implemented in climatrends have been applied in several research domains, including crop growing cycle analysis1, regional climate trend detection2–5, citizen science in agriculture6, and studies comparing climate trends with farmers’ perceptions7.
Reproducibility (being able to repeat an analysis) and replicability (being able to repeat an experiment) are essential principles in science, yet they remain challenging in many agricultural and ecological studies. Analyses often rely on custom scripts, inconsistent definitions of climate indices, or non-standard workflows, making results difficult to reuse across locations and seasons.
climatrends was developed to address this gap. The package evolved from a collection of scripts used in previous studies and now provides standardized, transparent, and reproducible methods to compute well-established climate indices. The functions are designed to handle heterogeneous testing environments—a common characteristic of decentralized agricultural trials—where locations differ in climate, timing, and growing seasons. The package also supports fixed-period time-series analysis and integrates smoothly with API-based climate data sources (e.g., nasapower).
The temperature, precipitation, and crop-sensitive indices implemented in climatrends draw from validated methods in climatology and crop science. The package is listed in the CRAN Task View for Agricultural Science.
Most functions in climatrends accept a numeric vector of climate data and, optionally, a vector of dates to enable time-series calculations. The package provides S3 methods for objects of classes:
numericarray / matrixdata.framesfMethods for sf and data.frame allow
seamless integration with climate data services accessed through API
clients such as nasapower8.
This vignette introduces the main functions and illustrates how to compute indices commonly used in ecological and agricultural research.
Temperature-based indices are foundational in ecological and crop modeling. They summarize daily temperature dynamics and help identify heat accumulation, thermal stress, and seasonality.
Below we compute temperature indices for the first half of 2019 in Innlandet county, Norway:
library("climatrends")
data("innlandet", package = "climatrends")
temp1 = temperature(innlandet$tmax, innlandet$tmin)
temp1
## maxDT minDT maxNT minNT DTR SU TR CFD WSDI CSDI T10p T90p
## <dbl> <dbl> <dbl> <dbl> <int> <int> <int> <int> <int> <int> <dbl> <dbl>
## 1: 15.13 -14.86 6.77 -19.25 6 0 0 115 4 5 -15.81 9.09
To compute indices for a time series, set
timeseries = TRUE. The argument intervals defines the
window size (in days) for each period:
temp2 = temperature(innlandet$tmax, innlandet$tmin,
dates = innlandet$dates,
timeseries = TRUE,
intervals = 30)
temp2
## id date index value
## <int> <date> <chr> <dbl>
## 1: 1 2019-01-01 maxDT -0.15
## 2: 1 2019-01-01 minDT -14.86
## 3: 1 2019-01-01 maxNT -3.41
## 4: 1 2019-01-01 minNT -18.67
## 5: 1 2019-01-01 DTR 4.35
## ---
## 68: 1 2019-05-31 CFD 3.00
## 69: 1 2019-05-31 WSDI 2.00
## 70: 1 2019-05-31 CSDI 3.00
## 71: 1 2019-05-31 T10p 0.20
## 72: 1 2019-05-31 T90p 11.14
Growing degree-days (GDD) represent accumulated heat over time and
are widely used in phenology to estimate plant and insect developmental
rates9.
climatrends computes GDD using the GDD()
function. Here we calculate GDD using an adjusted equation suited for
cold regions:
gdd = GDD(innlandet$tmax, innlandet$tmin, tbase = 2, equation = "b")
gdd
## gdd
## <dbl>
## 1: 0.00
## 2: 0.00
## 3: 0.00
## 4: 0.00
## 5: 0.00
## ---
## 178: 143.04
## 179: 147.38
## 180: 153.89
## 181: 162.18
## 182: 164.89
The function can also:
return.as = "daily"),
orreturn.as = "ndays").For example, the Korean pine (Pinus koraiensis) requires 105 \(^\circ C\) accumulated GDD to initiate photosynthesis10. Below, we ask the function to compute the number of days required to reach 150 °C for a given location:
lonlat = data.frame(lon = 129.19,
lat = 36.39)
GDD(lonlat,
day.one = "2019-04-01",
last.day = "2019-10-01",
degree.days = 150,
return.as = "ndays")
This means that 45 days were needed to accumulate 150 \(^\circ C\) degree-days during the 2019 season.
Late spring frost occurs when a freezing event follows a period of
accumulated warmth—potentially damaging sensitive early growth stages.
The late_frost() function identifies frost events and
describes:
lf = late_frost(innlandet$tmax,
innlandet$tmin,
dates = innlandet$date,
base = 2)
lf
## date gdd event duration
## <date> <dbl> <fct> <int>
## 1: 2019-01-01 0.00 frost 108
## 2: 2019-04-19 0.00 latent 1
## 3: 2019-04-20 0.00 frost 1
## 4: 2019-04-21 0.00 latent 2
## 5: 2019-04-23 0.00 frost 2
## 6: 2019-04-25 0.98 warming 6
## 7: 2019-05-01 0.00 frost 14
## 8: 2019-05-15 19.14 warming 11
## 9: 2019-05-26 0.00 frost 6
## 10: 2019-06-01 82.48 warming 31
Precipitation indices are available through the
rainfall() function. They follow the same principles as the
temperature indices but use daily precipitation.
Below we illustrate how climatrends works with remote-sensing data
retrieved from NASA POWER through nasapower package:
library("nasapower")
lonlat = data.frame(lon = c(-73.3, -74.5),
lat = c(-6.1, - 6.2))
rain = rainfall(lonlat,
day.one = "2018-11-01",
last.day = "2018-12-31")
rain
Crop-sensitive indices capture climatic variability during key
developmental stages in crop growth. These indices have been used in
agroclimatic assessments and impact studies3,4. Below, we compute them using the
sf method for five spatial locations in Sinop, Brazil:
library("sf")
data("lonlatsf", package = "climatrends")
crop_sensitive(lonlatsf,
day.one = "2018-12-01",
last.day = "2019-01-31",
as.sf = FALSE)
Thresholds for individual indices can be modified using arguments of
the form *.threshold (e.g.,
tmax.threshold).
Evapotranspiration (ETo) is the combined loss of water through
evaporation and plant transpiration, representing a fundamental
component of ecological and agricultural models.
climatrends computes reference evapotranspiration using the
Blaney–Criddle method11, which
is suitable when only temperature data are available.
The ETo() function supports array inputs, where each row
represents a location and each column a day. The argument:
data("temp_dat", package = "climatrends")
eto = ETo(temp_dat,
day.one = "2013-10-28",
span = c(9, 10, 11, 12, 8, 10, 11, 11, 12, 10),
lat = rep(25, 10),
Kc = 0.92)
eto
## ETo
## <dbl>
## 1: 4.21
## 2: 4.34
## 3: 4.13
## 4: 3.50
## 5: 4.02
## 6: 3.75
## 7: 4.02
## 8: 3.89
## 9: 3.91
## 10: 3.65