Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/hrbrmstr/weatherkit

šŸŽšŸŒ”šŸ”Ž Obtain Historical, Current, and Predictive Weather Data from Apple WeatherKit REST API in R
https://github.com/hrbrmstr/weatherkit

darksky r rstats weatherkit weatherkit-rest-api

Last synced: 3 months ago
JSON representation

šŸŽšŸŒ”šŸ”Ž Obtain Historical, Current, and Predictive Weather Data from Apple WeatherKit REST API in R

Awesome Lists containing this project

README

        

---
output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```

```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
```

```{r description, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::yank_title_and_description()
```

## What's Inside The Tin

The following functions are implemented:

```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```

## Installation

```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```

## NOTE

Please reference the local [Authorization](authorization.md) documentation or use `vignette("authorization", package="weatherkit")` at an R console for information on how to obtain the necessary authentication and signing components required to use the WeatherKit REST API from this package.

If your apps, web apps, or websites display any Apple weather data (other than weather alerts or value-added services or products, as described below), you must clearly display the Apple Weather trademark (ļ£æ Weather), as well as the [legal link to other data sources](https://weatherkit.apple.com/legal-attribution.html).

## Usage

```{r lib-ex}
library(weatherkit)
library(ragg)

# current version
packageVersion("weatherkit")

```

```{r availability}
wxkit_availability(43.2683199, -70.8635506, "US")
```

```{r weather}
wx <- wxkit_weather(43.2683199, -70.8635506)
wx <- wx_tidy(wx)
str(wx)
```

```{r current-conditions}
current_conditions(wx)
```

```{r hourly-forecast}
hourly_forecast(wx)
```

```{r daily-forecast}
daily_forecast(wx)
```

```{r wx-alerts, eval=FALSE}
# weatherAlerts structure

List of 4
$ name : chr "WeatherAlertCollection"
$ metadata :List of 9
$ detailsUrl: chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
$ alerts :'data.frame': 1 obs. of 18 variables:
> str(y$weatherAlerts)
List of 4
$ name : chr "WeatherAlertCollection"
$ metadata :List of 9
..$ attributionURL: chr "https://weather-data.apple.com/legal-attribution.html"
..$ expireTime : chr "2022-07-28T18:13:02Z"
..$ language : chr "en-US"
..$ latitude : num 43.3
..$ longitude : num -70.9
..$ providerName : chr "National Weather Service"
..$ readTime : chr "2022-07-28T18:08:02Z"
..$ reportedTime : chr "2022-07-28T18:08:02Z"
..$ version : int 1
$ detailsUrl: chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
$ alerts :'data.frame': 1 obs. of 18 variables:
..$ name : chr "WeatherAlertSummary"
..$ id : chr "55f14171-c72f-5340-8003-9b51e52d14e5"
..$ areaId : chr "mez018"
..$ areaName : chr "Interior York"
..$ countryCode : chr "US"
..$ description : chr "Special Weather Statement"
..$ effectiveTime: chr "2022-07-28T17:42:00Z"
..$ expireTime : chr "2022-07-28T19:00:00Z"
..$ issuedTime : chr "2022-07-28T17:42:00Z"
..$ detailsUrl : chr "https://weather-data.apple.com/alertDetails/index.html?ids=55f14171-c72f-5340-8003-9b51e52d14e5&lang=en-US&time"| __truncated__
..$ precedence : int 0
..$ severity : chr "minor"
..$ source : chr "National Weather Service"
..$ eventSource : chr "US"
..$ urgency : chr "expected"
..$ certainty : chr "observed"
..$ importance : chr "low"
..$ responses :List of 1
.. ..$ : list()
```

```{r temps, dev="ragg_png", fig.width=800/96, fig.height=500/96}
library(ggtext)
library(ggforce)
library(hrbragg) # remotes::install_github("hrbrmstr/hrbragg")
library(ggplot2)
library(weatherkit)

data.frame(
x = celsius_to_fahrenheit(wx$forecastDaily$days$temperatureMin),
xend = celsius_to_fahrenheit(wx$forecastDaily$days$temperatureMax),
y = as.integer(as.Date(wx$forecastDaily$days$forecastStart))
) -> xdf

xdf |>
ggplot() +
geom_link(
aes(
x, y, xend=xend, yend=y,
colour = stat(index)
),
linewidth = 4, # remotes::install_github("tidyverse/ggplot2")
lineend = "round",
show.legend = FALSE
) +
scale_x_continuous(
name = NULL,
label = function(x) sprintf("%sĀ°F", x),
sec.axis = dup_axis()
) +
scale_y_reverse(
name = NULL,
breaks = seq_rng(xdf$y),
labels = function(x) {
x <- as.Date(x, origin="1970-01-01")
ifelse(x == Sys.Date(), "Today", strftime(x, "%a"))
},
sec.axis = dup_axis()
) +
scale_colour_viridis_c(
option = "cividis"
) +
labs(
title = "Weather for Berwick, Maine"
) +
theme_gs(grid="XY", axis_text_size = 12) +
theme(
axis.title.x.top = element_blank(),
axis.text.y.left = element_markdown(family = "Inter"),
axis.text.y.right = element_markdown(family = "Inter"),
panel.grid.major.x = element_line(linetype = "dotted", size = 0.5),
panel.grid.major.y = element_line(linetype = "dotted", size = 0.5)
)
```

## weatherkit Metrics

```{r cloc, echo=FALSE}
cloc::cloc_pkg_md()
```

## Code of Conduct

Please note that this project is released with a Contributor Code of Conduct.
By participating in this project you agree to abide by its terms.