# Introduction to climatrends

#### Kauê de Sousa

# Summary

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.

# Statement of need

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.

# Usage

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:

- `numeric`
- `array` / `matrix`
- `data.frame`
- `sf`

Methods 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

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

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 daily degree-day values (`return.as = "daily"`), or
- compute the number of days needed to reach a specified heat sum (`return.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

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:

- frost duration,
- accumulated GDD during frost, -latency periods (no frost, no GDD),
- warming periods (positive GDD accumulation).

    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

## Rainfall

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

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`).

## Reference evapotranspiration

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:

- span defines the number of days per time series,
- lat sets the latitude used in the calculation,
- Kc is the crop coefficient.

    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

## References

1.
Kehel, Z., Crossa, J. & Reynolds, M. Identifying Climate Patterns during the Crop-Growing Cycle from 30 Years of CIMMYT Elite Spring Wheat International Yield Trials. in Applied mathematics and omics to assess crop genetic resources for climate change adaptive traits (eds. Bari, A., Damania, A. B., Mackay, M. & Dayanandan, S.) 151–174 (CRC Press, 2016).
2.
Aguilar, E., Peterson, T. C., Obando, P. R., Frutos, R., et al. Changes in precipitation and temperature extremes in Central America and northern South America, 1961–2003. Journal of Geophysical Research 110, D23107 (2005).
3.
Challinor, A. J., Koehler, A.-K., Ramirez-Villegas, J., Whitfield, S. & Das, B. Current warming will reduce yields unless maize breeding and seed systems adapt immediately. Nature Climate Change 6, 954–958 (2016).
4.
Trnka, M., Rötter, R. P., Ruiz-Ramos, M., Kersebaum, K. C., et al. Adverse weather conditions for European wheat production will become more frequent with climate change. Nature Climate Change 4, 637–643 (2014).
5.
Zohner, C. M., Mo, L., Renner, S. S., Svenning, J.-C., et al. Late-spring frost risk between 1959 and 2017 decreased in North America but increased in Europe and Asia. Proceedings of the National Academy of Sciences 201920816 (2020). doi:10.1073/pnas.1920816117
6.
van Etten, J., de Sousa, K., Aguilar, A., Barrios, M., et al. Crop variety management for climate adaptation supported by citizen science. Proceedings of the National Academy of Sciences 116, 4194–4199 (2019).
7.
de Sousa, K., Casanoves, F., Sellare, J., Ospina, A., et al. How climate awareness influences farmers’ adaptation decisions in Central America? Journal of Rural Studies 64, 11–19 (2018).
8.
Sparks, A. H. nasapower: A NASA POWER Global Meteorology, Surface Solar Energy and Climatology Data Client for R. Journal of Open Source Software 3, 1035 (2018).
9.
Prentice, I. C., Cramer, W., Harrison, S. P., Leemans, R., et al. Special Paper: A Global Biome Model Based on Plant Physiology and Dominance, Soil Properties and Climate. Journal of Biogeography 19, 117 (1992).
10.
Wu, J., Guan, D., Yuan, F., Wang, A. & Jin, C. Soil Temperature Triggers the Onset of Photosynthesis in Korean Pine. PLoS ONE 8, e65401 (2013).
11.
Brouwer, C. & Heibloem, M. Irrigation water management: Irrigation water needs. (Food; Agriculture Organization of The United Nations, 1986).