Column

Probabilidade da ocorrência de microclima 2016

Column

Probabilidade da ocorrência de microclima 2020

NDVI 2020 x NDVI 2016

---
title: "Análise do impacto da vegetação no microclima"
author: Fellipe Mira Chaves
output: 
  flexdashboard::flex_dashboard:
    theme: journal
    social: menu
    source_code: embed
---

```{r setup, include = FALSE}
library(flexdashboard)
library(tidyverse)
library(tmap)
require(raster)

setwd("E:/")

guara.shp <- rgdal::readOGR("2016/shp/shp_reprojetado/guara_shp_rep.shp")

bairros <-  rgdal::readOGR("bairros/bairros_novo.shp")


raster_2020 <- stack("2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB1_pTOA.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB2_pTOA.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB3_pTOA.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB4_pTOA.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB5_pTOA.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB6_pTOA.tif",
                    '2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB7_pTOA.tif',
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/recorte_BB10_T.tif",
                    "2020_novo/LC08_L1TP_218076_20200812_20200822_01_T1/binario_limiar_b10.tif",
                    "mapbiomas_2020.tif")

names(raster_2020) <- c(paste0("B",c(1:7,10)),"resposta","clas")

raster_2020$NDVI <- (raster_2020$B5 - raster_2020$B4)/(raster_2020$B5 + raster_2020$B4)

raster_2016 <- stack("/2016/recorte_bruto/recorte_B1_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B2_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B3_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B4_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B5_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B6_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B7_pTOA.tif",
                    "/2016/recorte_bruto/recorte_B10_T.tif",
                    "/2016/recorte_bruto/binario_limiar_b10.tif",
                    "/2016/recorte_bruto/NDVI.tif",
                    "mapbiomas_2016.tif")

names(raster_2016) <- c(paste0("B",c(1:7,10)),"resposta","NDVI","clas")


#raster_2020$clas <- reclassify(raster_2020$clas,rcl = mat.recl)
#raster_2020$clas <- crop(raster_2020$clas, guara.shp)
#raster_2020$clas <- mask(raster_2020$clas, guara.shp)

mat.recl <- matrix(c(1,10,1,
                     10,15,2,
                     15,30,3,
                     30,35,4,
                     35,46,5),
                   ncol = 3, 
                   byrow = T)

raster_2016$clas <- reclassify(raster_2016$clas,rcl = mat.recl)
raster_2016$clas <- crop(raster_2016$clas, guara.shp)
raster_2016$clas <- mask(raster_2016$clas,guara.shp)

raster_2020$clas <- reclassify(raster_2020$clas,rcl = mat.recl)
raster_2020$clas <- crop(raster_2020$clas, guara.shp)
raster_2020$clas <- mask(raster_2020$clas, guara.shp)


raster_2016$clas <- as.integer(raster_2016$clas) 

raster_2020$clas <- as.integer(raster_2020$clas)


data_2016 <- data.frame(na.omit(getValues(raster_2016)))
data_2020 <- data.frame(na.omit(getValues(raster_2020)))
data_2020$clas <- as.integer(data_2020$clas)
bairro_2016 <- crop(raster_2016, bairros)
bairro_2016 <- mask(bairro_2016, bairros)

bairro_2020 <- crop(raster_2020, bairros)
bairro_2020 <- mask(bairro_2020,bairros)

data_bairro_2016 <- data.frame(na.omit(getValues(bairro_2016)))
data_bairro_2020 <- data.frame(na.omit(getValues(bairro_2020)))

df <- as.data.frame(data_bairro_2016$NDVI)
df$NDVI_2020 <- data.frame(data_bairro_2020$NDVI)
df$temp_2016 <- data.frame(data_bairro_2016$B10)
df$temp_2020 <- data.frame(data_bairro_2020$B10)
dfNDVI <- cbind(data_bairro_2016$NDVI,
            data_bairro_2020$NDVI)

M_2016 <- glm(resposta~NDVI,
              data = data_2016,
              family =  binomial(link="logit"))

raster_2016$prob_temp <- predict(raster_2016,
                             model = M_2016,
                             type = "response")
M_2020 <- glm(resposta~NDVI,
              data = data_2020,
              family =  binomial(link="logit"))

raster_2020$prob_temp <- predict(raster_2020,
                                 model = M_2020,
                                 type = "response")

```

Column {data-width=500}
-----------------------------------------------------------------------

### Probabilidade da ocorrência de microclima 2016

```{r}
tmap_mode("view")
tm_shape(raster_2016$clas, 
         name = "Classificação: RandomForests")+
  tm_raster(title = "Classes",
            style='pretty', 
            palette = 'inferno',
            legend.show = F)+
  tm_shape(raster_2016$NDVI,
           name = "NDVI")+
  tm_raster(title = "NDVI",
            style = "fisher",
            legend.show = F)+
  tm_shape(raster_2016$prob_temp,
           name = "Temperatura")+
  tm_raster(title = "Probabilidade [%]",
            style = "fisher", 
            palette = "inferno",
            legend.show = T)+
  tm_shape(bairros)+
  tm_borders(col="gray")+
  tm_text(text = "name",col = "gray")+
  tm_layout(main.title = "Mapeamento das variaveis - 2016")+
  tm_view(bbox = guara.shp)
```

Column {data-width=500}
-----------------------------------------------------------------------

### Probabilidade da ocorrência de microclima 2020

```{r}
tmap_mode("view")
tm_shape(raster_2020$clas, 
         name = "Classificação: RandomForests")+
  tm_raster(title = "Classes",
            style='pretty', 
            palette = 'inferno',
            legend.show = F)+
  tm_shape(raster_2020$NDVI,
           name = "NDVI")+
  tm_raster(title = "NDVI",
            style = "fisher",
            legend.show = F)+
  tm_shape(raster_2020$prob_temp,
           name = "Temperatura")+
  tm_raster(title = "Probabilidade [%]",
            style = "fisher", 
            palette = "inferno")+
  tm_shape(bairros)+
  tm_borders(col="gray")+
  tm_text(text = "name",col = "gray")+
  tm_layout(main.title = "Mapeamento das variaveis - 2020")+
  tm_view(bbox = guara.shp)
```

### NDVI 2020 x NDVI 2016

```{r}
a <- raster_2020$NDVI %>% as.data.frame(na.omit(getValues(.)))
names(a) <- "NDVI 2020"
b <- raster_2016$NDVI %>% as.data.frame(na.omit(getValues(.)))
names(b) <- "NDVI 2016"
a <- tibble::tibble(cbind(a,b))

b <- ggplot(a)+
  geom_density(aes(x=`NDVI 2020`),col="gray",fill="khaki",alpha=0.41)+
  geom_density(aes(x=`NDVI 2016`),col="gray",fill="green4",alpha=0.41)+
  theme_light()

b %>% plotly::ggplotly()
```