Retrieves daily wildfire risk levels as either tabular data or a
SpatRaster.
Usage
aemet_forecast_fires(
area = c("p", "c"),
verbose = FALSE,
extract_metadata = FALSE
)Arguments
- area
A character string specifying the forecast area:
"p"for mainland Spain and the Balearic Islands or"c"for the Canary Islands.- verbose
A logical value. If
TRUE, displays information about the exchange between the client and server.- extract_metadata
A logical value. If
TRUE, returns a tibble describing the response fields. Seeget_metadata_aemet().
Value
A tibble or a SpatRaster.
Details
The SpatRaster provides six factor() levels: "1" for very low risk,
"2" for low risk, "3" for moderate risk, "4" for high risk, "5"
for very high risk and "6" for extreme risk.
The resulting object has several layers, each representing one of the next
seven forecast days. It also has additional attributes provided by the
terra package, such as terra::time() and terra::coltab().
API key
Queries to the AEMET OpenData API require an API key. Use aemet_api_key()
to set it globally. Query timeout can be controlled with
options(climaemet_timeout = 60) (default value). See
httr2::req_timeout() for details.
Examples
aemet_forecast_fires(extract_metadata = TRUE)
#> # A tibble: 1 × 6
#> unidad_generadora descripción periodicidad formato copyright notaLegal
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 Servicio de Aplicaciones… Mapa de ni… diario image/… © AEMET.… https://…
# Extract alerts.
alerts <- aemet_forecast_fires()
alerts
#> class : SpatRaster
#> size : 922, 1541, 8 (nrow, ncol, nlyr)
#> resolution : 0.01, 0.01 (x, y)
#> extent : -10.205, 5.205, 34.995, 44.215 (xmin, xmax, ymin, ymax)
#> coord. ref. : lon/lat WGS 84 (EPSG:4326)
#> source(s) : memory
#> color table : 1, 2, 3, 4, 5, 6, 7, 8
#> names : 2026-06-23, 2026-06-24, 2026-06-25, 2026-06-26, 2026-06-27, 2026-06-28, ...
#> min values : Very low, Very low, Very low, Very low, Very low, Very low, ...
#> max values : Extreme, Extreme, Extreme, Extreme, Extreme, Extreme, ...
#> time (days) : 2026-06-23 to 2026-06-30 (8 steps)
# Plot the raster.
library(terra)
#> terra 1.9.34
plot(alerts, all_levels = TRUE)
# Zoom in on an area.
cyl <- mapSpain::esp_get_ccaa("Castilla y Leon", epsg = 4326)
# Convert to a SpatVector.
cyl <- vect(cyl)
fires_cyl <- crop(alerts, cyl)
title <- names(fires_cyl)[1]
plot(fires_cyl[[1]], main = title, all_levels = TRUE)
plot(cyl, add = TRUE)
