Skip to contents

Paquete bioclima: Variables bioclimáticas utilizando terra

El paquete bioclima es un paquete de R diseñado para generar eficientemente variables bioclimáticas utilizando el paquete terra en lugar de raster. Esta elección de dependencia hace que el proceso sea más rápido, ya que terra está optimizado para operaciones raster a gran escala. El paquete bioclima también tiene disponible la opción de crear un subconjunto de variables sin necesidad de construir todas ellas. Además, ofrece la opción de crear variables bioclimáticas basadas en otros períodos de tiempo (por ejemplo, semanas, días), definir períodos diferentes a los trimestres (utilizados para bio08, 09, 10, 11, 16, 17, 18, 19). O incluso utilizar la temperatura promedio real (parámetro ‘tavg’), en lugar de una aproximación basada en la temperatura máxima y mínima ((tmax + tmin)) / 2).

La funcionalidad proporcionada por bioclima está inspirada en la función biovars del paquete dismo. El objetivo es agilizar el proceso de creación de variables bioclimáticas para modelado ecológico y ambiental.

Aviso: Este paquete está en desarrollo

Este paquete de R está actualmente en desarrollo y puede contener errores, fallos o características incompletas.

Notas importantes

Utilice este paquete bajo su propio riesgo. El desarrollador no garantiza la estabilidad o corrección del código.

Se agradecen las contribuciones y los informes de errores. Si encuentra problemas o tiene sugerencias de mejora, por favor abra un problema (“Issues”) en el repositorio de GitHub.

Gracias por su comprensión y colaboración mientras trabajo para mejorar y estabilizar este paquete de R.

Instalación

Para instalar bioclima, puede utilizar el paquete remotes. Si aún no lo tiene instalado, puede hacerlo ejecutando:

install.packages("remotes")
remotes::install_github("gepinillab/bioclima")
## * checking for file ‘/tmp/RtmpJaCEfI/remotes30211b2ec6a/gepinillab-bioclima-c450b66/DESCRIPTION’ ... OK
## * preparing ‘bioclima’:
## * checking DESCRIPTION meta-information ... OK
## * checking for LF line-endings in source and make files and shell scripts
## * checking for empty or unneeded directories
## Omitted ‘LazyData’ from DESCRIPTION
##   NB: this package now depends on R (>= 4.1.0)
##   WARNING: Added dependency on R >= 4.1.0 because package code uses the
##   pipe |> or function shorthand \(...) syntax added in R 4.1.0.
##   File(s) using such syntax:
##     ‘clima.R’ ‘stats_clima.R’
## * building ‘bioclima_0.1.2.tar.gz’

Instale y cargue los paquetes necesarios:

# Cargue librerias e instálelas si es necesario
if (!require("climateR")) {
  remotes::install_github("mikejohnson51/climateR") }
if (!require("AOI")) {
  remotes::install_github("mikejohnson51/AOI") }
if (!require("terra")) {
  install.packages("terra") }
if (!require("raster")) {
  install.packages("raster") }
if (!require("dismo")) {
  install.packages("dismo") }
if (!require("here")) {
  install.packages("here") }
if (!require("magrittr")) {
  install.packages("magrittr") }
if (!require("bioclima")) {
  remotes::install_github("gepinillab/bioclima") }

Obtener datos mensuales de Costa Rica

Descargue variables climáticas mensuales de la base de datos Terraclimate utilizando el paquete climateR. Estos rasters tienen una resolución espacial de 2.5 minutos de arco y una resolución temporal mensual desde 1958 a 2022 (cada año la base de datos se actualiza para incluir los meses del año pasado). El siguiente ejemplo creará variables bioclimáticas para Costa Rica resumiendo un período de 30 años.

# Descargar datos de Costa Rica (30 años de datos mensuales; 360 meses)
env.data <- climateR::getTerraClim(
  AOI = AOI::aoi_get(country = "Costa Rica"),  # Área de interés
  varname =  c("tmin", "tmax", "ppt", "soil", "srad"),  # Variables a descargar
  startDate = "1990-01-01",  # Fecha límite inferior
  endDate = "2019-12-01")  # Fecha límite superior
# Guardar temperatura mínima mensual
tmin <- env.data$tmin
# Guardar temperatura máxima mensual
tmax <- env.data$tmax
# Guardar precipitación mensual
ppt <- env.data$ppt
# Guardar radiación solar
srad <- env.data$srad
# Guardar humedad del suelo
mois <- env.data$soil
# Checar estructura de spatRaster (incluye 360 meses cada uno)
tmax
## class       : SpatRaster 
## dimensions  : 73, 82, 360  (nrow, ncol, nlyr)
## resolution  : 0.04166671, 0.04166671  (x, y)
## extent      : -85.95834, -82.54167, 8.208332, 11.25  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +ellps=WGS84 +no_defs 
## source(s)   : memory
## names       : tmax_~total, tmax_~total, tmax_~total, tmax_~total, tmax_~total, tmax_~total, ... 
## min values  :       10.83,       11.55,       12.12,       12.53,       11.95,       11.79, ... 
## max values  :       34.67,       35.76,       36.56,       36.93,       35.76,       34.92, ... 
## unit        :        degC,        degC,        degC,        degC,        degC,        degC, ... 
## time        : 1990-01-01 to 2019-12-01 (2 steps) UTC

Por favor, verifique los rasters antes de guardarlos. El 15 de noviembre de 2023, los datos climáticos obtenidos estaban invertidos. Afortunadamente, se puede corregir utilizando este código.

# Graficar el primer mes (1990-01) de precipitación
# Verificar si el mapa está invertido
plot(ppt[[1]])

# EJECUTAR ESTE CÓDIGO SI LOS VALORES DEL MAPA ESTÁN INVERTIDOS
# tmin <- rast(x = tmin, vals = values(t(tmin)))
# tmax <- rast(x = tmax, vals = values(t(tmax)))
# ppt <- rast(x = ppt, vals = values(t(ppt)))
# srad <- rast(x = srad, vals = values(t(srad)))
# mois <- rast(x = mois, vals = values(t(mois)))
# plot(ppt[[1]])

Luego, podrá guardar los rasters mensuales en un único archivo TIFF. Cada mes se guardará en las bandas de un raster, por lo que no es necesario guardar cada mes individualmente.

# Crear una carpeta
dir.create(here("data"))
# Guardar cada spatRaster
terra::writeRaster(tmin,
                   here("data", "tmin_1990-01-a-2019-12.tif"),
                   overwrite = TRUE)
terra::writeRaster(tmax,
                   here("data", "tmax_1990-01-a-2019-12.tif"),
                   overwrite = TRUE)
terra::writeRaster(ppt,
                   here("data", "ppt_1990-01-a-2019-12.tif"),
                   overwrite = TRUE)
terra::writeRaster(srad,
                   here("data", "srad_1990-01-a-2019-12.tif"),
                   overwrite = TRUE)
terra::writeRaster(mois,
                   here("data", "mois_1990-01-a-2019-12.tif"),
                   overwrite = TRUE)

Crear variables bioclimáticas

Una vez que tenga las variables mensuales, es hora de crear las variables bioclimáticas basadas en los promedios mensuales (n = 12 meses). Primero, necesitamos crear promedios mensuales para cada variable, y luego usar la función clima() para obtener las 19 variables bioclimáticas.

tmin_avg <- terra::tapp(tmin, index = rep(1:12, 30), fun = mean, na.rm = TRUE)
tmax_avg <- terra::tapp(tmax, index = rep(1:12, 30), fun = mean, na.rm = TRUE)
ppt_avg <- terra::tapp(ppt, index = rep(1:12, 30), fun = mean, na.rm = TRUE)
srad_avg <- terra::tapp(srad, index = rep(1:12, 30), fun = mean, na.rm = TRUE)
mois_avg <- terra::tapp(mois, index = rep(1:12, 30), fun = mean, na.rm = TRUE)

bios <- bioclima::clima(tmin = tmin_avg, tmax = tmax_avg, prcp = ppt_avg,
                        srad = srad_avg, mois = mois_avg,
              bios = 1:35, period = 3, circular = TRUE)
# Plot variables de temperatura
plot(bios[[1:11]])

# Plot variables de precipitación
plot(bios[[12:19]])

# Plot variables de radición solar
plot(bios[[20:27]])

# Plot variables de humedad del suelo
plot(bios[[28:35]])

### Diferencias con dismo::biovars() Obtener variables bioclimáticas usando la función del paquete dismo.

# Convertir a stack rasters
r.ppt <- raster::stack(ppt_avg)
r.tmax <- raster::stack(tmax_avg)
r.tmin <- raster::stack(tmin_avg)
# Correr biovars
bios_dismo <- dismo::biovars(prec = r.ppt, 
                             tmax = r.tmax,
                             tmin = r.tmin)
# Comparar salidas (la salida de dismo se convierte a spatRaster)
plot(rast(bios_dismo) - bios[[1:19]])

#### Tiempo de ejecución

# Correr bioclima
start.bioclima <- Sys.time()
bios <- bioclima::clima(tmin = tmin_avg, tmax = tmax_avg, prcp = ppt_avg,
              bios = c(1:19), period = 3, circular = TRUE)
end.bioclima <- Sys.time()
time.bioclima <- end.bioclima - start.bioclima
# Correr biovars
start.biovars <- Sys.time()
bios_dismo <- dismo::biovars(prec = r.ppt, 
                             tmax = r.tmax,
                             tmin = r.tmin)
end.biovars <- Sys.time()
time.biovars <- end.biovars - start.biovars
time.biovars - time.bioclima
## Time difference of 0.800643 secs

Al comparar los tiempos de ejecución, la diferencia para un área cómo Costa Rica es mínima. Pero al aumentar la resolución, el área (más celdas), o al hacer series temporales, está diferencia puede ser significativa. Por ejemplo, al correr el mismo ejemplo con Colombia (un área que es 50 veces más grande que Costa Rica) la diferencia fue de casi un minuto, siendo bioclima 25 veces más rápido (resultados no mostrados en este documento y que dependen de la computadora utilizada).

Seleccionar un grupo de variables

Muchas veces no es necesario utilizar todas las variables bioclimáticas en nuestros análisis. Por este motivo, y a diferencia de biovars(), se puede definir en el parámetro ‘bios’ el número que identifica cada una de las variables bioclimáticas. De esta forma no es necesario obtener todas las 19 variables para luego solo seleccionar las variables de interés. En el siguiente ejemplo solo se obtendrán cuatro variables (bio05, bio06, bio13 y bio14). Este ejemplo es algo más rápido, ya que no es necesario calcular internamente los trimestres más cálidos/fríos o secos/húmedos.

bios4 <- bioclima::clima(
  tmin = tmin_avg, 
  tmax = tmax_avg, 
  prcp = ppt_avg,
  bios = c(5, 6, 13, 14), 
  period = 3, 
  circular = TRUE)
plot(bios4)

Contruir series temporales bioclimaticas

Ya que se cuenta con una función más rápida para obtener las variables bioclimáticas, ahora vamos a crear una serie temporal de estas. En este ejemplo, vamos a utilizar las variables mensuales descargadas previamente (360 meses). Sabiendo que solo se tienen 30 años de información, vamos a crear una serie de tiempo usando un promedio móvil mensual (moviendo un mes cada vez hacia el presente) con una ventana temporal de veinte años (cada promedio será de 240 meses). Este ejercicio creara una serie de 121 sets de variables que promedian veinte años cada una. El primer set corresponderá al promedio de enero 1990 a diciembre 2009, el segundo al promedio de febrero 1990 a enero 2010… y el último de enero 2000 a diciembre 2019.

Para guardar los intervalos de veinte años, se puede crear un índice basado en el mes de inicio. Luego se utilizará un loop para crear cada periodo de veinte años.

mes_inicial <- seq(as.Date("1990-01-01", format = "%Y-%m-%d"),
                   as.Date("2000-01-01", format = "%Y-%m-%d"), 
                   by = "1 month")
head(mes_inicial)
## [1] "1990-01-01" "1990-02-01" "1990-03-01" "1990-04-01" "1990-05-01"
## [6] "1990-06-01"
dir.create(here("./data/bios"))
for (i in 1:length(mes_inicial)) {
  # Crear promedios de cada mes (e.g., promedios de veinte eneros, 
  # promedio de veinte febreros, etc.)
  # TMAX
  tmax_int <-  terra::tapp(
    x = tmax[[i:(i+240-1)]], #240 meses
    index = 1:12, # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  # TMIN
  tmin_int <-  terra::tapp(
    x = tmin[[i:(i+240-1)]], #240 meses
    index = 1:12, # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  # PRCP
  prcp_int <-  terra::tapp(
    x = ppt[[i:(i+240-1)]], #240 meses
    index = 1:12, # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  # Crear sets of variables bioclimaticas
  bios_ts <- bioclima::clima(
    bios = 1:19,
    tmax = tmax_int,
    tmin = tmin_int,
    prcp = prcp_int, 
    checkNA = FALSE # Verificar si los píxeles NA coinciden entre las variables de entrada. Si no estás seguro, deja en TRUE.
  )
  # Guardar archivos
  terra::writeRaster(
    bios_ts,
    filename = here("data", "bios", 
                    paste0(mes_inicial[i], "_mas-239-meses.tif")),
    overwrite = TRUE,
    gdal = c("COMPRESS=DEFLATE", "PREDICTOR=2")
  )
  # Imprimir porcentaje de avance en la consola
  print(round(i*100/length(mes_inicial), digits = 2))
  # Remover archivos temporales en la memoria RAM
  tmpFiles(remove = TRUE)
}
## [1] 0.83
## [1] 1.65
## [1] 2.48
## [1] 3.31
## [1] 4.13
## [1] 4.96
## [1] 5.79
## [1] 6.61
## [1] 7.44
## [1] 8.26
## [1] 9.09
## [1] 9.92
## [1] 10.74
## [1] 11.57
## [1] 12.4
## [1] 13.22
## [1] 14.05
## [1] 14.88
## [1] 15.7
## [1] 16.53
## [1] 17.36
## [1] 18.18
## [1] 19.01
## [1] 19.83
## [1] 20.66
## [1] 21.49
## [1] 22.31
## [1] 23.14
## [1] 23.97
## [1] 24.79
## [1] 25.62
## [1] 26.45
## [1] 27.27
## [1] 28.1
## [1] 28.93
## [1] 29.75
## [1] 30.58
## [1] 31.4
## [1] 32.23
## [1] 33.06
## [1] 33.88
## [1] 34.71
## [1] 35.54
## [1] 36.36
## [1] 37.19
## [1] 38.02
## [1] 38.84
## [1] 39.67
## [1] 40.5
## [1] 41.32
## [1] 42.15
## [1] 42.98
## [1] 43.8
## [1] 44.63
## [1] 45.45
## [1] 46.28
## [1] 47.11
## [1] 47.93
## [1] 48.76
## [1] 49.59
## [1] 50.41
## [1] 51.24
## [1] 52.07
## [1] 52.89
## [1] 53.72
## [1] 54.55
## [1] 55.37
## [1] 56.2
## [1] 57.02
## [1] 57.85
## [1] 58.68
## [1] 59.5
## [1] 60.33
## [1] 61.16
## [1] 61.98
## [1] 62.81
## [1] 63.64
## [1] 64.46
## [1] 65.29
## [1] 66.12
## [1] 66.94
## [1] 67.77
## [1] 68.6
## [1] 69.42
## [1] 70.25
## [1] 71.07
## [1] 71.9
## [1] 72.73
## [1] 73.55
## [1] 74.38
## [1] 75.21
## [1] 76.03
## [1] 76.86
## [1] 77.69
## [1] 78.51
## [1] 79.34
## [1] 80.17
## [1] 80.99
## [1] 81.82
## [1] 82.64
## [1] 83.47
## [1] 84.3
## [1] 85.12
## [1] 85.95
## [1] 86.78
## [1] 87.6
## [1] 88.43
## [1] 89.26
## [1] 90.08
## [1] 90.91
## [1] 91.74
## [1] 92.56
## [1] 93.39
## [1] 94.21
## [1] 95.04
## [1] 95.87
## [1] 96.69
## [1] 97.52
## [1] 98.35
## [1] 99.17
## [1] 100

Leer archivos

# Primer periodo
ene1990 <- rast(here("./data/bios/1990-01-01_mas-239-meses.tif"))
plot(ene1990)

# Último periodo
ene2000 <- rast(here("./data/bios/2000-01-01_mas-239-meses.tif"))
plot(ene2000)

# Checar differencias entre periodos para bio01 (promedio de temperatura anual)
plot(ene2000[[1]] - ene1990[[1]])

# Checar diferencias entre periodos para bio12 (promedio de precipitación anual)
plot(ene2000[[12]] - ene1990[[12]])

Definiendo periodos fijos

Muchas de las variables utilizadas son definidas por valores minimos o máximosa lo largo de un periodo de tiempo. Por ejemplo, precipitación del més más humedo, o la temperatura máxima del trimestre más calido. Al utilizar series de tiempo, el mes o trimestre puede varias entre periodos. En caso que la especie a modelar requiera de periodos fijos a lo largo de tiempo, se puede especificar cómo argumento adicional en la función clima.

Ver diferencias entre periodos de precipitación

En primer caso, vamos a calcular cúal es el mes con mayor precipitación para el periodo de 1990-01 a 2010-12.

# Obtener promedios mensuales
hum_1990_01 <-  terra::tapp(
    x = ppt[[1:240]], #240 meses
    index = "month", # índice mensual
    fun = mean, 
    na.rm = TRUE)
max_1990_01 <- which.max(hum_1990_01) |>
  terra::subst(1:12, time(hum_1990_01))
levels(max_1990_01) <- data.frame(id = 1:12,
                                mes = c("Ene", "Feb", "Mar", "Abr", 
                                        "May", "Jun", "Jul", "Aug", 
                                        "Sep", "Oct", "Nov", "Dic"))

plot(max_1990_01)

hum_2000_01 <-  terra::tapp(
    x = ppt[[121:360]], #240 meses
    index = "months", # índice mensual
    fun = mean, 
    na.rm = TRUE)
max_2000_01 <- which.max(hum_2000_01) |>
  terra::subst(1:12, time(hum_2000_01))
levels(max_2000_01) <- data.frame(id = 1:12,
                                mes = c("Ene", "Feb", "Mar", "Abr", 
                                        "May", "Jun", "Jul", "Aug", 
                                        "Sep", "Oct", "Nov", "Dic"))
plot(max_2000_01)

bio13_2000_01 <- clima(prcp = ppt[[121:360]], bios = 13)
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
plot(bio13_2000_01)

bio13_2000_01_fix <- clima(prcp = ppt[[121:360]], bios = 13, 
                           wettest_unit = max_1990_01)
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
plot(bio13_2000_01_fix)

# Trimestre de menor temperatura
for (i in 1:length(mes_inicial)) {
  # Crear promedios de cada mes (e.g., promedios de veinte eneros, 
  # promedio de veinte febreros, etc.)
  # TMIN
  menor_temp <-  terra::tapp(
    x = tmin[[i:(i+240-1)]], #240 meses
    index = "months", # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  tri_menor <- bioclima::get_window(menor_temp, period = 3, circular = TRUE) / 3
  min_tri_menor <- which.min(tri_menor) |>
    terra::subst(1:12, time(menor_temp))
  levels(min_tri_menor) <- data.frame(id = 1:12,
                                mes = c("EFM", "FMA", "MAM", "AMJ", 
                                        "MJJ", "JJA", "JAS", "ASO", 
                                        "SON", "OND", "NDE", "DEF"))
  if (i == 1) {
    ts_trimestre <- min_tri_menor
  } else {
    ts_trimestre <- c(ts_trimestre, min_tri_menor)
  }
  
  # Imprimir porcentaje de avance en la consola
  print(round(i*100/length(mes_inicial), digits = 2))
  # Remover archivos temporales en la memoria RAM
  tmpFiles(remove = TRUE)
}
## [1] 0.83
## [1] 1.65
## [1] 2.48
## [1] 3.31
## [1] 4.13
## [1] 4.96
## [1] 5.79
## [1] 6.61
## [1] 7.44
## [1] 8.26
## [1] 9.09
## [1] 9.92
## [1] 10.74
## [1] 11.57
## [1] 12.4
## [1] 13.22
## [1] 14.05
## [1] 14.88
## [1] 15.7
## [1] 16.53
## [1] 17.36
## [1] 18.18
## [1] 19.01
## [1] 19.83
## [1] 20.66
## [1] 21.49
## [1] 22.31
## [1] 23.14
## [1] 23.97
## [1] 24.79
## [1] 25.62
## [1] 26.45
## [1] 27.27
## [1] 28.1
## [1] 28.93
## [1] 29.75
## [1] 30.58
## [1] 31.4
## [1] 32.23
## [1] 33.06
## [1] 33.88
## [1] 34.71
## [1] 35.54
## [1] 36.36
## [1] 37.19
## [1] 38.02
## [1] 38.84
## [1] 39.67
## [1] 40.5
## [1] 41.32
## [1] 42.15
## [1] 42.98
## [1] 43.8
## [1] 44.63
## [1] 45.45
## [1] 46.28
## [1] 47.11
## [1] 47.93
## [1] 48.76
## [1] 49.59
## [1] 50.41
## [1] 51.24
## [1] 52.07
## [1] 52.89
## [1] 53.72
## [1] 54.55
## [1] 55.37
## [1] 56.2
## [1] 57.02
## [1] 57.85
## [1] 58.68
## [1] 59.5
## [1] 60.33
## [1] 61.16
## [1] 61.98
## [1] 62.81
## [1] 63.64
## [1] 64.46
## [1] 65.29
## [1] 66.12
## [1] 66.94
## [1] 67.77
## [1] 68.6
## [1] 69.42
## [1] 70.25
## [1] 71.07
## [1] 71.9
## [1] 72.73
## [1] 73.55
## [1] 74.38
## [1] 75.21
## [1] 76.03
## [1] 76.86
## [1] 77.69
## [1] 78.51
## [1] 79.34
## [1] 80.17
## [1] 80.99
## [1] 81.82
## [1] 82.64
## [1] 83.47
## [1] 84.3
## [1] 85.12
## [1] 85.95
## [1] 86.78
## [1] 87.6
## [1] 88.43
## [1] 89.26
## [1] 90.08
## [1] 90.91
## [1] 91.74
## [1] 92.56
## [1] 93.39
## [1] 94.21
## [1] 95.04
## [1] 95.87
## [1] 96.69
## [1] 97.52
## [1] 98.35
## [1] 99.17
## [1] 100
modal_trimestre <- terra::modal(ts_trimestre)
levels(modal_trimestre) <- data.frame(id = 1:12,
                                    mes = c("EFM", "FMA", "MAM", "AMJ", 
                                            "MJJ", "JJA", "JAS", "ASO", 
                                            "SON", "OND", "NDE", "DEF"))
plot(modal_trimestre)

for (i in 1:length(mes_inicial)) {
  srad_int <-  terra::tapp(
    x = srad[[i:(i+240-1)]], #240 meses
    index = 1:12, # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  mois_int <-  terra::tapp(
    x = mois[[i:(i+240-1)]], #240 meses
    index = 1:12, # índice mensual
    fun = mean, 
    na.rm = TRUE) # remover NAs
  # Crear sets of variables bioclimaticas
  ts_bios_subset <- bioclima::clima(
    bios = c(27, 35),
    # tmin = tmin_int,
    # tmax = tmax_int,
    srad = srad_int, 
    mois = mois_int, 
    checkNA = FALSE,
    coldest_period = modal_trimestre
  )
  if (i == 1) {
    bio27_ts <- ts_bios_subset[["bio27"]]
    bio35_ts <- ts_bios_subset[["bio35"]]
  } else {
    bio27_ts <- c(bio27_ts, ts_bios_subset[["bio27"]])
    bio35_ts <- c(bio35_ts, ts_bios_subset[["bio35"]])
  }
  # Imprimir porcentaje de avance en la consola
  print(round(i*100/length(mes_inicial), digits = 2))
  # Remover archivos temporales en la memoria RAM
  tmpFiles(remove = TRUE)
}
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 0.83
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 1.65
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 2.48
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 3.31
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 4.13
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 4.96
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 5.79
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 6.61
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 7.44
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 8.26
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 9.09
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 9.92
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 10.74
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 11.57
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 12.4
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 13.22
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 14.05
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 14.88
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 15.7
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 16.53
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 17.36
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 18.18
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 19.01
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 19.83
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 20.66
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 21.49
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 22.31
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 23.14
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 23.97
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 24.79
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 25.62
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 26.45
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 27.27
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 28.1
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 28.93
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 29.75
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 30.58
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 31.4
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 32.23
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 33.06
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 33.88
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 34.71
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 35.54
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 36.36
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 37.19
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 38.02
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 38.84
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 39.67
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 40.5
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 41.32
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 42.15
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 42.98
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 43.8
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 44.63
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 45.45
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 46.28
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 47.11
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 47.93
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 48.76
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 49.59
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 50.41
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 51.24
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 52.07
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 52.89
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 53.72
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 54.55
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 55.37
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 56.2
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 57.02
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 57.85
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 58.68
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 59.5
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 60.33
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 61.16
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 61.98
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 62.81
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 63.64
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 64.46
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 65.29
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 66.12
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 66.94
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 67.77
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 68.6
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 69.42
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 70.25
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 71.07
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 71.9
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 72.73
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 73.55
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 74.38
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 75.21
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 76.03
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 76.86
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 77.69
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 78.51
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 79.34
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 80.17
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 80.99
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 81.82
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 82.64
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 83.47
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 84.3
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 85.12
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 85.95
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 86.78
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 87.6
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 88.43
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 89.26
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 90.08
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 90.91
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 91.74
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 92.56
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 93.39
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 94.21
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 95.04
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 95.87
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 96.69
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 97.52
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 98.35
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 99.17
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
## Bio27, Bio35 was(were) built with a period of 3 units with circularity.
## [1] 100
plot(bio27_ts[[1]])

plot(bio35_ts[[121]])

wind.data <- climateR::getTerraClim(
  AOI = AOI::aoi_get(country = "Costa Rica"),  # Área de interés
  varname =  c("PDSI"),  # Variables a descargar
  startDate = "1990-01-01",  # Fecha límite inferior
  endDate = "2019-12-01")
wind <- wind.data$PDSI
plot(wind[[1]])

wind_avg <- terra::tapp(wind, index = rep(1:12, 30), fun = mean, na.rm = TRUE)
wind_stats <- bioclima::stats_clima(variable = wind_avg, 
                                    inter_variable = ppt_avg,
                                    prefix_variable = "wind",
                                    suffix_inter_max = "wettest",
                                    suffix_inter_min = "driest")
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
wind_stats
## class       : SpatRaster 
## dimensions  : 73, 82, 8  (nrow, ncol, nlyr)
## resolution  : 0.04166671, 0.04166671  (x, y)
## extent      : -85.95834, -82.54167, 8.208332, 11.25  (xmin, xmax, ymin, ymax)
## coord. ref. : +proj=longlat +ellps=WGS84 +no_defs 
## source(s)   : memory
## names       :  wind_mean,   wind_max,  wind_min,   wind_cv, wind_~eriod, wind_~eriod, ... 
## min values  : -1.7785278, -1.0403333, -2.632333,  54.49579,  -1.1933333,  -2.5182222, ... 
## max values  : -0.6481944,  0.4073333, -1.047000, 128.35310,   0.1524444,  -0.9714444, ...
plot(wind_stats[[1]])

wind_stats_v2 <- bioclima::stats_clima(variable = wind_avg,
                                         stats = NULL,
                                         inter_variable = tmax_avg - tmin_avg,
                                         prefix_variable = "wind",
                                         suffix_inter_max = "warmest",
                                         suffix_inter_min = "coldest")
## SpatRasters have same extent, number of rows and columns, projection, resolution, and origin
plot(wind_stats_v2)