require(raster)
## Loading required package: raster
## Loading required package: sp
## The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
## which was just loaded, will retire in October 2023.
## Please refer to R-spatial evolution reports for details, especially
## https://r-spatial.org/r/2023/05/15/evolution4.html.
## It may be desirable to make the sf package available;
## package maintainers should consider adding sf to Suggests:.
## The sp package is now running under evolution status 2
## (status 2 uses the sf package in place of rgdal)
require(rasterVis)
## Loading required package: rasterVis
## Loading required package: lattice
require(rgdal)
## Loading required package: rgdal
## Please note that rgdal will be retired during October 2023,
## plan transition to sf/stars/terra functions using GDAL and PROJ
## at your earliest convenience.
## See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
## rgdal: version: 1.6-7, (SVN revision 1203)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 3.6.2, released 2023/01/02
## Path to GDAL shared files: C:/Users/juanp/AppData/Local/R/win-library/4.3/rgdal/gdal
## GDAL does not use iconv for recoding strings.
## GDAL binary built with GEOS: TRUE
## Loaded PROJ runtime: Rel. 9.2.0, March 1st, 2023, [PJ_VERSION: 920]
## Path to PROJ shared files: C:/Users/juanp/AppData/Local/R/win-library/4.3/rgdal/proj
## PROJ CDN enabled: FALSE
## Linking to sp version:2.0-0
## To mute warnings of possible GDAL/OSR exportToProj4() degradation,
## use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
require(leaflet)
## Loading required package: leaflet
require(tmaptools)
## Loading required package: tmaptools
require(lattice)
require(xts)
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following object is masked from 'package:leaflet':
##
## addLegend
Se carga en primer lugar los archivos de imágenes que será útil para encontrar las territorios con caracterÃsticas adecuadas para la Caña de Azucar
# Datos tomados de https://www.worldclim.org/data/worldclim21.html
archivos=list.files("./precipitaciones/",full.names = TRUE)
prec_months=stack(archivos)
prec_months
## class : RasterStack
## dimensions : 1080, 2160, 2332800, 12 (nrow, ncol, ncell, nlayers)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : wc2.1_10m_prec_01, wc2.1_10m_prec_02, wc2.1_10m_prec_03, wc2.1_10m_prec_04, wc2.1_10m_prec_05, wc2.1_10m_prec_06, wc2.1_10m_prec_07, wc2.1_10m_prec_08, wc2.1_10m_prec_09, wc2.1_10m_prec_10, wc2.1_10m_prec_11, wc2.1_10m_prec_12
## min values : 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
## max values : 908, 793, 720, 1004, 2068, 2210, 2381, 1674, 1955, 2328, 718, 806
archivos=list.files("./temperaturas/",full.names = TRUE)
temp_months=stack(archivos)
temp_months
## class : RasterStack
## dimensions : 1080, 2160, 2332800, 12 (nrow, ncol, ncell, nlayers)
## resolution : 0.1666667, 0.1666667 (x, y)
## extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
## crs : +proj=longlat +datum=WGS84 +no_defs
## names : wc2.1_10m_tavg_01, wc2.1_10m_tavg_02, wc2.1_10m_tavg_03, wc2.1_10m_tavg_04, wc2.1_10m_tavg_05, wc2.1_10m_tavg_06, wc2.1_10m_tavg_07, wc2.1_10m_tavg_08, wc2.1_10m_tavg_09, wc2.1_10m_tavg_10, wc2.1_10m_tavg_11, wc2.1_10m_tavg_12
## min values : -45.88400, -44.80000, -57.92575, -64.19250, -64.81150, -64.35825, -68.46075, -66.52250, -64.56325, -55.90000, -43.43475, -45.32700
## max values : 34.00950, 32.82425, 32.90950, 34.19375, 36.25325, 38.35550, 39.54950, 38.43275, 35.79000, 32.65125, 32.78800, 32.82525
plot(prec_months)
plot(temp_months)
names(prec_months)=month.name
plot(prec_months)
names(temp_months)=month.name
plot(temp_months)
#Mapa binario de lugares que cumplen las condiciones óptimas por precipitación
prec_optima_mensual_bin=prec_months>125 & prec_months>290
plot(prec_optima_mensual_bin)
prec_optimo=sum(prec_months)/12
prec_optimo[prec_optimo[]<125 | prec_optimo[]>290]=NA
plot(prec_optimo)
#crs(prec_optimo1)="+proj=longlat +datum=WGS84"
#Mapa binario de lugares que cumplen las condiciones óptimas por temperatura
temp_optima_mensual_bin=temp_months>22.5 & temp_months>28
plot(temp_optima_mensual_bin)
temp_optimo=sum(temp_months)/12
temp_optimo[temp_optimo < 22.5 | temp_optimo > 28] = NA
plot(temp_optimo)
#crs(temp_optimo1)="+proj=longlat +datum=WGS84"
A continuación, usamos la biblioteca leaflet para proyectar nuestras imágenes Raster de precipitaciones y temperatura sobre el shape global
Nota: Durante la ejecución de RMarkdown y R, la imagen raster no ha cargado debidamente y no se ha proyectado sobre el shape global
leaflet() %>% addProviderTiles('Esri.WorldImagery') %>% addRasterImage(prec_optimo)
leaflet() %>% addProviderTiles('Esri.WorldImagery') %>% addRasterImage(temp_optimo)
Identificar algunos puntos (2 o 3) al azar en la región del valle del cauca (use google maps) y extraer la información de clima. Grafique las series de tiempo de temperatura y precipitación.
Seleccionamos dos puntos en el centro del Valle
# optimo=merge(prec_optima_mensual_bin,temp_optima_mensual_bin)
# levelplot(optimo,par.settings=BuRdTheme)
#Puntos museo providencia e ingenio providencia Cerrito (valle)
puntos <- data.frame(
longitude = c(-76.5535226,-76.2470723),
latitude = c(3.7614825,3.6302707)
)
names(temp_months)=month.name
names(prec_months)=month.name
temp_region=as.data.frame(extract(temp_months,puntos))
prec_region= as.data.frame(extract(prec_months,puntos))
temp_region
## January February March April May June July August September
## 1 20.38600 20.50375 20.63725 20.38350 20.2000 19.996 20.0890 20.13525 20.15400
## 2 22.50275 22.61550 22.73675 22.44175 22.3585 22.328 22.6225 22.74675 22.57575
## October November December
## 1 19.79975 19.75750 20.13100
## 2 22.02075 21.88275 22.14775
prec_region
## January February March April May June July August September October November
## 1 83 93 120 187 166 112 69 91 117 208 171
## 2 92 102 132 172 146 112 61 73 105 195 173
## December
## 1 119
## 2 121
Se genera la serie de tiempo con los datos del primer punto
ts_data <- ts(temp_region[,1], start=c(2000,1), end= c(2000,7),frequency=12)
ts_data
## Jan Feb Mar Apr May Jun Jul
## 2000 20.38600 22.50275 20.38600 22.50275 20.38600 22.50275 20.38600
plot(ts_data)
Por medio de alguna métrica de similaridad (ejemplo: distancia euclidiana) genere un código en R que permita identificar mapas de similaridad a nivel global para los sitios identificados en 3. Grafique los mapas con una escala de colores adecuada.
euclid_prov_temp= sqrt(sum((temp_months-as.numeric(temp_region[,1]))^2))
levelplot(euclid_prov_temp,par.settings=BTCTheme,at=seq(0,176,10), main="Zonas similares Punto 1 Temperatura - Ing. Providencia")
euclid_prov_temp2= sqrt(sum((temp_months-as.numeric(temp_region[,2]))^2))
levelplot(euclid_prov_temp2,par.settings=BTCTheme,at=seq(0,176,10), main="Zonas similares Punto 2 Temperatura - Museo Providencia")
euclid_prov_prec= sqrt(sum((prec_months-as.numeric(prec_region[,1]))^2))
levelplot(euclid_prov_prec,par.settings=BuRdTheme,at=seq(0,176,10), main="Zonas similares Punto 1 Precipitacion - Ing. Providencia")
euclid_prov_prec2= sqrt(sum((prec_months-as.numeric(prec_region[,2]))^2))
levelplot(euclid_prov_prec2,par.settings=BuRdTheme,at=seq(0,176,10), main="Zonas similares Punto 2 Precipitacion - Museo Providencia")