1. Introducción.

El objetivo de este cuaderno es obtener, procesar e ilustrar datos climaticos utilizando R.

Configuración.

library(AOI)
library(climateR)
library(sf)
## Linking to GEOS 3.9.1, GDAL 3.3.2, PROJ 7.2.1; sf_use_s2() is TRUE
library(raster)
## Loading required package: sp
library(rasterVis)
## Loading required package: lattice
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:raster':
## 
##     intersect, select, union
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

3.

(boyaca <-  st_read("C:/Users/GERARDO/Desktop/GB2022/datos/15_BOYACA/ADMINISTRATIVO/MGN_MPIO_POLITICO.shp"))
## Reading layer `MGN_MPIO_POLITICO' from data source 
##   `C:\Users\GERARDO\Desktop\GB2022\Datos\15_BOYACA\ADMINISTRATIVO\MGN_MPIO_POLITICO.shp' 
##   using driver `ESRI Shapefile'
## Simple feature collection with 123 features and 9 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -74.66496 ymin: 4.655196 xmax: -71.94885 ymax: 7.055557
## Geodetic CRS:  WGS 84
## Simple feature collection with 123 features and 9 fields
## Geometry type: POLYGON
## Dimension:     XY
## Bounding box:  xmin: -74.66496 ymin: 4.655196 xmax: -71.94885 ymax: 7.055557
## Geodetic CRS:  WGS 84
## First 10 features:
##    DPTO_CCDGO MPIO_CCDGO MPIO_CNMBR                           MPIO_CRSLC
## 1          15      15001      TUNJA                                 1541
## 2          15      15022    ALMEIDA                                 1908
## 3          15      15047  AQUITANIA                                 1789
## 4          15      15051   ARCABUCO                                 1856
## 5          15      15087      BELÉN                                 1756
## 6          15      15090     BERBEO      Ordenanza 28 de Abril 9 de 1913
## 7          15      15092  BETÉITIVA                                 1754
## 8          15      15097    BOAVITA                                 1613
## 9          15      15104     BOYACÁ                                 1537
## 10         15      15106    BRICEÑO Ordenanza 14 del 25 de Julio de 1890
##    MPIO_NAREA MPIO_NANO DPTO_CNMBR Shape_Leng  Shape_Area
## 1   119.68957      2017     BOYACÁ  0.5723744 0.009766301
## 2    57.67212      2017     BOYACÁ  0.3484692 0.004701759
## 3   942.14660      2017     BOYACÁ  1.8003115 0.076843504
## 4   137.89859      2017     BOYACÁ  0.7527090 0.011256738
## 5   163.08822      2017     BOYACÁ  0.6293489 0.013314920
## 6    58.01301      2017     BOYACÁ  0.4291743 0.004730850
## 7   101.89955      2017     BOYACÁ  0.4738184 0.008317810
## 8   145.30529      2017     BOYACÁ  0.6597822 0.011867743
## 9    48.02287      2017     BOYACÁ  0.3256140 0.003918022
## 10   64.59970      2017     BOYACÁ  0.4849753 0.005273255
##                          geometry
## 1  POLYGON ((-73.34014 5.58308...
## 2  POLYGON ((-73.36793 5.01349...
## 3  POLYGON ((-72.76242 5.63856...
## 4  POLYGON ((-73.50487 5.84347...
## 5  POLYGON ((-72.91692 6.08612...
## 6  POLYGON ((-73.0677 5.27048,...
## 7  POLYGON ((-72.81796 5.97422...
## 8  POLYGON ((-72.64907 6.43640...
## 9  POLYGON ((-73.34806 5.47411...
## 10 POLYGON ((-73.89118 5.73749...

3.1

tc_prcp = getTerraClim(boyaca, param = "prcp", startDate = "2019-02-01")
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
tc_tmp <- tc_prcp[[1]]
tc_tmp
## class      : RasterStack 
## dimensions : 59, 66, 3894, 1  (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667  (x, y)
## extent     : -74.66667, -71.91667, 4.625, 7.083333  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## names      : X2019.02 
## min values :      0.2 
## max values :    358.6
library(leaflet)
library(RColorBrewer)
pal <- colorNumeric(c("red", "orange", "#fcc000","yellow", "cyan", "blue", "#3240cd"), values(tc_tmp$X2019.02), 
                    na.color = "transparent")

leaflet() %>% addTiles() %>%
  addRasterImage(tc_tmp$X2019.02 , colors = pal, opacity = 0.8) %>%
  addLegend(pal = pal, values = values(tc_tmp$X2019.02),
    title = "Lluvia-Feb.2019 [mm]")
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded ellps WGS 84 in Proj4 definition: +proj=merc +a=6378137
## +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null
## +wktext +no_defs +type=crs
## Warning in showSRID(uprojargs, format = "PROJ", multiline = "NO", prefer_proj =
## prefer_proj): Discarded datum World Geodetic System 1984 in Proj4 definition
head(param_meta$terraclim)
##     common.name call                   description units
## 1           aet  aet     Actual Evapotranspiration    mm
## 2 water_deficit  def        Climatic Water Deficit    mm
## 3        palmer PDSI Palmer Drought Severity Index      
## 4           pet  pet  Reference Evapotranspiration    mm
## 5          prcp  ppt     Accumulated Precipitation    mm
## 6             q    q                        Runoff    mm
tc_palmer = getTerraClim(boyaca, param = "palmer", startDate = "2019-02-01")
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
tc_tmp <- tc_palmer[[1]]
tc_tmp
## class      : RasterStack 
## dimensions : 59, 66, 3894, 1  (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667  (x, y)
## extent     : -74.66667, -71.91667, 4.625, 7.083333  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## names      : X2019.02 
## min values :     -4.1 
## max values :      2.3
pal <- colorNumeric(c("#fc7300","orange", "yellow","#9acd32", "green"), values(tc_tmp$X2019.02), 
                    na.color = "transparent")

leaflet() %>% addTiles() %>%
  addRasterImage(tc_tmp$X2019.02, colors = pal, opacity = 0.8) %>%
  addLegend(pal = pal, values = values(tc_tmp$X2019.02),
    title = "PDSI-Feb.2019")
## Warning in colors(.): Some values were outside the color scale and will be
## treated as NA

3.2

wat_def = getTerraClimNormals(boyaca, param = "water_deficit", period = "19812010", month=2)
## Spherical geometry (s2) switched off
## Spherical geometry (s2) switched on
wat_def
## $terraclim_19812010_water_deficit
## class      : RasterStack 
## dimensions : 59, 66, 3894, 1  (nrow, ncol, ncell, nlayers)
## resolution : 0.04166667, 0.04166667  (x, y)
## extent     : -74.66667, -71.91667, 4.625, 7.083333  (xmin, xmax, ymin, ymax)
## crs        : +proj=longlat +datum=WGS84 +no_defs 
## names      :  X02 
## min values :  3.4 
## max values : 65.2
tc_tmp <- wat_def[[1]]
pal <- colorNumeric(c("green", "#9acd32","yellow", "orange", 
                    "#fc7300"), values(tc_tmp$X02), 
                    na.color = "transparent")
leaflet() %>% addTiles() %>%
  addRasterImage(tc_tmp$X02, colors = pal, opacity = 0.8) %>%
  addLegend(pal = pal, values = values(tc_tmp$X02),
    title = "Déficit de agua-Febrero")