Degree days transformation and aggregation of climate data
Source:R/staggregate.R
staggregate_degree_days.Rd
The function staggregate_degree_days()
aggregates climate data to the daily
level, performs a degree days transformation on these daily values, and
aggregates the transformed values to the polygon level and desired temporal
scale
Usage
staggregate_degree_days(
data,
overlay_weights,
time_agg = "month",
start_date = NA,
time_interval = "1 hour",
thresholds
)
Arguments
- data
The raster brick with the data to be transformed and aggregated
- overlay_weights
A table of weights which can be generated using the function
overlay_weights()
- time_agg
the temporal scale to aggregate data to. Options are
'day'
,'month'
, or'year'
- start_date
the date (and time, if applicable) of the first layer in the raster. To be input in a format compatible with lubridate::as_datetime(), e.g.
"1991-10-29"
or"1991-10-29 00:00:00"
. The default isNA
since the rasters usually already contain temporal information in the layer names and they do not need to be manually supplied.- time_interval
the time interval between layers in the raster to be aggregated. To be input in a format compatible with seq(), e.g.
'1 day'
or'3 months'
. The default is'1 hour'
and this argument is required if thestart_date
argument is notNA
.- thresholds
A vector of temperature thresholds critical to a crop
Examples
degree_days_output <- staggregate_degree_days(
data = temp_nj_jun_2024_era5 - 273.15, # Climate data to transform and
# aggregate
overlay_weights = overlay_weights_nj, # Output from overlay_weights()
time_agg = "month", # Sum the transformed daily values across months
start_date = "2024-06-01 00:00:00", # The start date of the supplied data,
# only required if the layer name
# format is not compatible with stagg
time_interval = "1 hour", # The temporal interval of the supplied data,
# only required if the start_date is not NA
thresholds = c(0, 10, 20) # Calculate degree days above 0, 10, and 20
# degrees Celsius
)
#> Rewriting the data's temporal metadata (layer names) to reflect a dataset starting on the supplied start date and with a temporal interval of 1 hour
#> Skipping pre-transformation aggregation to daily level
#> Executing degree days transformation
#> Aggregating by polygon and month
head(degree_days_output)
#> year month poly_id threshold_ninf_to_0 threshold_0_to_10 threshold_10_to_20
#> <num> <num> <char> <num> <num> <num>
#> 1: 2024 6 011 0 7200 7057.782
#> 2: 2024 6 033 0 7200 6994.112
#> 3: 2024 6 015 0 7200 6929.559
#> 4: 2024 6 009 0 7200 7135.649
#> 5: 2024 6 007 0 7200 6935.083
#> 6: 2024 6 041 0 7200 6480.811
#> threshold_20_to_inf
#> <num>
#> 1: 3179.867
#> 2: 3414.202
#> 3: 3365.634
#> 4: 2146.668
#> 5: 3407.180
#> 6: 2724.483