diff --git a/R/data.R b/R/data.R index 73736e4c..4fe71497 100644 --- a/R/data.R +++ b/R/data.R @@ -1,8 +1,11 @@ #' Australia climate data #' -#' Daily measure on precipitation (\code{prcp}), maximum temperature -#' (\code{tmax}), and minimum temperature (\code{tmin}) in 2020 for -#' 639 stations. +#' \code{climate_aus}: daily measure on precipitation (\code{prcp}), +#' maximum temperature (\code{tmax}), and minimum temperature (\code{tmin}) +#' in 2020 for 639 stations. \code{historical_tmax}: daily maximum temperature +#' (\code{tmax}) for 75 stations in Victoria and New South Wales for two +#' periods: 1971-1975 and 2016-2020. +#' #' @details #' \describe{ #' \item{id}{station ID, "ASN000" are international paddings, the next @@ -16,13 +19,17 @@ #' \item{elev}{elevation of the stations} #' \item{name}{station name} #' \item{wmo_id}{the world meteorological organisation (WMO) station number} -#' \item{ts}{a list-column that nests all the temporal variables: -#' date, prcp, tmax, and tmin} +#' \item{ts}{For \code{climate_aus}: date, prcp, tmax, and tmin, for +#' \code{historical_tmax}: date and tmax} #' } +#' @rdname climate-data #' @examples #' climate_aus %>% face_temporal() %>% face_spatial() "climate_aus" +#' @rdname climate-data +"historical_tmax" + #' Toy climate data #' #' Daily measure (2020-01-01 to 2020-01-10) on precipitation (prcp), diff --git a/data-raw/prcp_aus.R b/data-raw/prcp_aus.R deleted file mode 100644 index 084dfaa3..00000000 --- a/data-raw/prcp_aus.R +++ /dev/null @@ -1,36 +0,0 @@ -## code to prepare `prcp_aus` dataset goes here -library(rnoaa) -library(tidyverse) -library(cubble) - -aus_stations <- all_stations %>% - filter(element == "PRCP", !is.na(wmo_id)) - -# query the climate data for the selected station (may take a while if run for -# the first time) -raw <- aus_stations %>% - rowwise() %>% - mutate(ts = list( - meteo_pull_monitors( - monitors = id, - var = c("PRCP"), - date_min = "2016-01-01", - date_max = "2020-12-31" - ) %>% - select(-id) - ) - ) - -raw_cb <- raw %>% - select(-c(element:last_year)) %>% - unnest(ts) %>% - cubble::as_cubble(key = id, index = date, coords = c(long, lat)) - -prcp_aus <- raw_cb %>% - face_temporal(ts) %>% - mutate(wk = lubridate::week(date)) %>% - group_by(wk) %>% - summarise(prcp = sum(prcp, na.rm = TRUE)) %>% - face_spatial() - -usethis::use_data(prcp_aus, overwrite = TRUE) diff --git a/data-raw/tmax-hist.R b/data-raw/tmax-hist.R index 8a779f26..9fd35ab3 100644 --- a/data-raw/tmax-hist.R +++ b/data-raw/tmax-hist.R @@ -1,38 +1,39 @@ -## code to prepare `DATASET` dataset goes here -library(rnoaa) library(tidyverse) library(cubble) -all_stations <- ghcnd_stations() %>% - filter(str_starts(id, "ASN")) %>% - filter(last_year >= 2020) %>% - mutate(wmo_id = as.numeric(wmo_id), - name = str_to_lower(name)) %>% - select(-state, -gsn_flag) +all_stations <- rnoaa::ghcnd_stations() |> + filter(str_starts(id, "ASN")) |> # Australian stations start wiht "ASN" + filter(last_year >= 2020) |> + mutate(wmo_id = as.numeric(wmo_id), name = str_to_lower(name)) |> + select(-state, -gsn_flag) |> + select(id, longitude, latitude, elevation, name, + wmo_id, element, first_year, last_year) |> + rename(long = longitude, lat = latitude, elev = elevation) -cand <- all_stations %>% - filter(element == "TMAX", - first_year < 1970, - !is.na(wmo_id)) +tmax_stations <- all_stations |> + filter(element == "TMAX", first_year < 1970, !is.na(wmo_id)) %>% + filter(between(as.numeric(stringr::str_sub(id, 7, 8)), 46, 90)) %>% + filter(!id %in% c("ASN00047048", "ASN00085279", "ASN00085298")) %>% + select(-c(element:last_year)) -historical_tmax <- cand %>% - rowwise() %>% - mutate(ts = list(meteo_pull_monitors( - monitors = id, var = "TMAX", - date_min = glue::glue("{first_year}-01-01"), - date_max = glue::glue("{last_year}-12-31")) |> - select(-id))) %>% - as_cubble(index = date, key = id, coords = c(longitude, latitude)) +tmax71 <- rnoaa::meteo_pull_monitors( + monitors = tmax_stations$id, var = "TMAX", + date_min = glue::glue("1971-01-01"), + date_max = glue::glue("1975-12-31") +) -tmax_hist <- historical_tmax |> - face_temporal() |> - mutate(tmax = tmax / 10) |> - filter(between(lubridate::year(date), 1970, 1975) | - lubridate::year(date) > 2015) |> - mutate(yearmonth = tsibble::yearmonth(date)) |> - group_by(yearmonth) |> - summarise(tmax = mean(tmax, na.rm = TRUE)) |> - face_spatial() |> - select(-c(element:last_year)) |> - filter(stringr::str_sub(id, 7, 8) >= 76) +tmax16 <- rnoaa::meteo_pull_monitors( + monitors = tmax_stations$id, var = "TMAX", + date_min = glue::glue("2016-01-01"), + date_max = glue::glue("2020-12-31") +) -usethis::use_data(tmax_hist, overwrite = TRUE, compress = "gzip") +tmax <- tmax71 %>% + bind_rows(tmax16) %>% + arrange(id, date) %>% + mutate(tmax = tmax /10) + +historical_tmax <- make_cubble( + spatial = tmax_stations, temporal = tmax, + key = id, index = date, coords = c(long, lat)) + +usethis::use_data(historical_tmax, overwrite = TRUE) diff --git a/data/historical_tmax.rda b/data/historical_tmax.rda new file mode 100644 index 00000000..f1fa5949 Binary files /dev/null and b/data/historical_tmax.rda differ diff --git a/man/climate_aus.Rd b/man/climate-data.Rd similarity index 63% rename from man/climate_aus.Rd rename to man/climate-data.Rd index 9d548a8b..1786b442 100644 --- a/man/climate_aus.Rd +++ b/man/climate-data.Rd @@ -3,17 +3,24 @@ \docType{data} \name{climate_aus} \alias{climate_aus} +\alias{historical_tmax} \title{Australia climate data} \format{ An object of class \code{spatial_cubble_df} (inherits from \code{cubble_df}, \code{tbl_df}, \code{tbl}, \code{data.frame}) with 639 rows and 7 columns. + +An object of class \code{spatial_cubble_df} (inherits from \code{cubble_df}, \code{tbl_df}, \code{tbl}, \code{data.frame}) with 75 rows and 7 columns. } \usage{ climate_aus + +historical_tmax } \description{ -Daily measure on precipitation (\code{prcp}), maximum temperature -(\code{tmax}), and minimum temperature (\code{tmin}) in 2020 for -639 stations. +\code{climate_aus}: daily measure on precipitation (\code{prcp}), +maximum temperature (\code{tmax}), and minimum temperature (\code{tmin}) +in 2020 for 639 stations. \code{historical_tmax}: daily maximum temperature +(\code{tmax}) for 75 stations in Victoria and New South Wales for two +periods: 1971-1975 and 2016-2020. } \details{ \describe{ @@ -28,8 +35,8 @@ See http://www.bom.gov.au/climate/cdo/about/site-num.shtml} \item{elev}{elevation of the stations} \item{name}{station name} \item{wmo_id}{the world meteorological organisation (WMO) station number} -\item{ts}{a list-column that nests all the temporal variables: -date, prcp, tmax, and tmin} +\item{ts}{For \code{climate_aus}: date, prcp, tmax, and tmin, for +\code{historical_tmax}: date and tmax} } } \examples{ diff --git a/man/dplyr.Rd b/man/dplyr.Rd index 214e81ad..cf803b55 100644 --- a/man/dplyr.Rd +++ b/man/dplyr.Rd @@ -13,7 +13,6 @@ \alias{rename.spatial_cubble_df} \alias{rename.temporal_cubble_df} \alias{bind_rows.temporal_cubble_df} -\alias{bind_rows.spatial_cubble_df} \alias{bind_cols.spatial_cubble_df} \alias{bind_cols.temporal_cubble_df} \alias{rowwise.spatial_cubble_df} @@ -52,8 +51,6 @@ bind_rows.temporal_cubble_df(..., .id = NULL) -bind_rows.spatial_cubble_df(..., .id = NULL) - bind_cols.spatial_cubble_df(..., .name_repair) bind_cols.temporal_cubble_df(..., .name_repair)