-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.Rmd
286 lines (210 loc) · 9.08 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r knitr, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
message = FALSE,
warning = FALSE,
dev = "ragg_png",
tidy = "styler",
comment = "#>",
dpi = 300,
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# climaemet <img src="man/figures/logo.png" align="right" width="120"/>
<!-- badges: start -->
[![rOS-badge](https://ropenspain.github.io/rostemplate/reference/figures/ropenspain-badge.svg)](https://ropenspain.es/)
[![CRAN
status](https://www.r-pkg.org/badges/version/climaemet)](https://CRAN.R-project.org/package=climaemet)
[![CRAN_time_from_release](https://www.r-pkg.org/badges/ago/climaemet)](https://cran.r-project.org/package=climaemet)
[![CRAN_latest_release_date](https://www.r-pkg.org/badges/last-release/climaemet)](https://cran.r-project.org/package=climaemet)
[![CRAN
results](https://badges.cranchecks.info/worst/climaemet.svg)](https://cran.r-project.org/web/checks/check_results_climaemet.html)
[![r-universe](https://ropenspain.r-universe.dev/badges/climaemet)](https://ropenspain.r-universe.dev/climaemet)
[![R-CMD-check](https://github.com/rOpenSpain/climaemet/actions/workflows/roscron-check-full.yaml/badge.svg)](https://github.com/rOpenSpain/climaemet/actions/workflows/roscron-check-full.yaml)
[![R-hub](https://github.com/rOpenSpain/climaemet/actions/workflows/rhub.yaml/badge.svg)](https://github.com/rOpenSpain/climaemet/actions/workflows/rhub.yaml)
[![codecov](https://codecov.io/gh/rOpenSpain/climaemet/graph/badge.svg?token=ZD3FL138Z4)](https://app.codecov.io/gh/rOpenSpain/climaemet)
[![DOI](https://img.shields.io/badge/DOI-10.5281/zenodo.5205573-blue)](https://doi.org/10.5281/zenodo.5205573)
[![metacran
downloads](https://cranlogs.r-pkg.org/badges/climaemet)](https://cran.r-project.org/package=climaemet)
[![license](https://img.shields.io/badge/license-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)
[![Project Status: Active -- The project has reached a stable, usable state and
is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
<!-- badges: end -->
The goal of **climaemet** is to serve as an interface to download the climatic
data of the Spanish Meteorological Agency (AEMET) directly from R using their
[API](https://opendata.aemet.es/) and create scientific graphs (climate charts,
trend analysis of climate time series, temperature and precipitation anomalies
maps, "warming stripes" graphics, climatograms, etc.).
Browse manual and vignettes at <https://ropenspain.github.io/climaemet/>.
## AEMET Open Data
AEMET OpenData is a REST API developed by AEMET that allows the dissemination
and reuse of the Agency's meteorological and climatological information. To see
more details visit: <https://opendata.aemet.es/centrodedescargas/inicio>
## License for the original data
Information prepared by the Spanish Meteorological Agency (© AEMET). You can
read about it [here](https://www.aemet.es/en/nota_legal).
A summary for the usage of the data could be interpreted as:
> People can use freely this data. You should mention AEMET as the collector of
> the original data in every situation except if you are using this data
> privately and individually. AEMET makes no warranty as to the accuracy or
> completeness of the data. All data are provided on an "as is" basis. AEMET is
> not responsible for any damage or loss derived from the interpretation or use
> of this data.
## Installation
You can install the released version of **climaemet** from
[CRAN](https://CRAN.R-project.org) with:
```{r, eval=FALSE}
install.packages("climaemet")
```
You can install the developing version of **climaemet** using the
[r-universe](https://ropenspain.r-universe.dev/climaemet):
```{r, eval=FALSE}
# Install climaemet in R:
install.packages("climaemet",
repos = c("https://ropenspain.r-universe.dev", "https://cloud.r-project.org")
)
```
Alternatively, you can install the developing version of **climaemet** with:
```{r, eval=FALSE}
library(remotes)
install_github("ropenspain/climaemet")
```
## API key
To be able to download data from AEMET you will need a free API key which you
can get [here](https://opendata.aemet.es/centrodedescargas/obtencionAPIKey).
```{r, eval=FALSE}
library(climaemet)
## Get api key from AEMET
browseURL("https://opendata.aemet.es/centrodedescargas/obtencionAPIKey")
## Use this function to register your API Key temporarly or permanently
aemet_api_key("MY API KEY")
```
### Changes on v1.0.0!
Now the `apikey` parameter on the functions have been deprecated. You may need
to set your API Key globally using `aemet_api_key()`. Note that you would need
also to remove the `apikey` parameter on your old codes.
## Now **climaemet** is tidy...
From `v1.0.0` onward, **climaemet** provides its results in [`tibble`
format](https://tibble.tidyverse.org/). Also, the functions try to guess the
correct format of the fields (i.e. something as a Date/Hour now is an hour,
numbers are parsed as double, etc.).
```{r tibble, message=TRUE}
library(climaemet)
# See a tibble in action
aemet_last_obs("9434")
```
### Examples
The package provides several functions to access the data of the API. Here you
can find some examples:
```{r api}
## Get AEMET stations
stations <- aemet_stations() # Need to have the API Key registered
knitr::kable(head(stations))
station <- "9434" # Zaragoza Aeropuerto
## Get last observation values for a station
data_observation <- aemet_last_obs(station)
knitr::kable(head(data_observation))
## Get daily/annual climatology values for a station
data_daily <- aemet_daily_clim(station,
start = "2022-01-01",
end = "2022-06-30"
)
knitr::kable(head(data_daily))
## Get monthly/annual climatology values for a station
data_monthly <- aemet_monthly_clim(station, year = 2022)
knitr::kable(head(data_monthly))
## Get recorded extreme values of temperature for a station
data_extremes <- aemet_extremes_clim(station, parameter = "T")
knitr::kable(head(data_extremes))
```
We can also draw a "warming stripes" graph with the downloaded data from a
weather station. These functions returns **ggplot2** plots:
```{r climatestripes, fig.asp=0.7, eval=TRUE}
# Plot a climate stripes graph for a period of years for a station
library(ggplot2)
# Example data
temp_data <- climaemet::climaemet_9434_temp
ggstripes(temp_data, plot_title = "Zaragoza Airport") +
labs(subtitle = "(1950-2020)")
```
Furthermore, we can draw the well-known Walter & Lieth climatic diagram for a
weather station and over a specified period of time:
```{r climatogram, fig.asp=0.7, eval=TRUE}
# Plot of a Walter & Lieth climatic diagram for a station
# Example data
wl_data <- climaemet::climaemet_9434_climatogram
ggclimat_walter_lieth(wl_data,
alt = "249", per = "1981-2010",
est = "Zaragoza Airport"
)
```
Additionally, we may be interested in drawing the wind speed and direction over
a period of time for the data downloaded from a weather station.:
```{r windrose, fig.asp=0.7, eval=TRUE}
# Plot a windrose showing the wind speed and direction for a station
# Example data
wind_data <- climaemet::climaemet_9434_wind
speed <- wind_data$velmedia
direction <- wind_data$dir
ggwindrose(
speed = speed, direction = direction,
speed_cuts = seq(0, 16, 4), legend_title = "Wind speed (m/s)",
calm_wind = 0, n_col = 1, plot_title = "Zaragoza Airport"
) +
labs(subtitle = "2000-2020", caption = "Source: AEMET")
```
## ... and spatial!
Another major change in `v1.0.0` is the ability of return information on spatial
`sf` format, using `return_sf = TRUE`. The coordinate reference system (CRS)
used is **EPSG 4326**, that correspond to the **World Geodetic System (WGS)**
and return coordinates in latitude/longitude (unprojected coordinates):
```{r spatial}
# You would need to install `sf` if not installed yet
# run install.packages("sf") for installation
library(ggplot2)
library(dplyr)
all_stations <- aemet_daily_clim(
start = "2021-01-08", end = "2021-01-08",
return_sf = TRUE
)
ggplot(all_stations) +
geom_sf(aes(colour = tmed), shape = 19, size = 2, alpha = 0.95) +
labs(
title = "Average temperature in Spain",
subtitle = "8 Jan 2021",
color = "Max temp.\n(celsius)",
caption = "Source: AEMET"
) +
scale_colour_gradientn(
colours = hcl.colors(10, "RdBu", rev = TRUE),
breaks = c(-10, -5, 0, 5, 10, 15, 20),
guide = "legend"
) +
theme_bw() +
theme(
panel.border = element_blank(),
plot.title = element_text(face = "bold"),
plot.subtitle = element_text(face = "italic")
)
```
## 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.
## Citation
Using **climaemet** for a paper you are writing?. Consider citing it:
```{r echo=FALSE, results='asis'}
print(citation("climaemet")[1], style = "html")
```
A BibTeX entry for LaTeX users is:
```{r echo=FALSE, comment=''}
toBibtex(citation("climaemet")[1])
```
## Links
- Download from CRAN at <https://cran.r-project.org/package=climaemet>
- Browse source code at <https://github.com/ropenspain/climaemet>