View source: R/summary_wind_2d.R
summary_wind_2d | R Documentation |
Input data should be original unbinned data including wind direction and wind velocity; binning is done 2-dimensional over cartesian u and v wind vectors
summary_wind_2d(
data,
ws,
wd,
z,
groupings = grp(),
fun = "mean",
fun.args = list(),
nmin = 3,
ws_max = NA,
bins = 10^2,
smooth = TRUE,
k = 100,
extrapolate = TRUE,
dist = 0.1
)
data |
a data.frame or tibble containing the data (wide format). requires input data including at least three columns carrying information regarding:
|
ws |
symbol giving the wind velocity parameter name (wind velocity preferably in m/s) |
wd |
symbol giving the wind direction parameter name in degrees |
z |
symbol giving the parameter name to be summarised |
groupings |
additional groupings. Use helper |
fun |
function or list of functions for summary. |
fun.args |
a list of extra arguments to pass to fun. |
nmin |
numeric, minimum number of values for fun, if n < nmin: NA is returned |
ws_max |
numeric or Inf, maximum wind velocity for binning: above ws_max, z is set NA |
bins |
numeric, number of bins over the range of values if |
smooth |
TRUE/FALSE, applies if groups = c("u", "v"); should smoothing of summary results should be performed
using |
k |
numeric, applies if smooth = TRUE; degree of smoothing in smooth term in |
extrapolate |
TRUE/FALSE, applies if smooth = TRUE; |
dist |
numeric, fraction of 1, applies if smooth = TRUE and extrapolate = TRUE; maximum distance to next coordinate-pair at which the result of fit_gam_surface(z) should be returned |
a tibble with summarised data along u and v wind vectors
a tibble is returned, binned over u and v, with variables:
wd: wind direction corresponding to midpoint value of u and v
ws: wind velocity corresponding to midpoint value of u and v
u: midpoints of bins over u (from input wd and ws)
v: midpoints of bins over v (from input wd and ws)
z: result from fun(z, ...)
library(ggplot2)
fn <- rOstluft.data::f("Zch_Stampfenbachstrasse_2010-2014.csv")
data <- rOstluft::read_airmo_csv(fn)
data <- rOstluft::rolf_to_openair(data)
# summary NO2
summary_wind_2d(data, ws, wd, NOx, smooth = FALSE)
# multiple stats: Pass function, by name, reference, as function or one sided formula
funs <- list(
"mean",
"median" = function(x) median(x, na.rm = TRUE),
"q95" = ~ stats::quantile(., probs = 0.95)
)
summary_wind_2d(data, ws, wd, NOx, fun = funs, smooth = FALSE)
# is for some reason fun.args used with multiple functions, use ... to catch
# superfluous arguments:
funs <- list(
"q95" = function(x, ...) stats::quantile(x, probs = 0.95),
"mean"
)
summary_wind_2d(data, ws, wd, NOx, fun = funs, fun.args = list(na.rm = TRUE),
smooth = FALSE)
# additional groupings
summary_wind_2d(data, ws, wd, NOx, groupings = grp(site), smooth = FALSE)
# we can use expressions in grp For better readability groupings is
# defined outside of the function call
groupings = grp("site", year = lubridate::year(date))
summary_wind_2d(data, ws, wd, NOx, groupings = groupings, smooth = FALSE)
# smoothing
df1 <- summary_wind_2d(data, ws, wd, NOx, bins = 100^2, smooth = FALSE)
df2 <- summary_wind_2d(data, ws, wd, NOx, bins = 100^2, extrapolate = FALSE)
df3 <- summary_wind_2d(data, ws, wd, NOx, bins = 100^2, smooth = TRUE)
df <- dplyr::bind_rows(
"smooth = F" = df1,
"smooth = T, extrapolate = F" = df2,
"smooth = T, extrapolate = T" = df3,
.id = "smoothing"
)
ggplot(df, aes(x = u, y = v, fill = NOx)) +
coord_fixed(expand = FALSE) +
lims(x = c(-7.5, 7.5), y = c(-7.5, 7.5)) +
geom_raster() +
scale_fill_viridis_c(na.value = NA) +
facet_wrap(vars(smoothing), ncol = 2)
# for a small number of bins reduce k
summary_wind_2d(data, ws, wd, NO2, bins = 5^2, smooth = TRUE, k = 5)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.