data-raw/austria.R

library(tidyverse)
library(ggplot2)
library(countrycode)
library(rnoaa)
library(cubble)
library(weatherdata)

worldwide <- ghcnd_stations() %>%
  filter((wmo_id)!= "") %>%
  filter(first_year <= 2016, last_year >= 2020) %>%
  filter_major_three() %>%
  mutate(country = str_sub(id, 1, 2)) %>%
  rename(country_abb = country)

austria_raw <- worldwide %>% filter(country_abb == "AU") %>%
  mutate(ts = list(meteo_pull_monitors(monitors = id,
                                       var = c("PRCP", "TMAX", "TMIN"),
                                       date_min = "2016-01-01",
                                       date_max = "2020-12-31"))) %>%
  as_cubble(index = date, key = id, coords = c(longitude, latitude))

# only 4 stations has a reasonable amount of missing for tmax that allows
# to process
good_id <- austria_raw %>%
  add_missing_prct(prcp:tmin) %>%
  select(id, contains("missing")) %>%
  filter(tmax_missing < 0.1) %>%
  pull(id)

austria <- austria_raw %>%
  filter(id %in% good_id) %>%
  mutate(ts = list(ts %>% select(-prcp, -tmin)))
usethis::use_data(austria, overwrite = TRUE)

################################################################
austria %>%
  face_temporal() %>%
  mutate(yday = lubridate::yday(date),
         year = as.factor(lubridate::year(date)),
         wk = lubridate::week(date)) %>%
  group_by(wk, year) %>%
  summarise(tmax = mean(tmax, na.rm = TRUE)) %>%
  ggplot(aes(x = wk , y = tmax, color = year)) +
  geom_line() +
  facet_wrap(vars(id))
huizezhang-sherry/weatherdata documentation built on June 15, 2022, 6:40 p.m.