cumulative {cropgrowdays}R Documentation

Sum of a weather variable between between two dates

Description

Calculates the sum or total of daily values between two dates from a tibble or data frame of daily weather data. Alternatively, a number of days before or after a specific date may be specified. Typically this is used for solar radiation, evaporation or rainfall since the total rainfall, radiation or evaporation during a specified period may prove useful for modelling yield or plant growth.

Usage

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

Arguments

data

Tibble or dataframe of daily weather data

var

Variable(s) to be extracted (Default: radn). Several columns may be specified using column names c(variable1, variable2, ...)

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)

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 sum 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 calculated sum or total may prove useful, it will not include all the data and so may lead to biased underestimates. Hence, in these cases it may be unlikely that the sum 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 sum of all values of the weather variable var during the specified period.

See Also

sum, daily_mean, growing_degree_days, stress_days_over, and weather_extract

Examples

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

## Add selected totals of weather variables in 'boonah' to 'crop'' tibble
## using 'map2_dbl' from the 'purrr' package
## Note: using equivalent 'furrr' functions can speed up calculations 
crop2 <- crop |>
  dplyr::mutate(totalrain_post_sow_7d =
          purrr::map_dbl(sowing_date, function(x)
            cumulative(boonah, var = rain, startdate = x, ndays = 7)),
          totalrad_flower_harvest =
            purrr::map2_dbl(flower_date, harvest_date, function(x, y)
              cumulative(boonah, var = radn, startdate = x, enddate = y)))
crop2

[Package cropgrowdays version 0.2.1 Index]