Polynomial transformation and aggregation of climate data
Source:R/staggregate.R
staggregate_polynomial.Rd
The function staggregate_polynomial()
aggregates climate data to the daily
level, raises these daily values to the 1 through nth power, and aggregates
the transformed values to the polygon level and desired temporal scale.
Usage
staggregate_polynomial(
data,
overlay_weights,
daily_agg,
time_agg = "month",
start_date = NA,
time_interval = "1 hour",
degree
)
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()
- daily_agg
How to aggregate hourly values to daily values prior to transformation. Options are
'sum'
,'average'
, or'none'
('none'
will transform values without first aggregating to the daily level)- time_agg
the temporal scale to aggregate data to. Options are
'hour'
,'day'
,'month'
, or'year'
('hour'
cannot be selected unlessdaily_agg = 'none'
)- 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 daily_agg is not'none'
or if thestart_date
argument is notNA
.- degree
the highest exponent to raise the data to
Examples
polynomial_output <- staggregate_polynomial(
data = temp_nj_jun_2024_era5 - 273.15, # Climate data to transform and
# aggregate
overlay_weights = overlay_weights_nj, # Output from overlay_weights()
daily_agg = "average", # Average hourly values to produce daily values
# before transformation
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,
# required if daily_agg is not "none" or if the
# start_date argument is not NA
degree = 4 # Highest order
)
#> 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
#> Averaging over 24 layers per day to get daily values
#> Executing polynomial transformation
#> Aggregating by polygon and month
head(polynomial_output)
#> year month poly_id order_1 order_2 order_3 order_4
#> <num> <num> <char> <num> <num> <num> <num>
#> 1: 2024 6 011 726.5687 17749.71 437408.2 10873488
#> 2: 2024 6 033 733.6797 18116.46 451620.0 11364291
#> 3: 2024 6 015 728.9664 17889.96 443345.9 11091933
#> 4: 2024 6 009 686.7632 15826.99 367227.1 8579171
#> 5: 2024 6 007 730.9276 17985.27 446880.3 11210400
#> 6: 2024 6 041 683.5539 15879.92 375830.3 9051704