stress_days_over {cropgrowdays}R Documentation

The number of days that maximum temp is over a baseline value

Description

Calculate the number of days when the maximum temperature exceeds a base line stress_temp during specified dates for a tibble or data frame of daily weather data. Alternatively, a number of days before or after a specific date may be specified. The default value of stress_temp is 30 degrees C.

Usage

stress_days_over(
  data,
  var = NULL,
  datevar = NULL,
  ndays = 5,
  na.rm = FALSE,
  stress_temp = 30,
  startdate = NULL,
  enddate = NULL,
  monitor = FALSE,
  warn.consecutive = TRUE,
  ...
)

Arguments

data

Tibble or dataframe of daily weather data

var

Variable to be extracted (Default: maxt)

datevar

Date variable specifying day (Default: date_met)

ndays

Number of days after/before the start or end date, respectively. Ignored of both the start and end dates are specified (Default: 5)

na.rm

Used for calculations (Default: FALSE)

stress_temp

A numeric value set to the temperature considered to be stressful if the maximum temperature exceeds (Default: 30)

startdate

Start date of data to be extracted

enddate

Final date of data to be extracted

monitor

For debugging. Prints data and dates. (Default: FALSE)

warn.consecutive

A logical indicating whether to check that dates are consecutive, that none are missing and provide a warning if not (Default:TRUE)

...

options to be passed to sum calculation

Details

The number of days is returned but if there are any missing values, then the sum is set to NA since the default na.rm is TRUE. Note that if there are any missing dates, then a warning is issued but the sum of non-missing values is returned.

If any values are missing, while the number of days over stress_temp total may prove useful, it will not include all the data and so may lead to biased underestimates. Hence, depending on the time of year, it may be unlikely that this is a good estimate but the appropriateness of the estimate will depend on the exact circumstances of the missing data and so this decision is left to the user.

Value

Numeric variable containing the number of days where the maximum temperature was above the specified stress temperature cutoff

See Also

cumulative, daily_mean, growing_degree_days, and weather_extract

Examples

##  Selected calculations
## library(tidyverse) # only purrr used here for crop2 example
library(dplyr)
library(purrr)
stress_days_over(boonah, enddate = crop$flower_date[4], ndays = 3,
                 monitor = TRUE)
stress_days_over(boonah, enddate = crop$harvest_date[4], ndays = 3,
                 monitor = TRUE)
stress_days_over(boonah, startdate = crop$flower_date[4],
                 enddate = crop$harvest_date[4], monitor = TRUE)

## Add selected stress days at 'boonah' to 'crop' tibble
## using 'map2_dbl' from the 'purrr' package
## Note: using equivalent 'furrr' functions can speed up calculations 
crop2 <- crop |>
  mutate(stressdays25_post_sow_7d =
          purrr::map_dbl(sowing_date, function(x)
            stress_days_over(boonah, startdate = x, ndays = 7,
                             stress_temp = 25)),
          stressdays_flower_harvest =
            purrr::map2_dbl(flower_date, harvest_date, function(x, y)
              stress_days_over(boonah, startdate = x, enddate = y)))
crop2


[Package cropgrowdays version 0.2.1 Index]