diff --git a/CITATION.cff b/CITATION.cff index 0ee0766c..a24457ca 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -482,6 +482,19 @@ references: year: '2024' doi: 10.32614/CRAN.package.sf version: '>= 0.9.0' +- type: software + title: terra + abstract: 'terra: Spatial Data Analysis' + notes: Suggests + url: https://rspatial.org/ + repository: https://CRAN.R-project.org/package=terra + authors: + - family-names: Hijmans + given-names: Robert J. + email: r.hijmans@gmail.com + orcid: https://orcid.org/0000-0001-5872-2872 + year: '2024' + doi: 10.32614/CRAN.package.terra - type: software title: testthat abstract: 'testthat: Unit Testing for R' diff --git a/DESCRIPTION b/DESCRIPTION index 15c4555c..28f45a46 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,12 +43,12 @@ Suggests: rmarkdown, scales, sf (>= 0.9.0), + terra, testthat (>= 3.0.0) VignetteBuilder: knitr Config/Needs/website: cpp11, crosstalk, devtools, geofacet, geoR, gifski, - gstat, leaflet, reactable, scales, sf, terra, tidyterra, tidyverse, - usethis + gstat, leaflet, reactable, scales, tidyterra, tidyverse, usethis Config/testthat/edition: 3 Config/testthat/parallel: true Copyright: © AEMET. See file COPYRIGHTS diff --git a/NAMESPACE b/NAMESPACE index e2123183..4e13e904 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,6 +11,7 @@ export(aemet_detect_api_key) export(aemet_extremes_clim) export(aemet_forecast_beaches) export(aemet_forecast_daily) +export(aemet_forecast_fires) export(aemet_forecast_hourly) export(aemet_forecast_tidy) export(aemet_forecast_vars_available) @@ -57,4 +58,5 @@ importFrom(stats,aggregate) importFrom(stats,approx) importFrom(utils,head) importFrom(utils,tail) +importFrom(utils,untar) importFrom(utils,unzip) diff --git a/NEWS.md b/NEWS.md index 3c31f92a..619fbe35 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,8 +4,11 @@ - `aemet_alerts()` to get current meteorological alerts issued by AEMET. - Helper function `aemet_alert_zones()` to obtain the zoning defined by AEMET for the alerts. + - `aemet_forecast_fires()` to get a `SpatRaster` with the forecast of risk + level of wildfires. - Increase timeout limit with `httr2::req_timeout()`. - Better management of non valid/duplicated/empty API keys. +- New packages added to 'Suggest': **terra**. # climaemet 1.3.0 diff --git a/R/aemet_alerts.R b/R/aemet_alerts.R index 9e4575f6..ec099873 100644 --- a/R/aemet_alerts.R +++ b/R/aemet_alerts.R @@ -171,15 +171,11 @@ aemet_alerts <- function(ccaa = NULL, lang = c("es", "en"), verbose = FALSE, # nocov end # nolint end - id <- 1 - ### API Loop ---- for (id in ln) { this <- db_cuts[id, ] if (progress) cli::cli_progress_update() # nocov - - df <- aemet_hlp_single_alert(this, lang) final_result <- c(final_result, list(df)) diff --git a/R/aemet_forecast_fires.R b/R/aemet_forecast_fires.R new file mode 100644 index 00000000..bac5275c --- /dev/null +++ b/R/aemet_forecast_fires.R @@ -0,0 +1,138 @@ +#' AEMET fires forecast +#' +#' @description +#' +#' Get a [`SpatRaster`][terra::rast()] as provided by \CRANpkg{terra} with the +#' daily meteorological risk level for wildfires. +#' +#' @family aemet_api_data +#' @family forecasts +#' +#' @param area The area, being: +#' - `"p"` for Mainland Spain and Balearic Islands. +#' - `"c"` for Canary Islands. +#' @inheritParams get_data_aemet +#' @inheritParams aemet_daily +#' +#' @source +#' +#' . +#' +#' @return A [`tibble`][tibble::tibble()] or a [`SpatRaster`][terra::rast()] +#' object. +#' +#' @details +#' The `SpatRaster` provides 5 ([factor()])levels with the following meaning: +#' - `"1"`: Low risk. +#' - `"2"`: Moderate risk. +#' - `"3"`: High risk. +#' - `"4"`: Very high risk. +#' - `"5"`: Extreme risk. +#' +#' The resulting object has several layers, each one representing the forecast +#' for the upcoming 7 days. It also has additional attributes provided by the +#' \CRANpkg{terra} package, such as [terra::time()] and [terra::coltab()]. +#' +#' @export +#' +#' @examplesIf aemet_detect_api_key() +#' aemet_forecast_fires(extract_metadata = TRUE) +#' +#' # Extract alerts +#' alerts <- aemet_forecast_fires() +#' +#' alerts +#' +#' # Nice plotting with terra +#' library(terra) +#' plot(alerts) +#' +#' # Zoom in an area +#' cyl <- mapSpain::esp_get_ccaa("Castilla y Leon", epsg = 4326) +#' +#' # SpatVector +#' cyl <- vect(cyl) +#' +#' fires_cyl <- crop(alerts, cyl) +#' plot(fires_cyl[[1]]) +#' plot(cyl, add = TRUE) +#' +#' @export +aemet_forecast_fires <- function(area = c("p", "c"), verbose = FALSE, + extract_metadata = FALSE) { + # 1. Validate inputs---- + area <- match.arg(area) + stopifnot(is.logical(verbose)) + + # 2. Download ---- + + ## Metadata ---- + if (extract_metadata) { + apidest <- "/api/incendios/mapasriesgo/previsto/dia/1/area/p" + final_result <- get_metadata_aemet(apidest = apidest, verbose = verbose) + return(final_result) + } + + feed_url <- "https://www.aemet.es/es/api-eltiempo/incendios/download" + + + # Perform req + + tmp_tar <- tempfile(fileext = ".tar.gzip") + req1 <- httr2::request(feed_url) + # nolint start + response <- httr2::req_perform(req1, path = tmp_tar) + # nolint end + untar(tmp_tar, exdir = file.path(tempdir(), "fires")) + + # Select files + all_tifs <- list.files(file.path(tempdir(), "fires"), + pattern = ".tif$", + full.names = TRUE + ) + + area_tifs <- all_tifs[grepl(paste0("_", area, "_"), all_tifs)] + + # Create a table with dates, etc + dbase <- dplyr::tibble(file = area_tifs) + # Date of pred + date <- unlist(strsplit(area_tifs[1], "_"))[5] + date <- as.Date(date, "%d%m%Y") + dbase$base_date <- date + + # offset + off_all <- lapply(area_tifs, function(x) { + off <- unlist(strsplit(x, "_"))[3] + off <- as.integer(gsub("[^0-9]", "", off)) / 24 + }) + + dbase$offset <- unlist(off_all) + dbase$date <- dbase$base_date + dbase$offset + + # Now create rasters + rrast <- terra::rast(dbase$file) + + # To factors and NaNs to NA + rrast[is.nan(rrast)] <- NA + rrast <- terra::as.factor(rrast) + + # coltab + ctab <- data.frame(value = seq_len(5), col = c( + "#00f6f6", "#00ff00", "#ffff00", + "#ff7f00", "#ff0000" + )) + + # iter + it <- seq_len(terra::nlyr(rrast)) + + for (i in it) { + terra::coltab(rrast, layer = i) <- ctab + } + + # Time attributes + + terra::time(rrast) <- dbase$date + names(rrast) <- format(dbase$date, format = "%Y-%m-%d") + + rrast +} diff --git a/R/climaemet-package.R b/R/climaemet-package.R index 2110104f..c422229d 100644 --- a/R/climaemet-package.R +++ b/R/climaemet-package.R @@ -2,7 +2,7 @@ "_PACKAGE" ## usethis namespace: start -#' @importFrom utils head tail unzip +#' @importFrom utils head tail unzip untar #' @importFrom grDevices hcl.colors hcl.pals #' @importFrom stats aggregate approx #' @importFrom rlang .data diff --git a/README.md b/README.md index 207c6974..e8184711 100644 --- a/README.md +++ b/README.md @@ -119,22 +119,21 @@ library(climaemet) # See a tibble in action aemet_last_obs("9434") -#> # A tibble: 13 × 25 +#> # A tibble: 12 × 25 #> idema lon fint prec alt vmax vv dv lat dmax #> -#> 1 9434 -1.00 2024-08-26 03:00:00 0 249 8.6 5.5 292 41.7 293 -#> 2 9434 -1.00 2024-08-26 04:00:00 0 249 9.8 6 296 41.7 300 -#> 3 9434 -1.00 2024-08-26 05:00:00 0 249 8 5.6 291 41.7 288 -#> 4 9434 -1.00 2024-08-26 06:00:00 0 249 8.2 5.6 297 41.7 288 -#> 5 9434 -1.00 2024-08-26 07:00:00 0 249 6.1 3.9 306 41.7 308 -#> 6 9434 -1.00 2024-08-26 08:00:00 0 249 8.3 5.4 313 41.7 305 -#> 7 9434 -1.00 2024-08-26 09:00:00 0 249 8.4 5.3 319 41.7 295 -#> 8 9434 -1.00 2024-08-26 10:00:00 0 249 8.1 5 306 41.7 325 -#> 9 9434 -1.00 2024-08-26 11:00:00 0 249 7.6 4.6 309 41.7 295 -#> 10 9434 -1.00 2024-08-26 12:00:00 0 249 7.5 3.2 307 41.7 278 -#> 11 9434 -1.00 2024-08-26 13:00:00 0 249 6 3 317 41.7 305 -#> 12 9434 -1.00 2024-08-26 14:00:00 0 249 5.7 2.4 300 41.7 293 -#> 13 9434 -1.00 2024-08-26 15:00:00 0 249 5.2 2.2 331 41.7 305 +#> 1 9434 -1.00 2024-08-26 20:00:00 0 249 4 2.8 269 41.7 285 +#> 2 9434 -1.00 2024-08-26 21:00:00 0 249 4.4 2.8 285 41.7 280 +#> 3 9434 -1.00 2024-08-26 22:00:00 0 249 5.9 4.1 317 41.7 323 +#> 4 9434 -1.00 2024-08-26 23:00:00 0 249 7.8 4.2 312 41.7 238 +#> 5 9434 -1.00 2024-08-27 00:00:00 0 249 6.3 4.5 292 41.7 288 +#> 6 9434 -1.00 2024-08-27 01:00:00 0 249 6.5 4.9 284 41.7 290 +#> 7 9434 -1.00 2024-08-27 02:00:00 0 249 6.6 2.8 312 41.7 288 +#> 8 9434 -1.00 2024-08-27 03:00:00 0 249 5.2 3.5 281 41.7 288 +#> 9 9434 -1.00 2024-08-27 04:00:00 0 249 4.9 3.2 294 41.7 288 +#> 10 9434 -1.00 2024-08-27 05:00:00 0 249 5.9 2.1 307 41.7 220 +#> 11 9434 -1.00 2024-08-27 06:00:00 0 249 3.6 2 295 41.7 303 +#> 12 9434 -1.00 2024-08-27 07:00:00 0 249 3.7 2.5 310 41.7 298 #> # ℹ 15 more variables: ubi , pres , hr , stdvv , ts , #> # pres_nmar , tamin , ta , tamax , tpr , #> # stddv , inso , tss5cm , pacutp , tss20cm @@ -173,12 +172,12 @@ knitr::kable(head(data_observation)) | idema | lon | fint | prec | alt | vmax | vv | dv | lat | dmax | ubi | pres | hr | stdvv | ts | pres_nmar | tamin | ta | tamax | tpr | stddv | inso | tss5cm | pacutp | tss20cm | |:------|----------:|:--------------------|-----:|----:|-----:|----:|----:|---------:|-----:|:--------------------|------:|----:|------:|-----:|----------:|------:|-----:|------:|-----:|------:|-----:|-------:|-------:|--------:| -| 9434 | -1.004167 | 2024-08-26 03:00:00 | 0 | 249 | 8.6 | 5.5 | 292 | 41.66056 | 293 | ZARAGOZA AEROPUERTO | 990.3 | 63 | 0.6 | 18.5 | 1019.9 | 18.2 | 18.2 | 18.4 | 11.0 | 6 | 0.0 | 24.2 | 0 | 28.5 | -| 9434 | -1.004167 | 2024-08-26 04:00:00 | 0 | 249 | 9.8 | 6.0 | 296 | 41.66056 | 300 | ZARAGOZA AEROPUERTO | 990.4 | 64 | 0.9 | 18.1 | 1020.0 | 17.7 | 17.8 | 18.3 | 10.9 | 6 | 0.0 | 23.8 | 0 | 28.2 | -| 9434 | -1.004167 | 2024-08-26 05:00:00 | 0 | 249 | 8.0 | 5.6 | 291 | 41.66056 | 288 | ZARAGOZA AEROPUERTO | 990.3 | 66 | 0.6 | 17.8 | 1019.9 | 17.4 | 17.4 | 17.8 | 11.0 | 6 | 0.0 | 23.5 | 0 | 27.9 | -| 9434 | -1.004167 | 2024-08-26 06:00:00 | 0 | 249 | 8.2 | 5.6 | 297 | 41.66056 | 288 | ZARAGOZA AEROPUERTO | 990.7 | 67 | 0.6 | 17.8 | 1020.4 | 17.1 | 17.2 | 17.4 | 11.0 | 5 | 9.4 | 23.1 | 0 | 27.6 | -| 9434 | -1.004167 | 2024-08-26 07:00:00 | 0 | 249 | 6.1 | 3.9 | 306 | 41.66056 | 308 | ZARAGOZA AEROPUERTO | 991.0 | 65 | 0.4 | 20.7 | 1020.6 | 17.2 | 18.0 | 18.0 | 11.3 | 8 | 60.0 | 23.2 | 0 | 27.3 | -| 9434 | -1.004167 | 2024-08-26 08:00:00 | 0 | 249 | 8.3 | 5.4 | 313 | 41.66056 | 305 | ZARAGOZA AEROPUERTO | 990.9 | 62 | 1.1 | 20.6 | 1020.4 | 18.0 | 19.0 | 19.0 | 11.6 | 9 | 45.4 | 23.9 | 0 | 27.1 | +| 9434 | -1.004167 | 2024-08-26 20:00:00 | 0 | 249 | 4.0 | 2.8 | 269 | 41.66056 | 285 | ZARAGOZA AEROPUERTO | 986.5 | 49 | 0.2 | 26.9 | 1015.0 | 27.2 | 27.2 | 28.6 | 15.5 | 7 | 0 | 31.3 | 0 | 30.6 | +| 9434 | -1.004167 | 2024-08-26 21:00:00 | 0 | 249 | 4.4 | 2.8 | 285 | 41.66056 | 280 | ZARAGOZA AEROPUERTO | 986.8 | 49 | 0.4 | 26.3 | 1015.4 | 26.1 | 26.6 | 27.2 | 15.0 | 10 | 0 | 30.4 | 0 | 30.7 | +| 9434 | -1.004167 | 2024-08-26 22:00:00 | 0 | 249 | 5.9 | 4.1 | 317 | 41.66056 | 323 | ZARAGOZA AEROPUERTO | 986.9 | 55 | 0.6 | 24.8 | 1015.6 | 24.8 | 24.8 | 26.7 | 15.2 | 9 | 0 | 29.7 | 0 | 30.6 | +| 9434 | -1.004167 | 2024-08-26 23:00:00 | 0 | 249 | 7.8 | 4.2 | 312 | 41.66056 | 238 | ZARAGOZA AEROPUERTO | 987.0 | 61 | 0.9 | 23.4 | 1015.9 | 23.2 | 23.2 | 24.8 | 15.3 | 17 | 0 | 29.0 | 0 | 30.5 | +| 9434 | -1.004167 | 2024-08-27 00:00:00 | 0 | 249 | 6.3 | 4.5 | 292 | 41.66056 | 288 | ZARAGOZA AEROPUERTO | 987.0 | 62 | 0.5 | 22.9 | 1016.0 | 22.5 | 22.5 | 23.2 | 14.9 | 6 | 0 | 28.4 | 0 | 30.3 | +| 9434 | -1.004167 | 2024-08-27 01:00:00 | 0 | 249 | 6.5 | 4.9 | 284 | 41.66056 | 290 | ZARAGOZA AEROPUERTO | 986.8 | 63 | 0.4 | 22.4 | 1015.8 | 22.0 | 22.0 | 22.5 | 14.6 | 6 | 0 | 27.8 | 0 | 30.1 | ``` r diff --git a/codemeta.json b/codemeta.json index 158daedd..19fa6be8 100644 --- a/codemeta.json +++ b/codemeta.json @@ -184,6 +184,18 @@ }, "sameAs": "https://CRAN.R-project.org/package=sf" }, + { + "@type": "SoftwareApplication", + "identifier": "terra", + "name": "terra", + "provider": { + "@id": "https://cran.r-project.org", + "@type": "Organization", + "name": "Comprehensive R Archive Network (CRAN)", + "url": "https://cran.r-project.org" + }, + "sameAs": "https://CRAN.R-project.org/package=terra" + }, { "@type": "SoftwareApplication", "identifier": "testthat", @@ -351,7 +363,7 @@ }, "applicationCategory": "Meteorology", "isPartOf": "https://ropenspain.es/", - "fileSize": "1021.885KB", + "fileSize": "861.704KB", "citation": [ { "@type": "SoftwareSourceCode", diff --git a/man/aemet_alert_zones.Rd b/man/aemet_alert_zones.Rd index b3132484..b83ec11f 100644 --- a/man/aemet_alert_zones.Rd +++ b/man/aemet_alert_zones.Rd @@ -71,6 +71,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, diff --git a/man/aemet_alerts.Rd b/man/aemet_alerts.Rd index 08ee6353..912779a1 100644 --- a/man/aemet_alerts.Rd +++ b/man/aemet_alerts.Rd @@ -103,6 +103,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, diff --git a/man/aemet_beaches.Rd b/man/aemet_beaches.Rd index 2f12981c..5f8bfd28 100644 --- a/man/aemet_beaches.Rd +++ b/man/aemet_beaches.Rd @@ -69,6 +69,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, diff --git a/man/aemet_daily.Rd b/man/aemet_daily.Rd index d3bfa00a..31033128 100644 --- a/man/aemet_daily.Rd +++ b/man/aemet_daily.Rd @@ -101,6 +101,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, diff --git a/man/aemet_extremes_clim.Rd b/man/aemet_extremes_clim.Rd index 6605a34c..e56c9f9c 100644 --- a/man/aemet_extremes_clim.Rd +++ b/man/aemet_extremes_clim.Rd @@ -63,6 +63,7 @@ Other aemet_api_data: \code{\link{aemet_daily_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, diff --git a/man/aemet_forecast.Rd b/man/aemet_forecast.Rd index 5468b1ef..260c92e6 100644 --- a/man/aemet_forecast.Rd +++ b/man/aemet_forecast.Rd @@ -159,6 +159,7 @@ Other aemet_api_data: \code{\link{aemet_daily_clim}()}, \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, @@ -166,6 +167,7 @@ Other aemet_api_data: Other forecasts: \code{\link{aemet_forecast_beaches}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_forecast_tidy}()} } \concept{aemet_api_data} diff --git a/man/aemet_forecast_beaches.Rd b/man/aemet_forecast_beaches.Rd index 2e3351ce..bda31d7b 100644 --- a/man/aemet_forecast_beaches.Rd +++ b/man/aemet_forecast_beaches.Rd @@ -75,6 +75,7 @@ Other aemet_api_data: \code{\link{aemet_daily_clim}()}, \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, @@ -82,6 +83,7 @@ Other aemet_api_data: Other forecasts: \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_forecast_tidy}()} } \concept{aemet_api_data} diff --git a/man/aemet_forecast_fires.Rd b/man/aemet_forecast_fires.Rd new file mode 100644 index 00000000..1bed796f --- /dev/null +++ b/man/aemet_forecast_fires.Rd @@ -0,0 +1,96 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/aemet_forecast_fires.R +\name{aemet_forecast_fires} +\alias{aemet_forecast_fires} +\title{AEMET fires forecast} +\source{ +\url{https://www.aemet.es/en/eltiempo/prediccion/incendios}. +} +\usage{ +aemet_forecast_fires( + area = c("p", "c"), + verbose = FALSE, + extract_metadata = FALSE +) +} +\arguments{ +\item{area}{The area, being: +\itemize{ +\item \code{"p"} for Mainland Spain and Balearic Islands. +\item \code{"c"} for Canary Islands. +}} + +\item{verbose}{Logical \code{TRUE/FALSE}. Provides information about the flow of +information between the client and server.} + +\item{extract_metadata}{Logical \code{TRUE/FALSE}. On \code{TRUE} the output is +a \code{\link[tibble:tibble]{tibble}} with the description of the fields. See also +\code{\link[=get_metadata_aemet]{get_metadata_aemet()}}.} +} +\value{ +A \code{\link[tibble:tibble]{tibble}} or a \code{\link[terra:rast]{SpatRaster}} +object. +} +\description{ +Get a \code{\link[terra:rast]{SpatRaster}} as provided by \CRANpkg{terra} with the +daily meteorological risk level for wildfires. +} +\details{ +The \code{SpatRaster} provides 5 (\code{\link[=factor]{factor()}})levels with the following meaning: +\itemize{ +\item \code{"1"}: Low risk. +\item \code{"2"}: Moderate risk. +\item \code{"3"}: High risk. +\item \code{"4"}: Very high risk. +\item \code{"5"}: Extreme risk. +} + +The resulting object has several layers, each one representing the forecast +for the upcoming 7 days. It also has additional attributes provided by the +\CRANpkg{terra} package, such as \code{\link[terra:time]{terra::time()}} and \code{\link[terra:colors]{terra::coltab()}}. +} +\examples{ +\dontshow{if (aemet_detect_api_key()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} +aemet_forecast_fires(extract_metadata = TRUE) + +# Extract alerts +alerts <- aemet_forecast_fires() + +alerts + +# Nice plotting with terra +library(terra) +plot(alerts) + +# Zoom in an area +cyl <- mapSpain::esp_get_ccaa("Castilla y Leon", epsg = 4326) + +# SpatVector +cyl <- vect(cyl) + +fires_cyl <- crop(alerts, cyl) +plot(fires_cyl[[1]]) +plot(cyl, add = TRUE) +\dontshow{\}) # examplesIf} +} +\seealso{ +Other aemet_api_data: +\code{\link{aemet_alert_zones}()}, +\code{\link{aemet_alerts}()}, +\code{\link{aemet_beaches}()}, +\code{\link{aemet_daily_clim}()}, +\code{\link{aemet_extremes_clim}()}, +\code{\link{aemet_forecast_beaches}()}, +\code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_last_obs}()}, +\code{\link{aemet_monthly}}, +\code{\link{aemet_normal}}, +\code{\link{aemet_stations}()} + +Other forecasts: +\code{\link{aemet_forecast_beaches}()}, +\code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_tidy}()} +} +\concept{aemet_api_data} +\concept{forecasts} diff --git a/man/aemet_forecast_utils.Rd b/man/aemet_forecast_utils.Rd index 855e776b..427ed211 100644 --- a/man/aemet_forecast_utils.Rd +++ b/man/aemet_forecast_utils.Rd @@ -96,6 +96,7 @@ ggplot(temp_end) + \seealso{ Other forecasts: \code{\link{aemet_forecast_beaches}()}, -\code{\link{aemet_forecast_daily}()} +\code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()} } \concept{forecasts} diff --git a/man/aemet_last_obs.Rd b/man/aemet_last_obs.Rd index d2ac3e2b..a9763186 100644 --- a/man/aemet_last_obs.Rd +++ b/man/aemet_last_obs.Rd @@ -58,6 +58,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}}, \code{\link{aemet_stations}()} diff --git a/man/aemet_monthly.Rd b/man/aemet_monthly.Rd index 53c152b4..f946b88a 100644 --- a/man/aemet_monthly.Rd +++ b/man/aemet_monthly.Rd @@ -89,6 +89,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_normal}}, \code{\link{aemet_stations}()} diff --git a/man/aemet_normal.Rd b/man/aemet_normal.Rd index 9d72b34b..8d5b70dd 100644 --- a/man/aemet_normal.Rd +++ b/man/aemet_normal.Rd @@ -71,6 +71,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_stations}()} diff --git a/man/aemet_stations.Rd b/man/aemet_stations.Rd index 702e8b63..f41308e3 100644 --- a/man/aemet_stations.Rd +++ b/man/aemet_stations.Rd @@ -53,6 +53,7 @@ Other aemet_api_data: \code{\link{aemet_extremes_clim}()}, \code{\link{aemet_forecast_beaches}()}, \code{\link{aemet_forecast_daily}()}, +\code{\link{aemet_forecast_fires}()}, \code{\link{aemet_last_obs}()}, \code{\link{aemet_monthly}}, \code{\link{aemet_normal}} diff --git a/tests/testthat/_snaps/aemet_forecast_fires.md b/tests/testthat/_snaps/aemet_forecast_fires.md new file mode 100644 index 00000000..6db52c71 --- /dev/null +++ b/tests/testthat/_snaps/aemet_forecast_fires.md @@ -0,0 +1,8 @@ +# Errors + + Code + aemet_forecast_fires("Idonotexist") + Condition + Error in `match.arg()`: + ! 'arg' should be one of "p", "c" + diff --git a/tests/testthat/test-aemet_forecast_fires.R b/tests/testthat/test-aemet_forecast_fires.R new file mode 100644 index 00000000..2eb61ca6 --- /dev/null +++ b/tests/testthat/test-aemet_forecast_fires.R @@ -0,0 +1,37 @@ +test_that("Errors", { + skip_on_cran() + skip_if_offline() + skip_if_not(aemet_detect_api_key(), message = "No API KEY") + + expect_snapshot(aemet_forecast_fires("Idonotexist"), error = TRUE) +}) + +test_that("Metadata", { + skip_on_cran() + skip_if_offline() + skip_if_not(aemet_detect_api_key(), message = "No API KEY") + + meta <- aemet_forecast_fires(extract_metadata = TRUE) + expect_s3_class(meta, "tbl") +}) + + +test_that("rasters", { + skip_on_cran() + skip_if_offline() + skip_if_not(aemet_detect_api_key(), message = "No API KEY") + + rr <- aemet_forecast_fires() + expect_s4_class(rr, "SpatRaster") + + expect_gt(terra::nlyr(rr), 5) + expect_true(all(terra::is.factor(rr))) + expect_true(all(terra::has.colors(rr))) + expect_true(terra::has.time(rr)) + + # Should be different for c + cc <- aemet_forecast_fires("c") + expect_s4_class(cc, "SpatRaster") + expect_true(terra::identical(rr, rr)) + expect_false(terra::identical(rr, cc)) +}) diff --git a/vignettes/climaemet.Rmd b/vignettes/climaemet.Rmd index b45c70e2..6f77886a 100644 --- a/vignettes/climaemet.Rmd +++ b/vignettes/climaemet.Rmd @@ -87,22 +87,21 @@ See how a `tibble` is displayed: # See a tibble in action aemet_last_obs("9434") -#> # A tibble: 13 × 25 +#> # A tibble: 12 × 25 #> idema lon fint prec alt vmax vv dv lat dmax ubi pres hr #> -#> 1 9434 -1.00 2024-08-26 03:00:00 0 249 8.6 5.5 292 41.7 293 ZARAGOZA… 990. 63 -#> 2 9434 -1.00 2024-08-26 04:00:00 0 249 9.8 6 296 41.7 300 ZARAGOZA… 990. 64 -#> 3 9434 -1.00 2024-08-26 05:00:00 0 249 8 5.6 291 41.7 288 ZARAGOZA… 990. 66 -#> 4 9434 -1.00 2024-08-26 06:00:00 0 249 8.2 5.6 297 41.7 288 ZARAGOZA… 991. 67 -#> 5 9434 -1.00 2024-08-26 07:00:00 0 249 6.1 3.9 306 41.7 308 ZARAGOZA… 991 65 -#> 6 9434 -1.00 2024-08-26 08:00:00 0 249 8.3 5.4 313 41.7 305 ZARAGOZA… 991. 62 -#> 7 9434 -1.00 2024-08-26 09:00:00 0 249 8.4 5.3 319 41.7 295 ZARAGOZA… 991 58 -#> 8 9434 -1.00 2024-08-26 10:00:00 0 249 8.1 5 306 41.7 325 ZARAGOZA… 991. 53 -#> 9 9434 -1.00 2024-08-26 11:00:00 0 249 7.6 4.6 309 41.7 295 ZARAGOZA… 990. 50 -#> 10 9434 -1.00 2024-08-26 12:00:00 0 249 7.5 3.2 307 41.7 278 ZARAGOZA… 989. 48 -#> 11 9434 -1.00 2024-08-26 13:00:00 0 249 6 3 317 41.7 305 ZARAGOZA… 988. 46 -#> 12 9434 -1.00 2024-08-26 14:00:00 0 249 5.7 2.4 300 41.7 293 ZARAGOZA… 988. 44 -#> 13 9434 -1.00 2024-08-26 15:00:00 0 249 5.2 2.2 331 41.7 305 ZARAGOZA… 987. 43 +#> 1 9434 -1.00 2024-08-26 20:00:00 0 249 4 2.8 269 41.7 285 ZARAGOZA… 986. 49 +#> 2 9434 -1.00 2024-08-26 21:00:00 0 249 4.4 2.8 285 41.7 280 ZARAGOZA… 987. 49 +#> 3 9434 -1.00 2024-08-26 22:00:00 0 249 5.9 4.1 317 41.7 323 ZARAGOZA… 987. 55 +#> 4 9434 -1.00 2024-08-26 23:00:00 0 249 7.8 4.2 312 41.7 238 ZARAGOZA… 987 61 +#> 5 9434 -1.00 2024-08-27 00:00:00 0 249 6.3 4.5 292 41.7 288 ZARAGOZA… 987 62 +#> 6 9434 -1.00 2024-08-27 01:00:00 0 249 6.5 4.9 284 41.7 290 ZARAGOZA… 987. 63 +#> 7 9434 -1.00 2024-08-27 02:00:00 0 249 6.6 2.8 312 41.7 288 ZARAGOZA… 987. 62 +#> 8 9434 -1.00 2024-08-27 03:00:00 0 249 5.2 3.5 281 41.7 288 ZARAGOZA… 986. 64 +#> 9 9434 -1.00 2024-08-27 04:00:00 0 249 4.9 3.2 294 41.7 288 ZARAGOZA… 986. 65 +#> 10 9434 -1.00 2024-08-27 05:00:00 0 249 5.9 2.1 307 41.7 220 ZARAGOZA… 986. 67 +#> 11 9434 -1.00 2024-08-27 06:00:00 0 249 3.6 2 295 41.7 303 ZARAGOZA… 987. 70 +#> 12 9434 -1.00 2024-08-27 07:00:00 0 249 3.7 2.5 310 41.7 298 ZARAGOZA… 987. 67 #> # ℹ 12 more variables: stdvv , ts , pres_nmar , tamin , ta , #> # tamax , tpr , stddv , inso , tss5cm , pacutp , tss20cm ``` diff --git a/vignettes/example-gif.gif b/vignettes/example-gif.gif index e4abcba0..ac6c33b5 100644 Binary files a/vignettes/example-gif.gif and b/vignettes/example-gif.gif differ diff --git a/vignettes/extending-climaemet.Rmd b/vignettes/extending-climaemet.Rmd index df451235..d43d3fd4 100644 --- a/vignettes/extending-climaemet.Rmd +++ b/vignettes/extending-climaemet.Rmd @@ -73,52 +73,49 @@ cat(paste("---\n\n", clean, "\n---")) AGENCIA ESTATAL DE METEOROLOGÍA PREDICCIÓN GENERAL PARA ESPAÑA -DÍA 26 DE AGOSTO DE 2024 A LAS 11:27 HORA OFICIAL -PREDICCIÓN VÁLIDA PARA EL LUNES 26 +DÍA 27 DE AGOSTO DE 2024 A LAS 09:13 HORA OFICIAL +PREDICCIÓN VÁLIDA PARA EL MARTES 27 A.- FENÓMENOS SIGNIFICATIVOS -Intervalos de tramontana fuerte en litorales de Baleares y -Ampurdán, tendiendo a amainar. Chubascos localmente fuertes en -los Pirineos orientales. +No se descartan chubascos localmente fuertes en el Pirineo +oriental. Ascenso localmente notable de las máximas en el Alto +Ebro. B.- PREDICCIÓN -Tendencia a la estabilización en la Península con predominio de -cielos poco nubosos o con intervalos de nubes altas. Únicamente -en áreas mediterráneas se dará nubosidad baja, con probables -lluvias débiles en zonas de la Comunidad Valenciana, Estrecho y -Alborán, tendiendo a poco nuboso y en áreas del extremo norte -tendrán intervalos nubosos matinales. Por la tarde, crecerá -nubosidad de evolución en el centro, este y sureste peninsular, -así como en el nordeste de Cataluña y norte de Huesca, con -probabilidad de algún chubasco disperso en el Pirineo e Ibérica -orientales y sierras del sureste, sin descartar tormentas -ocasionales. Intervalos nubosos al principio en Baleares tendiendo -a poco nuboso, sin descartar del todo algún chubasco a primeras -horas en Pitiusas. En Canarias, nubosidad baja en el norte de las -islas de mayor relieve con cielos poco nubosos en el resto, con -tendencia a un aumento de la nubosidad media y alta y sin -descartar algún chubasco débil, incluso acompañado de tormenta, -en Tenerife. - -Probables bancos de niebla matinales en zonas de interior de los -tercios norte y este peninsular. No se descarta calima en el sur -peninsular, Melilla y en Canarias. - -Las máximas se recuperarán en la mitad norte e interiores del -este peninsular y descenderán en el tercio sur, Baleares y -nordeste de Cataluña. Únicamente se prevé superar los 35 grados -en áreas del cuadrante suroeste. Las mínimas en general -descenderán, con aumentos por Galicia, Cádiz y zona occidental -del centro peninsular. En Canarias predominarán los ascensos de -las máximas, más acusados en medianías. - -Soplará tramontana en Ampurdán y Baleares, con algún intervalo -fuerte al principio, y cierzo en el Ebro, tendiendo ambos a -amainar. Vientos del este y nordeste en el resto de áreas -mediterráneas, Cantábrico y cuadrante noroeste peninsular, con -algún intervalo de fuerte en litorales atlánticos gallegos, y -viendo flojo variable en el resto. En Canarias alisios moderados, -con algún intervalo fuerte. +Predominio de un tiempo estable en la Península y Baleares con +cielos poco nubosos o despejados y algunos intervalos de nubes +altas. Únicamente en el oeste de Galicia, Cantábrico oriental y +zonas del litoral de Cataluña y del interior sureste se prevé +nubosidad baja matinal, con probables brumas y bancos de niebla. +Asimismo se espera nubosidad, de forma más compacta, en el +Estrecho y Alborán, sin descartar alguna lluvia débil y dispersa +en el Estrecho y en Melilla. Por la tarde se desarrollará +nubosidad de evolución en el tercio este peninsular, así como en +montañas del sur, con probabilidad de chubascos y tormentas +ocasionales en el Pirineo e Ibérica orientales así como en las +sierras del sureste, algo más probables en el entorno de Sierra +Nevada. En Pirineos no se descarta que sean localmente fuertes. +Intervalos nubosos de tipo bajo en los nortes y de medio y alto en +el resto de Canarias, sin descartar chubascos, e incluso +tormentas, en el interior de Tenerife. Tampoco se descartan +calimas débiles en Canarias y sur peninsular. + +Las temperaturas máximas aumentarán en la mitad nordeste +peninsular y norte de Baleares, localmente notable en el Alto Ebro +y con descensos en el oeste de la Península. Se espera superar +los 35 grados en amplias zona de interior de la mitad sur +peninsular, sin descartarlos en las depresiones del nordeste y en +la meseta norte, y sin descartar tampoco llegar a los 38 en puntos +del Guadalquivir. Las mínimas aumentarán en la mitad norte, sin +grandes cambios en el resto. En Canarias, máximas en descenso y +mínimas con pocos cambios. + +Predominarán los vientos de componentes sur y este en la +vertiente mediterránea peninsular y Baleares, con tramontana +soplando al principio en Ampurdán y norte del archipiélago. +Vientos de componente este rolando a oeste en el Cantábrico, y +predominio de la componente oeste en el resto. En Canarias +soplarán alisos moderados. ---