climaemet

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 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 (in Spanish).

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 with:

install.packages("climaemet")

You can install the developing version of climaemet using the r-universe:

# Enable this universe
options(repos = c(
  ropenspain = "https://ropenspain.r-universe.dev",
  CRAN = "https://cloud.r-project.org"
))

install.packages("climaemet")

Alternatively, you can install the developing version of climaemet with:

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.

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. 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.).

You may see the following message on load:

library(climaemet)
#> 
#> Welcome to climaemet (1.0.0)
#> Note that since climaemet (>=1.0.0) the results are provided on tibble format. Run `climaemet_news()` to see the changelog.
#> If you experience any problem open an issue on https://github.com/rOpenSpain/climaemet/issues
#> 
#> 
#> AEMET_API_KEY variable detected on this session.

See how a tibble is displayed:

# See a tibble in action

aemet_last_obs("9434")
#> # A tibble: 0 × 0

Examples

The package provides several functions to access the data of the API. Here you can find some examples:

## Get AEMET stations
stations <- aemet_stations() # Need to have the API Key registered

knitr::kable(head(stations))
indicativoindsinopnombreprovinciaaltitudlongitudlatitud
0252D08186ARENYS DE MARBARCELONA742.54000041.58750
007608181BARCELONA AEROPUERTOBARCELONA42.07000041.29278
0200EBARCELONA, FABRABARCELONA4082.12416741.41833
0201D08180BARCELONABARCELONA62.20000041.39056
0149X08174MANRESABARCELONA2911.84027841.72000
0229I08192SABADELL AEROPUERTOBARCELONA1462.10305641.52361
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 = "2020-01-01", end = "2020-12-31")

knitr::kable(head(data_daily))
fechaindicativonombreprovinciaaltitudtmedprectminhoratmintmaxhoratmaxdirvelmediarachahorarachasolpresMaxhoraPresMaxpresMinhoraPresMin
2020-01-019434ZARAGOZA, AEROPUERTOZARAGOZA2491.00,00.306:101.814:50281.75.604:400.01004.6101001.915
2020-01-029434ZARAGOZA, AEROPUERTOZARAGOZA2490.60,0-0.308:101.618:40291.13.600:400.01003.4101000.716
2020-01-039434ZARAGOZA, AEROPUERTOZARAGOZA2494.20,0-0.107:108.519:10304.48.321:402.41003.6101000.7Varias
2020-01-049434ZARAGOZA, AEROPUERTOZARAGOZA2498.60,03.606:4013.614:50335.012.512:308.21003.9101001.215
2020-01-059434ZARAGOZA, AEROPUERTOZARAGOZA2498.20,03.023:0013.315:20303.610.305:308.91001.900996.9Varias
2020-01-069434ZARAGOZA, AEROPUERTOZARAGOZA2492.30,01.423:593.200:00293.17.220:200.01001.722998.604
## Get monthly/annual climatology values for a station
data_monthly <- aemet_monthly_clim(station, year = 2000)
knitr::kable(head(data_monthly))
fechaindicativop_maxn_cubhrn_gran_foginsoq_maxnw_55q_marq_medtm_minta_maxts_minnt_30nv_0050n_desw_rachanp_100n_nubp_solnw_91ts_20np_001ta_minenp_300nv_1000evapp_mesn_llun_torts_10w_mednt_00ti_maxn_nietm_mestm_maxnv_0100ts_50q_minnp_010
2000-194348.0(15)877065.41003.5(11)51026.0994.1-0.116.3(31)6.2001232/22.2(22)0115604.93-5.8(12)650586114.9305.015161.004.38.705.6979.7(14)2
2000-294340.0(–)060007.71004.9(04)91027.1996.04.820.8(27)10.700833/21.4(17)02172011.80-1.5(06)790016380.00012.716413.4010.816.9010.6988.6(17)0
2000-394345.4(22)458007.81001.0(09)81020.3989.56.024.0(11)11.000832/20.0(15)01965014.97-0.8(03)8300206211.17015.718112.1012.017.9013.6976.5(28)4
2000-4943422.2(26)861006.2991.5(07)71008.0977.88.427.2(25)14.900110/20.0(02)12146016.7101.7(06)9900173049.114117.517011.7013.718.9015.2959.5(02)6
2000-5943423.4(05)661228.7991.4(30)NA1014.4984.713.233.0(30)18.8501NA32459NA23.5139.2(01)14301211667.511824.813021.5019.525.7020.8977.5(06)8
2000-6943412.2(09)2570011.3995.0(14)NA1017.1987.616.037.5(27)20.319018NA11075NA27.7611.0(08)16400295534.98429.221016.5023.029.8026.1977.9(09)5
## Get recorded extreme values of temperature for a station
data_extremes <- aemet_extremes_clim(station, parameter = "T")
knitr::kable(head(data_extremes))
indicativonombreubicacioncodigotemMindiaMinanioMinmesMintemMaxdiaMaxanioMaxmesMaxtemMedBajaanioMedBajamesMedBajatemMedAltaanioMedAltamesMedAltatemMedMinanioMedMinmesMedMintemMedMaxanioMedMaxmesMedMax
9434ZARAGOZA, AEROPUERTOZARAGOZA023000-10441971220682016729195329720167-121957213520167
9434ZARAGOZA, AEROPUERTOZARAGOZA023000-1145196322552720197151956212119907-301956218019907
9434ZARAGOZA, AEROPUERTOZARAGOZA023000-639196422831919577711971214620017191973220719977
9434ZARAGOZA, AEROPUERTOZARAGOZA023000-243196723249201171041986217420147541970223720147
9434ZARAGOZA, AEROPUERTOZARAGOZA023000541967236529200171321984220820177851984227820177
9434ZARAGOZA, AEROPUERTOZARAGOZA023000521119712432292019718219532266200371261969233820037

We can also draw a “warming stripes” graph with the downloaded data from a weather station. These functions returns ggplot2 plots:

# Plot a climate stripes graph for a period of years for a station

library(ggplot2)

climatestripes_station("9434", start = 1980, end = 2020) +
  theme(plot.title = element_text(size = 10))

Furthermore, we can draw the well-known Walter & Lieth climatic diagram for a weather station and over a specified period of time:

# Plot of a Walter & Lieth climatic diagram (normal climatology values) for a station
climatogram_normal("9434", labels = "en")

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.:

# Plot a windrose showing the wind speed and direction for a station over a days period.
windrose_days(
  "9434",
  start = "2010-01-01",
  end = "2020-12-31",
  n_speeds = 5,
  speed_cuts = c(2.5, 5, 7.5, 10, 12.5, 15)
) +
  theme(plot.title = element_text(size = 10))

… 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):

# You would need to install `sf` if not installed yet
# run install.packages("sf") for installation

library(ggplot2)
library(dplyr)

all_stations <- aemet_last_obs(return_sf = TRUE)
# Last hour
all_last <-
  all_stations %>% filter(fint == all_stations[["fint"]][1])

last_hour <- max(all_last$fint)


ggplot(all_last) +
  geom_sf(aes(colour = ta),
    shape = 19,
    size = 2,
    alpha = 0.5
  ) +
  labs(
    title = "Temperature in Spain",
    subtitle = last_hour,
    color = "Max temp.\n(celsius)",
    caption = "Source: AEMET"
  ) +
  scale_colour_gradientn(
    colours = hcl.colors(10, "RdBu", rev = TRUE, alpha = 0.5),
    guide = "legend"
  ) +
  guides(colour = guide_legend(n.breaks = 10)) +
  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:

citation("climaemet")
#> 
#> To cite climaemet in publications use:
#> 
#>   Pizarro, M., Hernangómez, D. and Fernández-Avilés, G. (2021).
#>   climaemet (R Climate AEMET Tools).
#>   https://CRAN.R-project.org/package=climaemet.
#>   https://doi.org/10.5281/zenodo.5205573
#> 
#> A BibTeX entry for LaTeX users is
#> 
#>   @Manual{,
#>     title = {climaemet (R Climate AEMET Tools)},
#>     author = {Manuel Pizarro and Diego Hernangómez and Gema Fernández-Avilés},
#>     year = {2021},
#>     doi = {10.5281/zenodo.5205573},
#>     email = {m.pizarro@csic.es},
#>     url = {https://CRAN.R-project.org/package=climaemet},
#>   }

Links

Download from CRAN at https://cran.r-project.org/package=climaemet

Browse source code at https://github.com/ropenspain/climaemet

Copy Link

Version

Down Chevron

Install

install.packages('climaemet')

Monthly Downloads

494

Version

1.0.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Last Published

September 16th, 2021

Functions in climaemet (1.0.0)