Open hdugan opened 2 weeks ago
Mode is mathematical term for the most common value. I know using hourly data would be a lot of this type of app, so mode is probably the best choice. Although it gets weird pairing it with wind speed.
Here's an example
library(EDIutils)
library(tidyverse)
# custom functions for mode and rounding
modes <- function(x) {
ux <- unique(x)
tab <- tabulate(match(x, ux))
modes = ux[tab == max(tab)]
modes[1] # get most common
}
round_any = function(x, accuracy, f=round){f(x/ accuracy) * accuracy}
# Get BOYM Wind Speed from EDI
scope = "knb-lter-mcm"
identifier = 7003
revision = list_data_package_revisions(scope, identifier, filter = "newest")
packageId <- paste(scope, identifier, revision, sep = ".")
res <- read_data_entity_names(packageId)
entityId <- res$entityId[7]
raw <- read_data_entity(packageId, entityId)
# Download data
lb.wind <- readr::read_csv(file = raw) |>
mutate(date_time = mdy_hm(date_time)) %>%
mutate(date = as.Date(date_time))
# Create daily mode wdir and mean wspd
lb.daily = lb.wind %>%
filter(!is.na(wdir)) %>%
group_by(date) %>%
mutate(wd2 = round_any(wdir, accuracy = 2), ws = round_any(wdir, accuracy = 2)) |> # bin by 2°
summarise(wd = modes(wd2), ws = mean(wspd, na.rm = T)) # mode wind direction and mean wind speed
A challenge with using a daily average wind speed for wind roses is you end up with a direction that is not realistic. Bonney is a great example. The two dominant wind directions are NE and SW (and these switch daily). As a result, your daily wind rose is from the SE (which doesn't reflect a real wind direction). Example below:
wind_BOYM.pdf
To correct this, a mode wind direction might make more sense if you want to stick with daily data.