g <- gc(reset = T) rm(list = ls()) options(scipen = 0, warn = -1)
2024-06-23
g <- gc(reset = T) rm(list = ls()) options(scipen = 0, warn = -1)
require(pacman) pacman::p_load(raster,sf,leaflet,dplyr,geodata,rnaturalearth,rasterVis, RColorBrewer)
Paises
Paises_Mundo <- world(resolution=1, level=0, path="tempdir()", version="latest") Paises_Mundo <- st_as_sf(Paises_Mundo) Chile <- gadm(country="CHL", level=1, path="tempdir()", version="latest") Chile <- st_as_sf(Chile) Chile3 <- gadm(country="CHL", level=3, path="tempdir()", version="latest") Chile3 <- st_as_sf(Chile3)
Variables idóneas
Descargar desde Worldclim
temperatura <- worldclim_global(var='tavg', res=2.5, path=tempdir(), version="2.1")
temp <- stack(temperatura) names(temp) <- month.name plot(temp)
temp_cond <- temp > 18 & temp < 27 plot(temp_cond) #grafica mapas binarios (1 verde: cumple, 0 gris: no cumple)
temp_cond_gral <- calc(temp_cond, mean)
mytheme <- rasterTheme(region = brewer.pal(9, "YlOrRd")) levelplot(temp_cond_gral, par.settings = mytheme, main = "Condición Óptima de Temperatura Promedio anual (18° - 27°)") plot(temp_cond_gral,main = "Condición Óptima de Temperatura Promedio anual (18° - 27°)", xlab = "Longitud", ylab="Latitud")
Descargar desde Worldclim
precipitacion <- worldclim_global(var='prec', res=2.5, path=tempdir(), version="2.1")
precip<- stack(precipitacion) names(precip) = month.name plot(precip)
precip_total <- calc(precip, sum)
mytheme <- rasterTheme(region = brewer.pal(9, "Blues")) levelplot(precip_total, par.settings = mytheme, main = "Precipitación Total Anual") plot(precip_total, main = "Precipitación Total Anual", xlab = "Longitud", ylab="Latitud")
precip_cond <- precip_total > 54 & precip_total < 125 plot(precip_cond, main = "Precipitación Mundial (54 - 125 mm)", xlab = "Longitud", ylab="Latitud")
combined_cond <- temp_cond & precip_cond plot(combined_cond) condiciones_optimas_temp_y_Precip <- calc(combined_cond, mean) plot(condiciones_optimas_temp_y_Precip)
temp_media <- stack(temperatura) names(temp_media) <- month.name temp_media_gral <- calc(temp_media, mean) mytheme <- rasterTheme(region = brewer.pal(9, "YlOrRd")) levelplot(temp_media_gral, par.settings = mytheme, main = "Temperatura Promedio Anual") plot(temp_media_gral,main = "Temperatura Promedio Anual", xlab = "Longitud", ylab="Latitud")
precip_total <- calc(precip, sum)
mytheme <- rasterTheme(region = brewer.pal(9, "Blues")) levelplot(precip_total, par.settings = mytheme, main = "Precipitación Total Anual") plot(precip_total, main = "Precipitación Total Anual", xlab = "Longitud", ylab="Latitud")
Dado que el índice toma en cuenta tanto la precipitación como la temperatura, podemos analizar un valor representativo. Por ejemplo, para una precipitación de 54 mm y una temperatura media de 22.5°C
ia_ridez <- precip_total/(temp_media_gral + 10) valor = ia_ridez> 0 & ia_ridez < 5 plot(valor, main="Indice de Aridez - Martonne", xlab = "Longitud", ylab="Latitud") plot(Paises_Mundo$geometry, add=T)
Grabar archivo en el disco duro
writeRaster(valor, filename="Pitahaya", format="GTiff", overwrite=T)
aptitud_opc2_chile <- mask(valor,Chile) aptitud_opc2_chile <- crop(valor,Chile) plot(aptitud_opc2_chile, main="Indice de Aridez Martonne en Chile" , xlab = "Longitud", ylab="Latitud") plot(Chile$geometry, add=T)
Grabar archivo en el disco duro
writeRaster(aptitud_opc2_chile, filename="Pitahaya", format="GTiff", overwrite=T)